Skip to content

Commit 3879d0e

Browse files
dmitrivMSCopilot
andauthored
eslint: fix bracket notation in language extensions (#334771)
* eslint: enable no bracket notation rule Enable code-no-bracket-notation-for-identifiers for JavaScript and TypeScript files while grandfathering the 509 files with existing violations in a CODEOWNERS-gated allowlist. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * eslint: update bracket allowlist owners Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * eslint: group bracket notation exclusions Organize the existing baseline by feature area so cleanup can be tracked and assigned without changing the excluded file set. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * eslint: test no bracket notation rule Add RuleTester coverage for valid accesses, diagnostics, and autofix edge cases. Preserve escaped string-literal property names by checking their raw source before reporting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * eslint: fix bracket notation in language extensions Replace identifier-safe bracket notation across language feature extensions and remove the completed group from the temporary allowlist. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b0240f6 commit 3879d0e

17 files changed

Lines changed: 56 additions & 80 deletions

File tree

.eslint-allowed-bracket-notation-files

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -476,30 +476,6 @@ src/vs/platform/webContentExtractor/test/electron-main/webPageLoader.test.ts
476476
src/vs/workbench/contrib/remote/browser/remoteStartEntry.ts
477477
src/vs/workbench/contrib/remoteTunnel/test/electron-browser/remoteTunnel.contribution.test.ts
478478

479-
# Language feature extensions (22 files)
480-
extensions/css-language-features/client/src/node/cssClientMain.ts
481-
extensions/css-language-features/server/src/cssServer.ts
482-
extensions/css-language-features/server/src/node/cssServerNodeMain.ts
483-
extensions/emmet/src/abbreviationActions.ts
484-
extensions/emmet/src/defaultCompletionProvider.ts
485-
extensions/emmet/src/splitJoinTag.ts
486-
extensions/emmet/src/util.ts
487-
extensions/html-language-features/client/src/autoInsertion.ts
488-
extensions/html-language-features/client/src/node/htmlClientMain.ts
489-
extensions/html-language-features/server/src/modes/languageModes.ts
490-
extensions/html-language-features/server/src/node/htmlServerNodeMain.ts
491-
extensions/json-language-features/client/src/node/jsonClientMain.ts
492-
extensions/json-language-features/server/src/node/jsonServerNodeMain.ts
493-
extensions/markdown-language-features/src/extension.ts
494-
extensions/markdown-language-features/src/languageFeatures/copyFiles/copyFiles.ts
495-
extensions/markdown-language-features/src/languageFeatures/copyFiles/snippets.ts
496-
extensions/markdown-language-features/src/markdownEngine.ts
497-
extensions/merge-conflict/src/mergeDecorator.ts
498-
extensions/typescript-language-features/src/logging/telemetry.ts
499-
extensions/typescript-language-features/src/tsServer/serverProcess.electron.ts
500-
extensions/typescript-language-features/src/typescriptServiceClient.ts
501-
extensions/typescript-language-features/src/utils/platform.ts
502-
503479
# Git extension (6 files)
504480
extensions/git/src/askpass-main.ts
505481
extensions/git/src/askpassManager.ts

extensions/css-language-features/server/src/cssServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
142142
let service = languageServices[document.languageId];
143143
if (!service) {
144144
connection.console.log('Document type is ' + document.languageId + ', using css instead.');
145-
service = languageServices['css'];
145+
service = languageServices.css;
146146
}
147147
return service;
148148
}

