Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(lint): require dangling comma in multi-line contexts #567

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 1 commit into from
Aug 21, 2022
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
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
rules: {
'array-bracket-spacing': 'error',
'brace-style': 'error',
'comma-dangle': 'error',
'comma-dangle': ['error', 'always-multiline'],
'comma-spacing': 'error',
'computed-property-spacing': 'error',
curly: 'error',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test:watch": "cross-env CONSOLE_LOG_LEVEL=warn TS_NODE_PROJECT=./tsconfig.json mocha --watch",
"test:compiled": "cross-env CONSOLE_LOG_LEVEL=warn mocha \"./lib/**/*.spec.js\"",
"lint": "eslint --ext \".js,.ts\" src",
"fix": "eslint --ext \".js,.ts\" --fix src",
"build": "concurrently -n compile,lint -c blue,green \"yarn compile\" \"yarn lint\"",
"compile": "tsc -b",
"watch": "tsc -b --watch --verbose",
Expand Down
10 changes: 5 additions & 5 deletions src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function computeCallers(tspClient: TspClient, args: lsp.TextDocumen
const location = toLocation(callerReference, undefined);
calls.push({
location,
symbol
symbol,
});
}
return { calls, symbol: contextSymbol };
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function computeCallees(tspClient: TspClient, args: lsp.TextDocumen
const location = toLocation(reference, undefined);
calls.push({
location,
symbol: definitionSymbol
symbol: definitionSymbol,
});
}
return { calls, symbol: contextSymbol };
Expand Down Expand Up @@ -128,7 +128,7 @@ async function getDefinition(tspClient: TspClient, args: lsp.TextDocumentPositio
const definitionResult = await tspClient.request(CommandTypes.Definition, {
file,
line: args.position.line + 1,
offset: args.position.character + 1
offset: args.position.character + 1,
});
return definitionResult.body ? definitionResult.body[0] : undefined;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ function findEnclosingSymbolInTree(parent: tsp.NavigationTree, range: lsp.Range)
name: candidate.text,
kind: toSymbolKind(candidate.kind),
range: spanRange,
selectionRange: selectionRange
selectionRange: selectionRange,
};
}

Expand All @@ -197,7 +197,7 @@ async function findReferences(tspClient: TspClient, args: tsp.FileSpan): Promise
const result = await tspClient.request(CommandTypes.References, {
file,
line: args.start.line,
offset: args.start.offset
offset: args.start.offset,
});
if (!result.body) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ createLspConnection({
tsserverPath: options.tsserverPath as string,
tsserverLogFile: options.tsserverLogFile as string,
tsserverLogVerbosity: options.tsserverLogVerbosity as string,
showMessageLevel: logLevel as lsp.MessageType
showMessageLevel: logLevel as lsp.MessageType,
}).listen();
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export const Commands = {
APPLY_COMPLETION_CODE_ACTION: '_typescript.applyCompletionCodeAction',
/** Commands below should be implemented by the client */
SELECT_REFACTORING: '_typescript.selectRefactoring',
SOURCE_DEFINITION: SourceDefinitionCommand.id
SOURCE_DEFINITION: SourceDefinitionCommand.id,
};
14 changes: 7 additions & 7 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export function asCompletionItem(entry: tsp.CompletionEntry, file: string, posit
entry.source || entry.data ? {
name: entry.name,
source: entry.source,
data: entry.data
} : entry.name
]
}
data: entry.data,
} : entry.name,
],
},
};

if (entry.source && entry.hasAction) {
Expand Down Expand Up @@ -192,7 +192,7 @@ function asCommitCharacters(kind: ScriptElementKind): string[] | undefined {
}

export async function asResolvedCompletionItem(
item: lsp.CompletionItem, details: tsp.CompletionEntryDetails, client: TspClient, options: WorkspaceConfigurationCompletionOptions, features: SupportedFeatures
item: lsp.CompletionItem, details: tsp.CompletionEntryDetails, client: TspClient, options: WorkspaceConfigurationCompletionOptions, features: SupportedFeatures,
): Promise<lsp.CompletionItem> {
item.detail = asDetail(details);
item.documentation = asDocumentation(details);
Expand Down Expand Up @@ -364,8 +364,8 @@ function asCommand(codeActions: tsp.CodeAction[], filepath: string): lsp.Command
arguments: [filepath, codeActions.map(codeAction => ({
commands: codeAction.commands,
description: codeAction.description,
changes: codeAction.changes.filter(x => x.fileName !== filepath)
}))]
changes: codeAction.changes.filter(x => x.fileName !== filepath),
}))],
};
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const DEFAULT_TSSERVER_PREFERENCES: Required<tsp.UserPreferences> = {
providePrefixAndSuffixTextForRename: true,
provideRefactorNotApplicableReason: false,
quotePreference: 'auto',
useLabelDetailsInCompletionEntries: true
useLabelDetailsInCompletionEntries: true,
};

