Skip to content

chore: add trailingComma format rule #5427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions extensions/vscode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const { activate, deactivate } = defineExtension(async () => {
const { stop } = watch(activeTextEditor, () => {

if (!visibleTextEditors.value.some(
editor => config.server.includeLanguages.includes(editor.document.languageId)
editor => config.server.includeLanguages.includes(editor.document.languageId),
)) {
return;
}
Expand All @@ -36,7 +36,7 @@ export const { activate, deactivate } = defineExtension(async () => {
watch(() => config.server.includeLanguages, async () => {
const reload = await vscode.window.showInformationMessage(
'Please restart extension host to apply the new language settings.',
'Restart Extension Host'
'Restart Extension Host',
);
if (reload) {
executeCommand('workbench.action.restartExtensionHost');
Expand Down Expand Up @@ -87,7 +87,7 @@ function launch(context: vscode.ExtensionContext) {
module: serverModule.fsPath,
transport: lsp.TransportKind.ipc,
options: { execArgv: ['--nolazy', '--inspect=' + 6009] },
}
},
},
{
middleware: {
Expand All @@ -106,10 +106,10 @@ function launch(context: vscode.ExtensionContext) {
documentSelector: config.server.includeLanguages,
markdown: {
isTrusted: true,
supportHtml: true
supportHtml: true,
},
outputChannel: useOutputChannel('Vue Language Server'),
}
},
);

client.onNotification('tsserver/request', async ([id, command, args]) => {
Expand Down Expand Up @@ -155,14 +155,14 @@ try {
`e.name==='vue-typescript-plugin-pack'?[${config.server.includeLanguages
.map(lang => `'${lang}'`)
.join(',')}]`,
':Array.isArray(e.languages)'
].join('')
':Array.isArray(e.languages)',
].join(''),
);

// Expose tsserver process in SingleTsServer constructor
text = text.replace(
',this._callbacks.destroy("server errored")}))',
s => s + ',globalThis.__TSSERVER__||={},globalThis.__TSSERVER__[arguments[1]]=this'
s => s + ',globalThis.__TSSERVER__||={},globalThis.__TSSERVER__[arguments[1]]=this',
);

/**
Expand All @@ -172,12 +172,12 @@ try {
// patch jsTsLanguageModes
text = text.replace(
't.jsTsLanguageModes=[t.javascript,t.javascriptreact,t.typescript,t.typescriptreact]',
s => s + '.concat("vue")'
s => s + '.concat("vue")',
);
// patch isSupportedLanguageMode
text = text.replace(
'.languages.match([t.typescript,t.typescriptreact,t.javascript,t.javascriptreact]',
s => s + '.concat("vue")'
s => s + '.concat("vue")',
);

return text;
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { type NestedScopedConfigs, scopedConfigs } from './generated-meta';

export const config = defineConfigObject<NestedScopedConfigs>(
scopedConfigs.scope,
scopedConfigs.defaults
scopedConfigs.defaults,
);
8 changes: 4 additions & 4 deletions packages/component-meta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ export * from './lib/types';
export function createCheckerByJson(
rootPath: string,
json: any,
checkerOptions: MetaCheckerOptions = {}
checkerOptions: MetaCheckerOptions = {},
) {
return createCheckerByJsonConfigBase(
ts,
rootPath,
json,
checkerOptions
checkerOptions,
);
}

export function createChecker(
tsconfig: string,
checkerOptions: MetaCheckerOptions = {}
checkerOptions: MetaCheckerOptions = {},
) {
return createCheckerBase(
ts,
tsconfig,
checkerOptions
checkerOptions,
);
}
38 changes: 19 additions & 19 deletions packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
MetaCheckerOptions,
PropertyMeta,
PropertyMetaSchema,
SlotMeta
SlotMeta,
} from './types';

export * from './types';
Expand All @@ -22,30 +22,30 @@ export function createCheckerByJsonConfigBase(
ts: typeof import('typescript'),
rootDir: string,
json: any,
checkerOptions: MetaCheckerOptions = {}
checkerOptions: MetaCheckerOptions = {},
) {
rootDir = rootDir.replace(windowsPathReg, '/');
return baseCreate(
ts,
() => vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json, undefined, true),
checkerOptions,
rootDir,
path.join(rootDir, 'jsconfig.json.global.vue')
path.join(rootDir, 'jsconfig.json.global.vue'),
);
}

export function createCheckerBase(
ts: typeof import('typescript'),
tsconfig: string,
checkerOptions: MetaCheckerOptions = {}
checkerOptions: MetaCheckerOptions = {},
) {
tsconfig = tsconfig.replace(windowsPathReg, '/');
return baseCreate(
ts,
() => vue.createParsedCommandLine(ts, ts.sys, tsconfig, true),
checkerOptions,
path.dirname(tsconfig),
tsconfig + '.global.vue'
tsconfig + '.global.vue',
);
}

Expand All @@ -54,7 +54,7 @@ export function baseCreate(
getCommandLine: () => vue.ParsedCommandLine,
checkerOptions: MetaCheckerOptions,
rootPath: string,
globalComponentName: string
globalComponentName: string,
) {
let commandLine = getCommandLine();
let fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/'));
Expand Down Expand Up @@ -85,7 +85,7 @@ export function baseCreate(
ts,
projectHost.getCompilationSettings(),
commandLine.vueOptions,
id => id
id => id,
);
const language = vue.createLanguage(
[
Expand Down Expand Up @@ -128,7 +128,7 @@ export function baseCreate(
else {
language.scripts.delete(fileName);
}
}
},
);
const { languageServiceHost } = createLanguageServiceHost(ts, ts.sys, language, s => s, projectHost);
const tsLs = ts.createLanguageService(languageServiceHost);
Expand Down Expand Up @@ -337,11 +337,11 @@ interface ComponentMeta<T> {
ts.createSourceFile(
'/tmp.' + componentPath.slice(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
snapshot.getText(0, snapshot.getLength()),
ts.ScriptTarget.Latest
ts.ScriptTarget.Latest,
),
exportName,
printer,
ts
ts,
) : {};

for (const [propName, defaultExp] of Object.entries({
Expand Down Expand Up @@ -414,7 +414,7 @@ interface ComponentMeta<T> {
const type = typeChecker.getTypeOfSymbolAtLocation($exposed, symbolNode);
const properties = type.getProperties().filter(prop =>
// only exposed props will not have a valueDeclaration
!prop.valueDeclaration
!prop.valueDeclaration,
);

return properties.map(prop => {
Expand All @@ -433,7 +433,7 @@ interface ComponentMeta<T> {
function _getExports(
program: ts.Program,
typeChecker: ts.TypeChecker,
componentPath: string
componentPath: string,
) {

const sourceFile = program?.getSourceFile(getMetaFileName(componentPath));
Expand Down Expand Up @@ -479,7 +479,7 @@ function createSchemaResolvers(
symbolNode: ts.Expression,
{ rawType, schema: options, noDeclarations }: MetaCheckerOptions,
ts: typeof import('typescript'),
language: vue.Language<string>
language: vue.Language<string>,
) {
const visited = new Set<ts.Type>();

Expand Down Expand Up @@ -741,7 +741,7 @@ function createSchemaResolvers(
function readVueComponentDefaultProps(
root: vue.VueVirtualCode,
printer: ts.Printer | undefined,
ts: typeof import('typescript')
ts: typeof import('typescript'),
) {
let result: Record<string, {
default?: string;
Expand Down Expand Up @@ -794,7 +794,7 @@ function readVueComponentDefaultProps(
if (initializer) {
const expText = printer?.printNode(ts.EmitHint.Expression, initializer, ast) ?? initializer.getText(ast);
result[name] = {
default: expText
default: expText,
};
}
}
Expand Down Expand Up @@ -842,7 +842,7 @@ function readTsComponentDefaultProps(
ast: ts.SourceFile,
exportName: string,
printer: ts.Printer | undefined,
ts: typeof import('typescript')
ts: typeof import('typescript'),
) {
const props = getPropsNode();

Expand Down Expand Up @@ -918,7 +918,7 @@ function resolvePropsOption(
ast: ts.SourceFile,
props: ts.ObjectLiteralExpression,
printer: ts.Printer | undefined,
ts: typeof import('typescript')
ts: typeof import('typescript'),
) {

const result: Record<string, { default?: string, required?: boolean; }> = {};
Expand Down Expand Up @@ -953,7 +953,7 @@ function resolveModelOption(
ast: ts.SourceFile,
options: ts.ObjectLiteralExpression,
printer: ts.Printer | undefined,
ts: typeof import('typescript')
ts: typeof import('typescript'),
) {
const result: { default?: string; } = {};

Expand All @@ -973,7 +973,7 @@ function resolveModelOption(

function resolveDefaultOptionExpression(
_default: ts.Expression,
ts: typeof import('typescript')
ts: typeof import('typescript'),
) {
if (ts.isArrowFunction(_default)) {
if (ts.isBlock(_default.body)) {
Expand Down
34 changes: 17 additions & 17 deletions packages/component-meta/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,18 +1063,18 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ

const a = meta.slots.find(slot =>
slot.name === 'default'
&& slot.type === '{ num: number; }'
&& slot.type === '{ num: number; }',
);
const b = meta.slots.find(slot =>
slot.name === 'named-slot'
&& slot.type === '{ str: string; }'
&& slot.type === '{ str: string; }',
);
const c = meta.slots.find(slot =>
slot.name === 'vbind'
&& slot.type === '{ num: number; str: string; }'
&& slot.type === '{ num: number; str: string; }',
);
const d = meta.slots.find(slot =>
slot.name === 'no-bind'
slot.name === 'no-bind',
);

expect(a).toBeDefined();
Expand All @@ -1091,18 +1091,18 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ

const a = meta.slots.find(slot =>
slot.name === 'default'
&& slot.type === '{ num: number; }'
&& slot.type === '{ num: number; }',
);
const b = meta.slots.find(slot =>
slot.name === 'named-slot'
&& slot.type === '{ str: string; }'
&& slot.type === '{ str: string; }',
);
const c = meta.slots.find(slot =>
slot.name === 'vbind'
&& slot.type === '{ num: number; str: string; }'
&& slot.type === '{ num: number; str: string; }',
);
const d = meta.slots.find(slot =>
slot.name === 'no-bind'
slot.name === 'no-bind',
);

expect(a).toBeDefined();
Expand All @@ -1119,7 +1119,7 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ

expect(meta.slots.find(slot =>
slot.name === 'default'
&& slot.type === '{ foo: number; }'
&& slot.type === '{ foo: number; }',
)).toBeDefined();
});

Expand Down Expand Up @@ -1158,12 +1158,12 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
const a = meta.props.find(prop =>
prop.name === 'foo'
&& prop.required === true
&& prop.type === 'string'
&& prop.type === 'string',
);
const b = meta.props.find(prop =>
prop.name === 'bar'
&& prop.required === false
&& prop.type === 'number | undefined'
&& prop.type === 'number | undefined',
);

expect(a).toBeDefined();
Expand All @@ -1179,12 +1179,12 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
const a = meta.props.find(prop =>
prop.name === 'foo'
&& prop.required === true
&& prop.type === 'string'
&& prop.type === 'string',
);
const b = meta.props.find(prop =>
prop.name === 'bar'
&& prop.required === false
&& prop.type === 'number | undefined'
&& prop.type === 'number | undefined',
);

expect(a).toBeDefined();
Expand All @@ -1206,12 +1206,12 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
const a = Foo.props.find(prop =>
prop.name === 'foo'
&& prop.required === true
&& prop.type === 'string'
&& prop.type === 'string',
);
const b = Bar.props.find(prop =>
prop.name === 'bar'
&& prop.required === false
&& prop.type === 'number | undefined'
&& prop.type === 'number | undefined',
);

expect(a).toBeDefined();
Expand Down Expand Up @@ -1354,7 +1354,7 @@ const checkerOptions: MetaCheckerOptions = {
};
const tsconfigChecker = createChecker(
path.resolve(__dirname, '../../../test-workspace/component-meta/tsconfig.json'),
checkerOptions
checkerOptions,
);
const noTsConfigChecker = createCheckerByJson(
path.resolve(__dirname, '../../../test-workspace/component-meta'),
Expand All @@ -1364,7 +1364,7 @@ const noTsConfigChecker = createCheckerByJson(
"**/*",
],
},
checkerOptions
checkerOptions,
);

worker(tsconfigChecker, true);
Expand Down
Loading