extensions/emmet/src/abbreviationActions.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {
3838
const document = editor.document;
3939

4040
args = args || {};
41-
if (!args['language']) {
42-
args['language'] = document.languageId;
41+
if (!args.language) {
42+
args.language = document.languageId;
4343
}
4444
// we know it's not stylesheet due to the validate(false) call above
4545
const syntax = getSyntaxFromArgs(args) || 'html';
@@ -249,8 +249,8 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {
249249
}
250250

251251
const prompt = vscode.l10n.t("Enter Abbreviation");
252-
const inputAbbreviation = (args && args['abbreviation'])
253-
? (args['abbreviation'] as string)
252+
const inputAbbreviation = (args && args.abbreviation)
253+
? (args.abbreviation as string)
254254
: await vscode.window.showInputBox({ prompt, validateInput: inputChanged });
255255

256256
const changesWereMade = await makeChanges(inputAbbreviation, false);
@@ -285,10 +285,10 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
285285
}
286286

287287
args = args || {};
288-
if (!args['language']) {
289-
args['language'] = vscode.window.activeTextEditor.document.languageId;
288+
if (!args.language) {
289+
args.language = vscode.window.activeTextEditor.document.languageId;
290290
} else {
291-
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
291+
const excludedLanguages = vscode.workspace.getConfiguration('emmet').excludeLanguages ? vscode.workspace.getConfiguration('emmet').excludeLanguages : [];
292292
if (excludedLanguages.includes(vscode.window.activeTextEditor.document.languageId)) {
293293
return fallbackTab();
294294
}
@@ -301,7 +301,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
301301
const editor = vscode.window.activeTextEditor;
302302

303303
// When tabbed on a non empty selection, do not treat it as an emmet abbreviation, and fallback to tab instead
304-
if (vscode.workspace.getConfiguration('emmet')['triggerExpansionOnTab'] === true && editor.selections.find(x => !x.isEmpty)) {
304+
if (vscode.workspace.getConfiguration('emmet').triggerExpansionOnTab === true && editor.selections.find(x => !x.isEmpty)) {
305305
return fallbackTab();
306306
}
307307

@@ -357,7 +357,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
357357
return rootNode;
358358
}
359359

360-
const usePartialParsing = vscode.workspace.getConfiguration('emmet')['optimizeStylesheetParsing'] === true;
360+
const usePartialParsing = vscode.workspace.getConfiguration('emmet').optimizeStylesheetParsing === true;
361361
if (editor.selections.length === 1 && isStyleSheet(editor.document.languageId) && usePartialParsing && editor.document.lineCount > 1000) {
362362
rootNode = parsePartialStylesheet(editor.document, editor.selection.isReversed ? editor.selection.anchor : editor.selection.active);
363363
} else {
@@ -418,7 +418,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
418418
}
419419

420420
function fallbackTab(): Thenable<boolean | undefined> {
421-
if (vscode.workspace.getConfiguration('emmet')['triggerExpansionOnTab'] === true) {
421+
if (vscode.workspace.getConfiguration('emmet').triggerExpansionOnTab === true) {
422422
return vscode.commands.executeCommand('tab');
423423
}
424424
return Promise.resolve(true);
@@ -670,7 +670,7 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
670670
return line.replace(trimRegex, '').trim();
671671
});
672672
}
673-
expandOptions['text'] = input.textToWrap;
673+
expandOptions.text = input.textToWrap;
674674

675675
if (expandOptions.options) {
676676
// Below fixes https://github.com/microsoft/vscode/issues/29898
@@ -701,9 +701,9 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {
701701

702702
export function getSyntaxFromArgs(args: { [x: string]: string }): string | undefined {
703703
const mappedModes = getMappingForIncludedLanguages();
704-
const language: string = args['language'];
705-
const parentMode: string = args['parentMode'];
706-
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
704+
const language: string = args.language;
705+
const parentMode: string = args.parentMode;
706+
const excludedLanguages = vscode.workspace.getConfiguration('emmet').excludeLanguages ? vscode.workspace.getConfiguration('emmet').excludeLanguages : [];
707707
if (excludedLanguages.includes(language)) {
708708
return;
709709
}

extensions/emmet/src/defaultCompletionProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
4242

4343
private provideCompletionItemsInternal(document: vscode.TextDocument, position: vscode.Position, context: vscode.CompletionContext): Thenable<vscode.CompletionList | undefined> | undefined {
4444
const emmetConfig = vscode.workspace.getConfiguration('emmet');
45-
const excludedLanguages = emmetConfig['excludeLanguages'] ? emmetConfig['excludeLanguages'] : [];
45+
const excludedLanguages = emmetConfig.excludeLanguages ? emmetConfig.excludeLanguages : [];
4646
if (excludedLanguages.includes(document.languageId)) {
4747
return;
4848
}
@@ -52,8 +52,8 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
5252
const emmetMode = getEmmetMode((isSyntaxMapped ? mappedLanguages[document.languageId] : document.languageId), mappedLanguages, excludedLanguages);
5353

5454
if (!emmetMode
55-
|| emmetConfig['showExpandedAbbreviation'] === 'never'
56-
|| ((isSyntaxMapped || emmetMode === 'jsx') && emmetConfig['showExpandedAbbreviation'] !== 'always')) {
55+
|| emmetConfig.showExpandedAbbreviation === 'never'
56+
|| ((isSyntaxMapped || emmetMode === 'jsx') && emmetConfig.showExpandedAbbreviation !== 'always')) {
5757
return;
5858
}
5959

@@ -135,7 +135,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
135135
const offset = document.offsetAt(position);
136136
if (isStyleSheet(document.languageId) && context.triggerKind !== vscode.CompletionTriggerKind.TriggerForIncompleteCompletions) {
137137
validateLocation = true;
138-
const usePartialParsing = vscode.workspace.getConfiguration('emmet')['optimizeStylesheetParsing'] === true;
138+
const usePartialParsing = vscode.workspace.getConfiguration('emmet').optimizeStylesheetParsing === true;
139139
rootNode = usePartialParsing && document.lineCount > 1000 ? parsePartialStylesheet(document, position) : <Stylesheet>getRootNode(document, true);
140140
if (!rootNode) {
141141
return;
@@ -200,7 +200,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
200200
newItem.filterText = item.filterText;
201201
newItem.sortText = item.sortText;
202202

203-
if (emmetConfig['showSuggestionsAsSnippets'] === true) {
203+
if (emmetConfig.showSuggestionsAsSnippets === true) {
204204
newItem.kind = vscode.CompletionItemKind.Snippet;
205205
}
206206
newItems.push(newItem);

extensions/emmet/src/splitJoinTag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function getRangesToReplace(document: vscode.TextDocument, nodeToUpdate: HtmlFla
5656
const emmetMode = getEmmetMode(document.languageId, {}, []) ?? '';
5757
const emmetConfig = getEmmetConfiguration(emmetMode);
5858
if (emmetMode && emmetConfig.syntaxProfiles[emmetMode] &&
59-
(emmetConfig.syntaxProfiles[emmetMode]['selfClosingStyle'] === 'xhtml' || emmetConfig.syntaxProfiles[emmetMode]['self_closing_tag'] === 'xhtml')) {
59+
(emmetConfig.syntaxProfiles[emmetMode].selfClosingStyle === 'xhtml' || emmetConfig.syntaxProfiles[emmetMode].self_closing_tag === 'xhtml')) {
6060
textToReplaceWith = ' ' + textToReplaceWith;
6161
}
6262
}

extensions/emmet/src/util.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ export function sameNodes(node1: FlatNode | undefined, node2: FlatNode | undefin
606606

607607
export function getEmmetConfiguration(syntax: string) {
608608
const emmetConfig = vscode.workspace.getConfiguration('emmet');
609-
const syntaxProfiles = Object.assign({}, emmetConfig['syntaxProfiles'] || {});
610-
const preferences = Object.assign({}, emmetConfig['preferences'] || {});
609+
const syntaxProfiles = Object.assign({}, emmetConfig.syntaxProfiles || {});
610+
const preferences = Object.assign({}, emmetConfig.preferences || {});
611611
// jsx, xml and xsl syntaxes need to have self closing tags unless otherwise configured by user
612612
if (syntax === 'jsx' || syntax === 'xml' || syntax === 'xsl') {
613613
syntaxProfiles[syntax] = syntaxProfiles[syntax] || {};
@@ -624,12 +624,12 @@ export function getEmmetConfiguration(syntax: string) {
624624

625625
return {
626626
preferences,
627-
showExpandedAbbreviation: emmetConfig['showExpandedAbbreviation'],
628-
showAbbreviationSuggestions: emmetConfig['showAbbreviationSuggestions'],
627+
showExpandedAbbreviation: emmetConfig.showExpandedAbbreviation,
628+
showAbbreviationSuggestions: emmetConfig.showAbbreviationSuggestions,
629629
syntaxProfiles,
630-
variables: emmetConfig['variables'],
631-
excludeLanguages: emmetConfig['excludeLanguages'],
632-
showSuggestionsAsSnippets: emmetConfig['showSuggestionsAsSnippets']
630+
variables: emmetConfig.variables,
631+
excludeLanguages: emmetConfig.excludeLanguages,
632+
showSuggestionsAsSnippets: emmetConfig.showSuggestionsAsSnippets
633633
};
634634
}
635635

extensions/html-language-features/client/src/autoInsertion.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export function activateAutoInsertion(provider: (kind: 'autoQuote' | 'autoClose'
3838
return;
3939
}
4040
const configurations = workspace.getConfiguration(undefined, document.uri);
41-
isEnabled['autoQuote'] = configurations.get<boolean>('html.autoCreateQuotes') ?? false;
42-
isEnabled['autoClose'] = configurations.get<boolean>('html.autoClosingTags') ?? false;
43-
anyIsEnabled = isEnabled['autoQuote'] || isEnabled['autoClose'];
41+
isEnabled.autoQuote = configurations.get<boolean>('html.autoCreateQuotes') ?? false;
42+
isEnabled.autoClose = configurations.get<boolean>('html.autoClosingTags') ?? false;
43+
anyIsEnabled = isEnabled.autoQuote || isEnabled.autoClose;
4444
}
4545

4646
function onDidChangeTextDocument({ document, contentChanges, reason }: TextDocumentChangeEvent) {
@@ -58,9 +58,9 @@ export function activateAutoInsertion(provider: (kind: 'autoQuote' | 'autoClose'
5858
const lastChange = contentChanges[contentChanges.length - 1];
5959
if (lastChange.rangeLength === 0 && isSingleLine(lastChange.text)) {
6060
const lastCharacter = lastChange.text[lastChange.text.length - 1];
61-
if (isEnabled['autoQuote'] && lastCharacter === '=') {
61+
if (isEnabled.autoQuote && lastCharacter === '=') {
6262
doAutoInsert('autoQuote', document, lastChange);
63-
} else if (isEnabled['autoClose'] && (lastCharacter === '>' || lastCharacter === '/')) {
63+
} else if (isEnabled.autoClose && (lastCharacter === '>' || lastCharacter === '/')) {
6464
doAutoInsert('autoClose', document, lastChange);
6565
}
6666
}

extensions/html-language-features/server/src/modes/languageModes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ export function getLanguageModes(supportedLanguages: { [languageId: string]: boo
123123
modelCaches.push(documentRegions);
124124

125125
let modes = Object.create(null);
126-
modes['html'] = getHTMLMode(htmlLanguageService, workspace);
127-
if (supportedLanguages['css']) {
128-
modes['css'] = getCSSMode(cssLanguageService, documentRegions, workspace);
126+
modes.html = getHTMLMode(htmlLanguageService, workspace);
127+
if (supportedLanguages.css) {
128+
modes.css = getCSSMode(cssLanguageService, documentRegions, workspace);
129129
}
130-
if (supportedLanguages['javascript']) {
131-
modes['javascript'] = getJavaScriptMode(documentRegions, 'javascript', workspace);
132-
modes['typescript'] = getJavaScriptMode(documentRegions, 'typescript', workspace);
130+
if (supportedLanguages.javascript) {
131+
modes.javascript = getJavaScriptMode(documentRegions, 'javascript', workspace);
132+
modes.typescript = getJavaScriptMode(documentRegions, 'typescript', workspace);
133133
}
134134
return {
135135
async updateDataProviders(dataProviders: IHTMLDataProvider[]): Promise<void> {

extensions/json-language-features/client/src/node/jsonClientMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async function getSchemaRequestService(context: ExtensionContext, log: LogOutput
118118

119119
const response = await xhr({ url: uri, followRedirects: 5, headers });
120120
if (cache) {
121-
const etag = response.headers['etag'];
121+
const etag = response.headers.etag;
122122
if (typeof etag === 'string') {
123123
log.trace(`[json schema cache] Storing schema ${uri} etag ${etag} in cache`);
124124
await cache.putSchema(uri, etag, response.responseText);

extensions/markdown-language-features/src/languageFeatures/copyFiles/copyFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function resolveCopyDestinationSetting(documentUri: vscode.Uri, fileName: string
101101
]);
102102

103103
return outDest.replaceAll(/(?<escape>\\\$)|(?<!\\)\$\{(?<name>\w+)(?:\/(?<pattern>(?:\\\/|[^\}\/])+)\/(?<replacement>(?:\\\/|[^\}\/])*)\/)?\}/g, (match, _escape, name, pattern, replacement, _offset, _str, groups) => {
104-
if (groups?.['escape']) {
104+
if (groups?.escape) {
105105
return '$';
106106
}
107107

0 commit comments

Comments
 (0)