export interface WorkspaceConfiguration {
Expand Down Expand Up @@ -88,20 +88,20 @@ export class ConfigurationManager {
this.tspClient = client;
const formatOptions: tsp.FormatCodeSettings = {
// We can use \n here since the editor should normalize later on to its line endings.
newLineCharacter: '\n'
newLineCharacter: '\n',
};
const args: tsp.ConfigureRequestArguments = {
...hostInfo ? { hostInfo } : {},
formatOptions,
preferences: this.tsPreferences
preferences: this.tsPreferences,
};
await this.tspClient?.request(CommandTypes.Configure, args);
}

public async configureGloballyFromDocument(filename: string, formattingOptions?: lsp.FormattingOptions): Promise<void> {
const args: tsp.ConfigureRequestArguments = {
formatOptions: this.getFormattingOptions(filename, formattingOptions),
preferences: this.getPreferences(filename)
preferences: this.getPreferences(filename),
};
await this.tspClient?.request(CommandTypes.Configure, args);
}
Expand All @@ -115,12 +115,12 @@ export class ConfigurationManager {
const preferences = Object.assign<tsp.UserPreferences, tsp.UserPreferences, tsp.UserPreferences>(
{},
this.tsPreferences,
workspacePreferences?.inlayHints || {}
workspacePreferences?.inlayHints || {},
);

return {
...preferences,
quotePreference: this.getQuoteStylePreference(preferences)
quotePreference: this.getQuoteStylePreference(preferences),
};
}

Expand All @@ -129,7 +129,7 @@ export class ConfigurationManager {

const opts: tsp.FormatCodeSettings = {
...workspacePreferences?.format,
...formattingOptions
...formattingOptions,
};

if (opts.convertTabsToSpaces === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostic-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FileDiagnostics {
protected readonly uri: string,
protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void,
protected readonly documents: LspDocuments,
protected readonly features: SupportedFeatures
protected readonly features: SupportedFeatures,
) { }

update(kind: EventTypes, diagnostics: tsp.Diagnostic[]): void {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class DiagnosticEventQueue {
protected readonly publishDiagnostics: (params: lsp.PublishDiagnosticsParams) => void,
protected readonly documents: LspDocuments,
protected readonly features: SupportedFeatures,
protected readonly logger: Logger
protected readonly logger: Logger,
) { }

updateDiagnostics(kind: EventTypes, event: tsp.DiagnosticEvent): void {
Expand Down
6 changes: 3 additions & 3 deletions src/document-symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function collectDocumentSymbolsInRange(parent: tsp.NavigationTree, symbols: lsp.
kind: toSymbolKind(parent.kind),
range: spanRange,
selectionRange: selectionRange,
children
children,
});
}
}
Expand Down Expand Up @@ -76,9 +76,9 @@ export function collectSymbolInformation(uri: string, current: tsp.NavigationTre
kind: toSymbolKind(current.kind),
location: {
uri,
range
range,
},
containerName
containerName,
});
symbols.push(...children);
}
Expand Down
28 changes: 14 additions & 14 deletions src/features/fix-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function buildIndividualFixes(
client: TspClient,
file: string,
documents: LspDocuments,
diagnostics: readonly lsp.Diagnostic[]
diagnostics: readonly lsp.Diagnostic[],
): Promise<lsp.TextDocumentEdit[]> {
const edits: lsp.TextDocumentEdit[] = [];
for (const diagnostic of diagnostics) {
Expand All @@ -35,7 +35,7 @@ async function buildIndividualFixes(

const args: tsp.CodeFixRequestArgs = {
...Range.toFileRangeRequestArgs(file, diagnostic.range),
errorCodes: [+diagnostic.code!]
errorCodes: [+diagnostic.code!],
};

const response = await client.request(CommandTypes.GetCodeFixes, args);
Expand All @@ -58,7 +58,7 @@ async function buildCombinedFix(
client: TspClient,
file: string,
documents: LspDocuments,
diagnostics: readonly lsp.Diagnostic[]
diagnostics: readonly lsp.Diagnostic[],
): Promise<lsp.TextDocumentEdit[]> {
const edits: lsp.TextDocumentEdit[] = [];
for (const diagnostic of diagnostics) {
Expand All @@ -69,7 +69,7 @@ async function buildCombinedFix(

const args: tsp.CodeFixRequestArgs = {
...Range.toFileRangeRequestArgs(file, diagnostic.range),
errorCodes: [+diagnostic.code!]
errorCodes: [+diagnostic.code!],
};

const response = await client.request(CommandTypes.GetCodeFixes, args);
Expand All @@ -90,9 +90,9 @@ async function buildCombinedFix(
const combinedArgs: tsp.GetCombinedCodeFixRequestArgs = {
scope: {
type: 'file',
args: { file }
args: { file },
},
fixId: fix.fixId
fixId: fix.fixId,
};

const combinedResponse = await client.request(CommandTypes.GetCombinedCodeFix, combinedArgs);
Expand Down Expand Up @@ -126,15 +126,15 @@ class SourceFixAll extends SourceAction {
client: TspClient,
file: string,
documents: LspDocuments,
diagnostics: readonly lsp.Diagnostic[]
diagnostics: readonly lsp.Diagnostic[],
): Promise<lsp.CodeAction | null> {
const edits: lsp.TextDocumentEdit[] = [];
edits.push(...await buildIndividualFixes([
{ codes: errorCodes.incorrectlyImplementsInterface, fixName: fixNames.classIncorrectlyImplementsInterface },
{ codes: errorCodes.asyncOnlyAllowedInAsyncFunctions, fixName: fixNames.awaitInSyncFunction }
{ codes: errorCodes.asyncOnlyAllowedInAsyncFunctions, fixName: fixNames.awaitInSyncFunction },
], client, file, documents, diagnostics));
edits.push(...await buildCombinedFix([
{ codes: errorCodes.unreachableCode, fixName: fixNames.unreachableCode }
{ codes: errorCodes.unreachableCode, fixName: fixNames.unreachableCode },
], client, file, documents, diagnostics));
if (!edits.length) {
return null;
Expand All @@ -151,10 +151,10 @@ class SourceRemoveUnused extends SourceAction {
client: TspClient,
file: string,
documents: LspDocuments,
diagnostics: readonly lsp.Diagnostic[]
diagnostics: readonly lsp.Diagnostic[],
): Promise<lsp.CodeAction | null> {
const edits = await buildCombinedFix([
{ codes: errorCodes.variableDeclaredButNeverUsed, fixName: fixNames.unusedIdentifier }
{ codes: errorCodes.variableDeclaredButNeverUsed, fixName: fixNames.unusedIdentifier },
], client, file, documents, diagnostics);
if (!edits.length) {
return null;
Expand All @@ -171,10 +171,10 @@ class SourceAddMissingImports extends SourceAction {
client: TspClient,
file: string,
documents: LspDocuments,
diagnostics: readonly lsp.Diagnostic[]
diagnostics: readonly lsp.Diagnostic[],
): Promise<lsp.CodeAction | null> {
const edits = await buildCombinedFix([
{ codes: errorCodes.cannotFindName, fixName: fixNames.fixImport }
{ codes: errorCodes.cannotFindName, fixName: fixNames.fixImport },
], client, file, documents, diagnostics);
if (!edits.length) {
return null;
Expand All @@ -189,7 +189,7 @@ export class TypeScriptAutoFixProvider {
private static kindProviders = [
SourceFixAll,
SourceRemoveUnused,
SourceAddMissingImports
SourceAddMissingImports,
];

public static get kinds(): CodeActionKind[] {
Expand Down
2 changes: 1 addition & 1 deletion src/features/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class TypeScriptInlayHintsProvider {
documents: LspDocuments,
tspClient: TspClient,
lspClient: LspClient,
configurationManager: ConfigurationManager
configurationManager: ConfigurationManager,
): Promise<lsp.InlayHint[]> {
if (tspClient.apiVersion.lt(TypeScriptInlayHintsProvider.minVersion)) {
lspClient.showErrorMessage('Inlay Hints request failed. Requires TypeScript 4.4+.');
Expand Down
4 changes: 2 additions & 2 deletions src/features/source-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SourceDefinitionCommand {
documents: LspDocuments,
tspClient: TspClient,
lspClient: LspClient,
reporter: lsp.WorkDoneProgressReporter
reporter: lsp.WorkDoneProgressReporter,
): Promise<lsp.Location[] | void> {
if (tspClient.apiVersion.lt(SourceDefinitionCommand.minVersion)) {
lspClient.showErrorMessage('Go to Source Definition failed. Requires TypeScript 4.7+.');
Expand Down Expand Up @@ -57,7 +57,7 @@ export class SourceDefinitionCommand {
const args = Position.toFileLocationRequestArgs(file, position);
return await lspClient.withProgress<lsp.Location[] | void>({
message: 'Finding source definitions…',
reporter
reporter,
}, async () => {
const response = await tspClient.request(CommandTypes.FindSourceDefinition, args);
if (response.type === 'response' && response.body?.length) {
Expand Down
12 changes: 6 additions & 6 deletions src/file-lsp-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let server: LspServer;
before(async () => {
server = await createServer({
rootUri: uri(),
publishDiagnostics: () => { }
publishDiagnostics: () => { },
});
});

Expand All @@ -35,15 +35,15 @@ describe('documentHighlight', () => {
uri: uri('module2.ts'),
languageId: 'typescript',
version: 1,
text: readContents(filePath('module2.ts'))
text: readContents(filePath('module2.ts')),
};
server.didOpenTextDocument({
textDocument: doc
textDocument: doc,
});

const result = await server.documentHighlight({
textDocument: doc,
position: lastPosition(doc, 'doStuff')
position: lastPosition(doc, 'doStuff'),
});
assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
});
Expand All @@ -55,12 +55,12 @@ describe('completions', () => {
uri: uri('completion.ts'),
languageId: 'typescript',
version: 1,
text: readContents(filePath('completion.ts'))
text: readContents(filePath('completion.ts')),
};
server.didOpenTextDocument({ textDocument: doc });
const proposals = await server.completion({
textDocument: doc,
position: positionAfter(doc, 'doStuff')
position: positionAfter(doc, 'doStuff'),
});
assert.isNotNull(proposals);
const completion = proposals!.items.find(item => item.label === 'doStuff');
Expand Down
Loading