Skip to content

Commit

Permalink
Closes #4483: migrate to eslint (#8702)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foo-x authored Dec 23, 2023
1 parent de30a00 commit d712063
Show file tree
Hide file tree
Showing 74 changed files with 7,122 additions and 6,335 deletions.
231 changes: 231 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['eslint-plugin-jsdoc', 'eslint-plugin-prefer-arrow', '@typescript-eslint'],
root: true,
ignorePatterns: ['*.js'],
rules: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple',
},
],
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/ban-types': [
'error',
{
types: {
Object: {
message: 'Avoid using the `Object` type. Did you mean `object`?',
},
Function: {
message:
'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
},
Boolean: {
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?',
},
Number: {
message: 'Avoid using the `Number` type. Did you mean `number`?',
},
String: {
message: 'Avoid using the `String` type. Did you mean `string`?',
},
Symbol: {
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?',
},
},
},
],
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'forbid',
},
],
'@typescript-eslint/no-array-constructor': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-duplicate-enum-values': 'error',
'@typescript-eslint/no-duplicate-type-constituents': 'error',
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-loss-of-precision': 'error',
'@typescript-eslint/no-misused-new': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/parameter-properties': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'error',
'@typescript-eslint/no-shadow': [
'error',
{
hoist: 'all',
},
],
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'error',
// ignore the rule to conform to current code
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
{
path: 'always',
types: 'prefer-import',
lib: 'always',
},
],
'@typescript-eslint/typedef': 'off',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
complexity: 'off',
'constructor-super': 'error',
'dot-notation': 'off',
eqeqeq: ['error', 'smart'],
'guard-for-in': 'error',
'id-denylist': [
'error',
'any',
'Number',
'number',
'String',
'string',
'Boolean',
'boolean',
'Undefined',
'undefined',
],
'id-match': 'error',
'jsdoc/check-alignment': 'error',
// ignore the rule to conform to current code
'jsdoc/check-indentation': 'off',
'max-classes-per-file': 'off',
'new-parens': 'error',
'no-array-constructor': 'off',
'no-bitwise': 'error',
'no-caller': 'error',
'no-cond-assign': 'error',
'no-console': [
'error',
{
allow: [
'log',
'warn',
'dir',
'timeLog',
'assert',
'clear',
'count',
'countReset',
'group',
'groupEnd',
'table',
'dirxml',
'error',
'groupCollapsed',
'Console',
'profile',
'profileEnd',
'timeStamp',
'context',
],
},
],
'no-debugger': 'error',
'no-empty': 'error',
'no-empty-function': 'off',
'no-eval': 'error',
'no-fallthrough': 'error',
'no-implied-eval': 'off',
'no-invalid-this': 'off',
'no-loss-of-precision': 'off',
'no-new-wrappers': 'error',
'no-redeclare': 'error',
'no-return-await': 'error',
'no-shadow': 'off',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unsafe-finally': 'error',
'no-unused-expressions': 'off',
'no-unused-labels': 'error',
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-arrow/prefer-arrow-functions': [
'error',
{
allowStandaloneDeclarations: true,
},
],
'prefer-const': [
'error',
{
destructuring: 'all',
},
],
radix: 'error',
'require-await': 'off',
'spaced-comment': [
'error',
'always',
{
markers: ['/'],
},
],
'use-isnan': 'error',
'valid-typeof': 'off',
},
};
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": ["esbenp.prettier-vscode", "ms-vscode.vscode-typescript-tslint-plugin"],
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
82 changes: 43 additions & 39 deletions extensionBase.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import * as vscode from 'vscode';

