Skip to content
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

Adjust ESLint rules to match the VS Code rules #1377

Merged
merged 2 commits into from
Dec 6, 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
50 changes: 47 additions & 3 deletions .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,56 @@
},
"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-node-tests/src/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ suite('Protocol Converter', () => {

const result = await p2c.asInlayHints(items);
ok(result.every(hint => hint instanceof ProtocolInlayHint));
for (var i = 0; i < result.length; i++) {
for (let i = 0; i < result.length; i++) {
positionEqual(result[i].position, items[i].position);
}
strictEqual((result[0] as ProtocolInlayHint).data, '1');
Expand Down
48 changes: 24 additions & 24 deletions client-node-tests/src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ suite('Protocol Helper Tests', () => {
}

test('Position', () => {
let position: Position = Position.create(1, 2);
const position: Position = Position.create(1, 2);
strictEqual(position.line, 1);
strictEqual(position.character, 2);
ok(Position.is(position));
});

test('Range - start/end', () => {
let range: Range = Range.create(Position.create(1, 2), Position.create(8,9));
const range: Range = Range.create(Position.create(1, 2), Position.create(8,9));
strictEqual(range.start.line, 1);
strictEqual(range.start.character, 2);
strictEqual(range.end.line, 8);
Expand All @@ -36,7 +36,7 @@ suite('Protocol Helper Tests', () => {
});

test('Range - line/character', () => {
let range: Range = Range.create(1,2,8,9);
const range: Range = Range.create(1,2,8,9);
strictEqual(range.start.line, 1);
strictEqual(range.start.character, 2);
strictEqual(range.end.line, 8);
Expand All @@ -45,15 +45,15 @@ suite('Protocol Helper Tests', () => {
});

test('TextDocumentIdentifier', () => {
let uri = 'file:///folder/file.txt';
let identifier = TextDocumentIdentifier.create(uri);
const uri = 'file:///folder/file.txt';
const identifier = TextDocumentIdentifier.create(uri);
strictEqual(identifier.uri, uri);
ok(TextDocumentIdentifier.is(identifier));
});

test('VersionedTextDocumentIdentifier', () => {
let uri = 'file:///folder/file.txt';
let identifier = VersionedTextDocumentIdentifier.create(uri, 9);
const uri = 'file:///folder/file.txt';
const identifier = VersionedTextDocumentIdentifier.create(uri, 9);
strictEqual(identifier.uri, uri);
strictEqual(identifier.version, 9);
ok(VersionedTextDocumentIdentifier.is(identifier));
Expand All @@ -68,8 +68,8 @@ suite('Protocol Helper Tests', () => {
// });

test('TextDocumentItem', () => {
let uri = 'file:///folder/file.txt';
let item = TextDocumentItem.create(uri, 'pain-text', 9, 'content');
const uri = 'file:///folder/file.txt';
const item = TextDocumentItem.create(uri, 'pain-text', 9, 'content');
strictEqual(item.uri, uri);
strictEqual(item.languageId, 'pain-text');
strictEqual(item.version, 9);
Expand All @@ -78,7 +78,7 @@ suite('Protocol Helper Tests', () => {
});

test('Diagnostic', () => {
let diagnostic = Diagnostic.create(Range.create(1,2,8,9), 'message', DiagnosticSeverity.Warning, 99, 'source');
const diagnostic = Diagnostic.create(Range.create(1,2,8,9), 'message', DiagnosticSeverity.Warning, 99, 'source');
ok(Range.is(diagnostic.range));
strictEqual(diagnostic.message, 'message');
strictEqual(diagnostic.severity, DiagnosticSeverity.Warning);
Expand All @@ -87,15 +87,15 @@ suite('Protocol Helper Tests', () => {
});

test('Command', () => {
let command = Command.create('title', 'command', 'arg');
const command = Command.create('title', 'command', 'arg');
strictEqual(command.title, 'title');
strictEqual(command.command, 'command');
strictEqual(command.arguments![0], 'arg');
});

test('CodeLens', () => {
let codeLens = CodeLens.create(Range.create(1,2,8,9), 'data');
let range = codeLens.range;
const codeLens = CodeLens.create(Range.create(1,2,8,9), 'data');
const range = codeLens.range;
strictEqual(range.start.line, 1);
strictEqual(range.start.character, 2);
strictEqual(range.end.line, 8);
Expand All @@ -104,22 +104,22 @@ suite('Protocol Helper Tests', () => {
});

test('CodeActionContext', () => {
let codeActionContext = CodeActionContext.create([Diagnostic.create(Range.create(1, 2, 8, 9), 'message')]);
const codeActionContext = CodeActionContext.create([Diagnostic.create(Range.create(1, 2, 8, 9), 'message')]);
strictEqual(codeActionContext.diagnostics.length, 1);
ok(Diagnostic.is(codeActionContext.diagnostics[0]));
});

test('WorkspaceEdit - documentChanges', () => {
let workspaceChange = new WorkspaceChange();
let uri = 'file:///abc.txt';
let change1 = workspaceChange.getTextEditChange({uri: uri, version: 10});
const workspaceChange = new WorkspaceChange();
const uri = 'file:///abc.txt';
const change1 = workspaceChange.getTextEditChange({uri: uri, version: 10});
change1.insert(Position.create(0,1), 'insert');
change1.replace(Range.create(0,1,2,3), 'replace');
change1.delete(Range.create(0,1,2,3));
let change2 = workspaceChange.getTextEditChange({ uri: 'file:///xyz.txt', version: 20 });
const change2 = workspaceChange.getTextEditChange({ uri: 'file:///xyz.txt', version: 20 });
change2.insert(Position.create(2,3), 'insert');

let workspaceEdit = workspaceChange.edit;
const workspaceEdit = workspaceChange.edit;
strictEqual(workspaceEdit.changeAnnotations, undefined);
strictEqual(workspaceEdit.documentChanges!.length, 2);
let edits = (workspaceEdit.documentChanges![0] as TextDocumentEdit).edits;
Expand Down Expand Up @@ -151,16 +151,16 @@ suite('Protocol Helper Tests', () => {
});

test('WorkspaceEdit - changes', () => {
let workspaceChange = new WorkspaceChange();
let uri = 'file:///abc.txt';
let change1 = workspaceChange.getTextEditChange(uri);
const workspaceChange = new WorkspaceChange();
const uri = 'file:///abc.txt';
const change1 = workspaceChange.getTextEditChange(uri);
change1.insert(Position.create(0,1), 'insert');
change1.replace(Range.create(0,1,2,3), 'replace');
change1.delete(Range.create(0,1,2,3));
let change2 = workspaceChange.getTextEditChange('file:///xyz.txt');
const change2 = workspaceChange.getTextEditChange('file:///xyz.txt');
change2.insert(Position.create(2,3), 'insert');

let workspaceEdit = workspaceChange.edit;
const workspaceEdit = workspaceChange.edit;
strictEqual(workspaceEdit.changeAnnotations, undefined);
strictEqual(Object.keys(workspaceEdit.changes!).length, 2);
let edits = workspaceEdit.changes![uri];
Expand Down
7 changes: 6 additions & 1 deletion client-node-tests/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ suite('Client integration', () => {
});

test('InitializeResult', () => {
let expected = {
const expected = {
capabilities: {
textDocumentSync: 1,
definitionProvider: true,
Expand Down Expand Up @@ -955,6 +955,7 @@ suite('Client integration', () => {
const feature = client.getFeature(lsclient.WillCreateFilesRequest.method);
isDefined(feature);

// eslint-disable-next-line no-async-promise-executor
const sendCreateRequest = () => new Promise<vscode.WorkspaceEdit>(async (resolve, reject) => {
await feature.send({ files: createFiles, waitUntil: resolve, token: tokenSource.token });
// If feature.send didn't call waitUntil synchronously then something went wrong.
Expand Down Expand Up @@ -1039,6 +1040,7 @@ suite('Client integration', () => {
const feature = client.getFeature(lsclient.WillRenameFilesRequest.method);
isDefined(feature);

// eslint-disable-next-line no-async-promise-executor
const sendRenameRequest = () => new Promise<vscode.WorkspaceEdit>(async (resolve, reject) => {
await feature.send({ files: renameFiles, waitUntil: resolve, token: tokenSource.token });
// If feature.send didn't call waitUntil synchronously then something went wrong.
Expand Down Expand Up @@ -1087,6 +1089,7 @@ suite('Client integration', () => {
// DidRename relies on WillRename firing first and the items existing on disk in their correct locations
// so that the type of the items can be checked and stashed before they're actually renamed.
await createTestItems(renameFiles.map((f) => f.oldUri));
// eslint-disable-next-line no-async-promise-executor
await new Promise<vscode.WorkspaceEdit>(async (resolve, reject) => {
const featureWithWillRename = feature as any as { willRename(e: vscode.FileWillRenameEvent): void };
featureWithWillRename.willRename({ files: renameFiles, waitUntil: resolve, token: tokenSource.token });
Expand Down Expand Up @@ -1137,6 +1140,7 @@ suite('Client integration', () => {
const feature = client.getFeature(lsclient.WillDeleteFilesRequest.method);
isDefined(feature);

// eslint-disable-next-line no-async-promise-executor
const sendDeleteRequest = () => new Promise<vscode.WorkspaceEdit>(async (resolve, reject) => {
await feature.send({ files: deleteFiles, waitUntil: resolve, token: tokenSource.token });
// If feature.send didn't call waitUntil synchronously then something went wrong.
Expand Down Expand Up @@ -1185,6 +1189,7 @@ suite('Client integration', () => {
// DidDelete relies on WillDelete firing first and the items actually existing on disk
// so that the type of the items can be checked and stashed before they're actually deleted.
await createTestItems(deleteFiles);
// eslint-disable-next-line no-async-promise-executor
await new Promise<vscode.WorkspaceEdit>(async (resolve, reject) => {
const featureWithWillDelete = feature as any as { willDelete(e: vscode.FileWillDeleteEvent): void };
featureWithWillDelete.willDelete({ files: deleteFiles, waitUntil: resolve, token: tokenSource.token });
Expand Down
Loading