Skip to content

Commit f6386e7

Browse files
committed
chore: use dprint to format code
1 parent 80265d1 commit f6386e7

File tree

8 files changed

+138
-147
lines changed

8 files changed

+138
-147
lines changed

.github/workflows/auto-fix.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ jobs:
2828

2929
# lint
3030
- name: Auto-fix
31-
run: pnpm run lint:fix
31+
run: npm run lint:fix
32+
33+
# format
34+
- name: Format
35+
run: npm run format
3236

3337
# commit
3438
- name: Commit

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"dprint.dprint"
4+
]
5+
}

.vscode/settings.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2+
"dprint.path": "node_modules/dprint/dprint",
23
"[javascript]": {
3-
"editor.defaultFormatter": "vscode.typescript-language-features"
4+
"editor.defaultFormatter": "dprint.dprint"
5+
},
6+
"[typescript]": {
7+
"editor.defaultFormatter": "dprint.dprint"
48
},
59
"[json]": {
6-
"editor.defaultFormatter": "vscode.json-language-features"
10+
"editor.defaultFormatter": "dprint.dprint"
711
},
812
"[jsonc]": {
9-
"editor.defaultFormatter": "vscode.json-language-features"
10-
},
11-
"[typescript]": {
12-
"editor.defaultFormatter": "vscode.typescript-language-features"
13+
"editor.defaultFormatter": "dprint.dprint"
1314
},
15+
"editor.formatOnSave": true,
1416
"editor.codeActionsOnSave": {
1517
"source.organizeImports": "always"
1618
},
@@ -27,4 +29,4 @@
2729
"json.format.keepLines": true,
2830
"typescript.format.semicolons": "insert",
2931
"typescript.tsdk": "node_modules/typescript/lib"
30-
}
32+
}

dprint.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"useTabs": true,
3+
"typescript": {
4+
"quoteStyle": "preferSingle",
5+
"arrowFunction.useParentheses": "preferNone"
6+
},
7+
"json": {
8+
},
9+
"excludes": [
10+
"**/node_modules",
11+
"**/*-lock.json",
12+
"packages/language-service/data"
13+
],
14+
"plugins": [
15+
"https://plugins.dprint.dev/typescript-0.95.7.wasm",
16+
"https://plugins.dprint.dev/json-0.20.0.wasm"
17+
]
18+
}