import { CompositionState } from './src/state/compositionState';
import { ExCommandLine, SearchCommandLine } from './src/cmd_line/commandLine';
import { configuration } from './src/configuration/configuration';
import { Notation } from './src/configuration/notation';
import { Globals } from './src/globals';
import { Jump } from './src/jumps/jump';
import { Mode } from './src/mode/mode';
import { ModeHandler } from './src/mode/modeHandler';
import { ModeHandlerMap } from './src/mode/modeHandlerMap';
import { Mode } from './src/mode/mode';
import { Notation } from './src/configuration/notation';
import { Logger } from './src/util/logger';
import { StatusBar } from './src/statusBar';
import { VSCodeContext } from './src/util/vscodeContext';
import { ExCommandLine, SearchCommandLine } from './src/cmd_line/commandLine';
import { configuration } from './src/configuration/configuration';
import { globalState } from './src/state/globalState';
import { Register } from './src/register/register';
import { CompositionState } from './src/state/compositionState';
import { globalState } from './src/state/globalState';
import { StatusBar } from './src/statusBar';
import { taskQueue } from './src/taskQueue';
import { Logger } from './src/util/logger';
import { SpecialKeys } from './src/util/specialKeys';
import { VSCodeContext } from './src/util/vscodeContext';
import { exCommandParser } from './src/vimscript/exCommandParser';
import { taskQueue } from './src/taskQueue';

let extensionContext: vscode.ExtensionContext;
let previousActiveEditorUri: vscode.Uri | undefined;
Expand Down Expand Up @@ -355,15 +355,15 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
const compositionState = new CompositionState();

// Override VSCode commands
overrideCommand(context, 'type', async (args) => {
overrideCommand(context, 'type', async (args: { text: string }) => {
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();
if (mh) {
if (compositionState.isInComposition) {
compositionState.composingText += args.text;
if (mh.vimState.currentMode === Mode.Insert) {
compositionState.insertedText = true;
vscode.commands.executeCommand('default:type', { text: args.text });
void vscode.commands.executeCommand('default:type', { text: args.text });
}
} else {
await mh.handleKeyEvent(args.text);
Expand All @@ -372,33 +372,37 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
});
});

overrideCommand(context, 'replacePreviousChar', async (args) => {
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();
if (mh) {
if (compositionState.isInComposition) {
compositionState.composingText =
compositionState.composingText.substr(
0,
compositionState.composingText.length - args.replaceCharCnt,
) + args.text;
}
if (compositionState.insertedText) {
overrideCommand(
context,
'replacePreviousChar',
async (args: { replaceCharCnt: number; text: string }) => {
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();
if (mh) {
if (compositionState.isInComposition) {
compositionState.composingText =
compositionState.composingText.substr(
0,
compositionState.composingText.length - args.replaceCharCnt,
) + args.text;
}
if (compositionState.insertedText) {
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt,
});
mh.vimState.cursorStopPosition = mh.vimState.editor.selection.start;
mh.vimState.cursorStartPosition = mh.vimState.editor.selection.start;
}
} else {
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt,
});
mh.vimState.cursorStopPosition = mh.vimState.editor.selection.start;
mh.vimState.cursorStartPosition = mh.vimState.editor.selection.start;
}
} else {
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt,
});
}
});
});
});
},
);

overrideCommand(context, 'compositionStart', async () => {
taskQueue.enqueueTask(async () => {
Expand Down Expand Up @@ -440,7 +444,7 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
if (cmd) {
await new ExCommandLine(cmd, mh.vimState.currentMode).run(mh.vimState);
}
mh.updateView();
void mh.updateView();
}
});

Expand Down Expand Up @@ -471,7 +475,7 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
command.command.slice(1, command.command.length),
mh.vimState.currentMode,
).run(mh.vimState);
mh.updateView();
void mh.updateView();
} else {
await vscode.commands.executeCommand(command.command, command.args);
}
Expand All @@ -482,7 +486,7 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo

registerCommand(context, 'toggleVim', async () => {
configuration.disableExtension = !configuration.disableExtension;
toggleExtension(configuration.disableExtension, compositionState);
void toggleExtension(configuration.disableExtension, compositionState);
});

for (const boundKey of configuration.boundKeyCombinations) {
Expand Down Expand Up @@ -525,7 +529,7 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
}

// This is called last because getAndUpdateModeHandler() will change cursor
modeHandler.updateView({ drawSelection: true, revealRange: false });
void modeHandler.updateView({ drawSelection: true, revealRange: false });
}
}

Expand Down Expand Up @@ -579,7 +583,7 @@ function overrideCommand(
return vscode.commands.executeCommand('default:' + command, args);
}

return callback(args);
return callback(args) as vscode.Disposable;
});
context.subscriptions.push(disposable);
}
Expand Down
Loading

0 comments on commit d712063

Please sign in to comment.