Skip to content

Update eslint rules #1743

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
Dec 8, 2023
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
8 changes: 4 additions & 4 deletions $shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export namespace CodeActionsOnSaveRules {
}

export type CodeActionsOnSaveSettings = {
mode: CodeActionsOnSaveMode,
rules?: string[]
mode: CodeActionsOnSaveMode;
rules?: string[];
};

export enum ESLintSeverity {
Expand Down Expand Up @@ -125,7 +125,7 @@ export namespace ModeEnum {
}

export type ModeItem = {
mode: ModeEnum
mode: ModeEnum;
};

export namespace ModeItem {
Expand Down Expand Up @@ -157,7 +157,7 @@ export type ConfigurationSettings = {
useESLintClass: boolean;
experimental: {
useFlatConfig: boolean;
}
};
codeAction: CodeActionSettings;
codeActionOnSave: CodeActionsOnSaveSettings;
format: boolean;
Expand Down
61 changes: 58 additions & 3 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,67 @@
"rules": {
"semi": "off",
"@typescript-eslint/semi": "error",
"@typescript-eslint/member-delimiter-style": ["error" ,{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
},
"multilineDetection": "brackets"
}],
"indent": "off",
"@typescript-eslint/indent": ["warn", "tab", { "SwitchCase": 1 } ],
"@typescript-eslint/no-floating-promises": "error",
"no-extra-semi": "warn",
"curly": "warn",
"quotes": ["error", "single", { "allowTemplateLiterals": true } ],
"eqeqeq": "error",
"indent": "off",
"@typescript-eslint/indent": ["warn", "tab", { "SwitchCase": 1 } ],
"@typescript-eslint/no-floating-promises": "error"
"constructor-super": "warn",
"prefer-const": [
"warn",
{
"destructuring": "all"
}
],
"no-buffer-constructor": "warn",
"no-caller": "warn",
"no-case-declarations": "warn",
"no-debugger": "warn",
"no-duplicate-case": "warn",
"no-duplicate-imports": "warn",
"no-eval": "warn",
"no-async-promise-executor": "warn",
"no-new-wrappers": "warn",
"no-redeclare": "off",
"no-sparse-arrays": "warn",
"no-throw-literal": "warn",
"no-unsafe-finally": "warn",
"no-unused-labels": "warn",
"no-restricted-globals": [
"warn",
"name",
"length",
"event",
"closed",
"external",
"status",
"origin",
"orientation",
"context"
],
"no-var": "warn",
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "class",
"format": [
"PascalCase"
],
"leadingUnderscore": "allow"
}
]
}
}
2 changes: 1 addition & 1 deletion client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace ESLintClient {

type PerformanceStatus = {
firstReport: boolean;
validationTime: number
validationTime: number;
fixTime: number;
reported: number;
acknowledged: boolean;
Expand Down
10 changes: 6 additions & 4 deletions client/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class PatternParser {
}

next(): Node | undefined {
let start = this.index;
const start = this.index;
let ch: string | undefined;
while((ch = this.value[this.index]) !== this.stopChar) {
switch (ch) {
Expand Down Expand Up @@ -197,16 +197,18 @@ class PatternParser {
case ',':
if (this.mode === 'brace') {
if (start < this.index) {
let result = this.makeTextNode(start);
const result = this.makeTextNode(start);
this.index++;
return result;
}
}
this.index++;
break;
case '[':
// eslint-disable-next-line no-case-declarations
const buffer: string[] = [];
this.index++;
// eslint-disable-next-line no-case-declarations
const firstIndex = this.index;
while (this.index < this.value.length) {
const ch = this.value[this.index];
Expand Down Expand Up @@ -270,7 +272,7 @@ export function convert2RegExp(pattern: string): RegExp | undefined {
case NodeType.bracket:
return `[${node.value}]`;
case NodeType.brace: {
let buffer: string[] = [];
const buffer: string[] = [];
for (const child of node.alternatives) {
buffer.push(convertNode(child));
}
Expand All @@ -282,7 +284,7 @@ export function convert2RegExp(pattern: string): RegExp | undefined {
try {
const buffer: string[] = ['^'];

let parser = new PatternParser(pattern);
const parser = new PatternParser(pattern);
let node: Node | undefined;
while ((node = parser.next()) !== undefined) {
buffer.push(convertNode(node));
Expand Down
2 changes: 1 addition & 1 deletion client/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export namespace PatternItem {
type InspectData<T> = {
globalValue?: T;
workspaceValue?: T;
workspaceFolderValue?: T
workspaceFolderValue?: T;
};

type MigrationElement<T> = {
Expand Down
12 changes: 6 additions & 6 deletions client/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ export class TaskProvider {
* The workspace folders have changed.
*/
private updateWorkspaceFolders(added: ReadonlyArray<vscode.WorkspaceFolder>, removed: ReadonlyArray<vscode.WorkspaceFolder>): void {
for (let remove of removed) {
for (const remove of removed) {
const provider = this.providers.get(remove.uri.toString());
if (provider) {
provider.dispose();
this.providers.delete(remove.uri.toString());
}
}
for (let add of added) {
for (const add of added) {
const provider = new FolderTaskProvider(add);
if (provider.isEnabled()) {
this.providers.set(add.uri.toString(), provider);
Expand All @@ -134,17 +134,17 @@ export class TaskProvider {
* The configuration has changed.
*/
private updateConfiguration(): void {
for (let detector of this.providers.values()) {
for (const detector of this.providers.values()) {
if (!detector.isEnabled()) {
detector.dispose();
this.providers.delete(detector.workspaceFolder.uri.toString());
}
}
const folders = vscode.workspace.workspaceFolders;
if (folders) {
for (let folder of folders) {
for (const folder of folders) {
if (!this.providers.has(folder.uri.toString())) {
let provider = new FolderTaskProvider(folder);
const provider = new FolderTaskProvider(folder);
if (provider.isEnabled()) {
this.providers.set(folder.uri.toString(), provider);
provider.start();
Expand Down Expand Up @@ -176,7 +176,7 @@ export class TaskProvider {
return [];
} else {
const promises: Promise<vscode.Task | undefined>[] = [];
for (let provider of this.providers.values()) {
for (const provider of this.providers.values()) {
promises.push(provider.getTask());
}
const values = await Promise.all(promises);
Expand Down
4 changes: 2 additions & 2 deletions client/src/tests/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function toOSPath(path: string): string {

suite('Glob', () => {
test('Simple', () => {
let regExp = convert2RegExp('/test/*/');
const regExp = convert2RegExp('/test/*/');
isDefined(regExp);
let matches = regExp.exec(toOSPath('/test/foo/bar/file.txt'));
const matches = regExp.exec(toOSPath('/test/foo/bar/file.txt'));
isDefined(matches);
assert.strictEqual(matches.length, 1);
assert.strictEqual(matches[0], toOSPath('/test/foo/'));
Expand Down
4 changes: 2 additions & 2 deletions server/src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ export class LcsDiff {
change.modifiedStart++;
}

let mergedChangeArr: Array<DiffChange | null> = [null];
const mergedChangeArr: Array<DiffChange | null> = [null];
if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) {
changes[i] = mergedChangeArr[0]!;
changes.splice(i + 1, 1);
Expand Down Expand Up @@ -987,7 +987,7 @@ export class LcsDiff {
* @returns The concatenated list
*/
private ConcatenateChanges(left: DiffChange[], right: DiffChange[]): DiffChange[] {
let mergedChangeArr: DiffChange[] = [];
const mergedChangeArr: DiffChange[] = [];

if (left.length === 0 || right.length === 0) {
return (right.length > 0) ? right : left;
Expand Down
20 changes: 10 additions & 10 deletions server/src/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type ESLintProblem = {
ruleId: string;
message: string;
fix?: ESLintAutoFixEdit;
suggestions?: ESLintSuggestionResult[]
suggestions?: ESLintSuggestionResult[];
};

type ESLintDocumentReport = {
Expand Down Expand Up @@ -248,7 +248,7 @@ export namespace SuggestionsProblem {

interface ESLintClass {
// https://eslint.org/docs/developer-guide/nodejs-api#-eslintlinttextcode-options
lintText(content: string, options: {filePath?: string, warnIgnored?: boolean}): Promise<ESLintDocumentReport[]>;
lintText(content: string, options: {filePath?: string; warnIgnored?: boolean}): Promise<ESLintDocumentReport[]>;
// https://eslint.org/docs/developer-guide/nodejs-api#-eslintispathignoredfilepath
isPathIgnored(path: string): Promise<boolean>;
// https://eslint.org/docs/developer-guide/nodejs-api#-eslintgetrulesmetaforresultsresults
Expand Down Expand Up @@ -287,10 +287,10 @@ export type ESLintModule =
};

export namespace ESLintModule {
export function hasESLintClass(value: ESLintModule): value is { ESLint: ESLintClassConstructor; CLIEngine: undefined; } {
export function hasESLintClass(value: ESLintModule): value is { ESLint: ESLintClassConstructor; CLIEngine: undefined } {
return value.ESLint !== undefined;
}
export function hasCLIEngine(value: ESLintModule): value is { ESLint: undefined; CLIEngine: CLIEngineConstructor; } {
export function hasCLIEngine(value: ESLintModule): value is { ESLint: undefined; CLIEngine: CLIEngineConstructor } {
return value.CLIEngine !== undefined;
}
export function isFlatConfig(value: ESLintModule): value is { ESLint: ESLintClassConstructor; CLIEngine: undefined; isFlatConfig: true } {
Expand All @@ -305,7 +305,7 @@ type RuleData = {
};

namespace RuleData {
export function hasMetaType(value: RuleMetaData | undefined): value is RuleMetaData & { type: string; } {
export function hasMetaType(value: RuleMetaData | undefined): value is RuleMetaData & { type: string } {
return value !== undefined && value.type !== undefined;
}
}
Expand Down Expand Up @@ -337,7 +337,7 @@ class ESLintClassEmulator implements ESLintClass {
get isCLIEngine(): boolean {
return true;
}
async lintText(content: string, options: { filePath?: string | undefined; warnIgnored?: boolean | undefined; }): Promise<ESLintDocumentReport[]> {
async lintText(content: string, options: { filePath?: string | undefined; warnIgnored?: boolean | undefined }): Promise<ESLintDocumentReport[]> {
return this.cli.executeOnText(content, options.filePath, options.warnIgnored).results;
}
async isPathIgnored(path: string): Promise<boolean> {
Expand Down Expand Up @@ -440,7 +440,7 @@ export class Fixes {
let last: FixableProblem = sorted[0];
result.push(last);
for (let i = 1; i < sorted.length; i++) {
let current = sorted[i];
const current = sorted[i];
if (!Fixes.overlaps(last, current) && !Fixes.sameRange(last, current)) {
result.push(current);
last = current;
Expand All @@ -450,7 +450,7 @@ export class Fixes {
}
}

export type SaveRuleConfigItem = { offRules: Set<string>, onRules: Set<string>};
export type SaveRuleConfigItem = { offRules: Set<string>; onRules: Set<string>};

/**
* Manages the special save rule configurations done in the VS Code settings.
Expand Down Expand Up @@ -924,7 +924,7 @@ export namespace ESLint {
}
if (settings.validate === Validate.probe && TextDocumentSettings.hasLibrary(settings)) {
settings.validate = Validate.off;
let filePath = ESLint.getFilePath(document, settings);
const filePath = ESLint.getFilePath(document, settings);
if (filePath !== undefined) {
const parserRegExps = languageId2ParserRegExp.get(document.languageId);
const pluginName = languageId2PluginName.get(document.languageId);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ export namespace ESLint {
* Global paths for the different package managers
*/
namespace GlobalPaths {
const globalPaths: Record<string, { cache: string | undefined; get(): string | undefined; }> = {
const globalPaths: Record<string, { cache: string | undefined; get(): string | undefined }> = {
yarn: {
cache: undefined,
get(): string | undefined {
Expand Down
4 changes: 2 additions & 2 deletions server/src/eslintServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ namespace Thenable {
class BufferedMessageQueue {

private queue: Message<any, any>[];
private requestHandlers: Map<string, { handler: RequestHandler<any, any, any>, versionProvider?: VersionProvider<any> }>;
private notificationHandlers: Map<string, { handler: NotificationHandler<any>, versionProvider?: VersionProvider<any> }>;
private requestHandlers: Map<string, { handler: RequestHandler<any, any, any>; versionProvider?: VersionProvider<any> }>;
private notificationHandlers: Map<string, { handler: NotificationHandler<any>; versionProvider?: VersionProvider<any> }>;
private timer: NodeJS.Immediate | undefined;

constructor(private connection: Connection) {
Expand Down