extensions/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
"watch": "rolldown --watch --config",
461461
"pack": "pnpm run build:prod && vsce package",
462462
"release": "pnpm run build:prod && vsce publish",
463-
"gen-ext-meta": "vscode-ext-gen --scope vue --output lib/generated-meta.ts && tsslint --project tsconfig.json --fix --vscode-settings ../../.vscode/settings.json"
463+
"gen-ext-meta": "vscode-ext-gen --scope vue --output lib/generated-meta.ts && cd ../.. && pnpm run format"
464464
},
465465
"devDependencies": {
466466
"@types/node": "^22.10.4",

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
"release:next": "pnpm run release --dist-tag next",
1212
"test": "vitest run",
1313
"test:update": "vitest run --update",
14+
"format": "dprint fmt",
1415
"lint": "pnpm run oxlint && pnpm run tsslint",
15-
"lint:fix": "pnpm run oxlint:fix && pnpm run tsslint:fix",
16+
"lint:fix": "pnpm run oxlint:fix && pnpm run tsslint:fix && npm run format",
1617
"oxlint": "oxlint",
1718
"oxlint:fix": "oxlint --fix",
1819
"tsslint": "tsslint --project {tsconfig.json,packages/*/tsconfig.json,extensions/*/tsconfig.json}",
19-
"tsslint:fix": "pnpm run lint -- --fix --vscode-settings .vscode/settings.json"
20+
"tsslint:fix": "pnpm run lint -- --fix"
2021
},
2122
"devDependencies": {
2223
"@lerna-lite/cli": "^4.1.2",
@@ -25,6 +26,7 @@
2526
"@tsslint/config": "^1.5.0",
2627
"@tsslint/eslint": "^1.5.0",
2728
"@typescript-eslint/eslint-plugin": "^8.19.0",
29+
"dprint": "^0.50.0",
2830
"oxlint": "^1.0.0",
2931
"typescript": "latest",
3032
"vitest": "^3.1.3"

pnpm-lock.yaml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsslint.config.ts

Lines changed: 5 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { defineConfig } from '@tsslint/config';
22
import { convertRules } from '@tsslint/eslint';
33
import * as path from 'node:path';
4-
import type * as ts from 'typescript';
54

65
export default defineConfig({
76
rules: {
@@ -28,7 +27,11 @@ export default defineConfig({
2827
if (packageJson.private) {
2928
return;
3029
}
31-
const parentPackageJsonPath = ts.findConfigFile(path.dirname(path.dirname(packageJsonPath)), ts.sys.fileExists, 'package.json');
30+
const parentPackageJsonPath = ts.findConfigFile(
31+
path.dirname(path.dirname(packageJsonPath)),
32+
ts.sys.fileExists,
33+
'package.json',
34+
);
3235
const parentPackageJson = !!parentPackageJsonPath && parentPackageJsonPath !== packageJsonPath
3336
? JSON.parse(ts.sys.readFile(parentPackageJsonPath) ?? '')
3437
: {};
@@ -66,138 +69,4 @@ export default defineConfig({
6669
},
6770
},
6871
},
69-
formatting: [
70-
function trailingComma({ typescript: ts, sourceFile, insert, remove }) {
71-
const { text } = sourceFile;
72-
ts.forEachChild(sourceFile, function visit(node) {
73-
let lastNode: ts.Node | undefined;
74-
let end: number | undefined;
75-
let allow = true;
76-
77-
if (ts.isObjectLiteralExpression(node)) {
78-
lastNode = node.properties[node.properties.length - 1];
79-
end = node.end;
80-
}
81-
else if (
82-
ts.isArrayLiteralExpression(node)
83-
|| ts.isObjectBindingPattern(node)
84-
|| ts.isArrayBindingPattern(node)
85-
|| ts.isNamedImports(node)
86-
|| ts.isNamedExports(node)
87-
|| ts.isImportAttributes(node)
88-
|| ts.isTupleTypeNode(node)
89-
) {
90-
lastNode = node.elements[node.elements.length - 1];
91-
end = node.end;
92-
}
93-
else if (ts.isEnumDeclaration(node)) {
94-
lastNode = node.members[node.members.length - 1];
95-
end = node.end;
96-
}
97-
else if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
98-
lastNode = node.arguments?.[node.arguments.length - 1];
99-
end = node.end;
100-
}
101-
else if (ts.isFunctionLike(node)) {
102-
const last = node.parameters[node.parameters.length - 1];
103-
if (last && !last.dotDotDotToken) {
104-
lastNode = last;
105-
const right = 'body' in node && node.body?.getStart(sourceFile) || Infinity;
106-
const parenIndex = text.indexOf(')', lastNode.end);
107-
if (parenIndex !== -1 && parenIndex < right) {
108-
end = parenIndex + 1;
109-
}
110-
}
111-
}
112-
113-
if (lastNode && end) {
114-
const trailings = text.slice(lastNode.end, end - 1);
115-
const commaIndex = trailings.indexOf(',');
116-
if (allow && trailings.includes('\n')) {
117-
if (commaIndex === -1) {
118-
insert(lastNode.end, ',');
119-
}
120-
}
121-
else if (commaIndex !== -1) {
122-
const start = lastNode.end + commaIndex;
123-
remove(start, start + 1);
124-
}
125-
}
126-
ts.forEachChild(node, visit);
127-
});
128-
},
129-
/**
130-
* @example
131-
* ```diff
132-
* interface MyInterface {
133-
* - prop: string,
134-
* + prop: string;
135-
* }
136-
* ```
137-
*/
138-
function interfacePropertySemicolon({ typescript: ts, sourceFile, replace, insert }) {
139-
const { text } = sourceFile;
140-
ts.forEachChild(sourceFile, function visit(node) {
141-
if (ts.isInterfaceDeclaration(node)) {
142-
for (const member of node.members) {
143-
if (text[member.end - 1] === ',') {
144-
replace(member.end - 1, member.end, ';');
145-
}
146-
else if (text[member.end - 1] !== ';') {
147-
insert(member.end, ';');
148-
}
149-
}
150-
}
151-
ts.forEachChild(node, visit);
152-
});
153-
},
154-
/**
155-
* @example
156-
* ```diff
157-
* - const foo = (bar) => {};
158-
* + const foo = bar => {};
159-
* ```
160-
*/
161-
function arrowParens({ typescript: ts, sourceFile, remove }) {
162-
ts.forEachChild(sourceFile, function visit(node) {
163-
if (
164-
ts.isArrowFunction(node)
165-
&& node.parameters.length === 1
166-
&& !node.type
167-
) {
168-
const parameter = node.parameters[0];
169-
if (
170-
ts.isIdentifier(parameter.name)
171-
&& !parameter.type
172-
&& !parameter.dotDotDotToken
173-
&& !parameter.initializer
174-
&& sourceFile.text[parameter.getStart(sourceFile) - 1] === '('
175-
&& sourceFile.text[parameter.getEnd()] === ')'
176-
) {
177-
remove(parameter.getStart(sourceFile) - 1, parameter.getStart(sourceFile));
178-
remove(parameter.getEnd(), parameter.getEnd() + 1);
179-
}
180-
}
181-
ts.forEachChild(node, visit);
182-
});
183-
},
184-
function noUnnecessaryParentheses({ typescript: ts, sourceFile, remove }) {
185-
ts.forEachChild(sourceFile, function visit(node) {
186-
if (ts.isParenthesizedExpression(node)) {
187-
if (
188-
ts.isIdentifier(node.expression)
189-
|| ts.isPropertyAccessExpression(node.expression)
190-
|| ts.isElementAccessExpression(node.expression)
191-
|| ts.isCallExpression(node.expression)
192-
) {
193-
const start = node.getStart(sourceFile);
194-
const end = node.getEnd();
195-
remove(start, start + 1);
196-
remove(end - 1, end);
197-
}
198-
}
199-
ts.forEachChild(node, visit);
200-
});
201-
},
202-
],
20372
});

0 commit comments

Comments
 (0)