Skip to content

Commit

Permalink
dev/update eslint (#1915)
Browse files Browse the repository at this point in the history
* Update ESLint

* Install typescript-eslint and setup the config

* Fix source files

* Fix .nvmrc

* Fix keybinding-generator/cli.mts caller
  • Loading branch information
whitphx authored May 20, 2024
1 parent 765344d commit 592fc96
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 391 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.17.1
lts/hydrogen
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config({
ignores: ["src/vs/**"],
extends: [eslint.configs.recommended, ...tseslint.configs.recommended],
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "textEditor|isInMarkMode|prefixArgument",
},
],
},
});
7 changes: 4 additions & 3 deletions keybinding-generator/cli.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env node */

import * as fs from "fs";
import fs from "node:fs";
import url from "node:url";
import stripJsonComments from "strip-json-comments";
import {
KeyBinding,
Expand All @@ -11,8 +12,8 @@ import {
generateKeybindingsForRegisterCommands,
} from "./generate-keybindings.mjs";

const srcFilePath = "./keybindings.json";
const packageDotJsonPath = "./package.json";
const srcFilePath = url.fileURLToPath(import.meta.resolve("../keybindings.json"));
const packageDotJsonPath = url.fileURLToPath(import.meta.resolve("../package.json"));

console.info(`Reading ${srcFilePath} ...`);
const srcContent = fs.readFileSync(srcFilePath, "utf8");
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5716,12 +5716,12 @@
"webpack:prod": "webpack --mode production --devtool hidden-source-map",
"webpack": "yarn webpack:dev",
"test-compile": "tspc -p ./",
"gen-keys": "ts-node --esm ./keybinding-generator/cli.mts",
"gen-keys": "yarn node --into ./keybinding-generator --loader ts-node/esm cli.mts",
"test-gen-keys": "TS_NODE_PROJECT='keybinding-generator/tsconfig.json' NODE_OPTIONS='--loader ts-node/esm' yarn mocha --require ts-node/register './keybinding-generator/*.test.*'",
"fix:prettier": "prettier --write .",
"fix:eslint": "eslint src --ext ts --fix",
"fix:eslint": "eslint src --fix",
"check:prettier": "prettier --check .",
"check:eslint": "eslint src --ext ts",
"check:eslint": "eslint src",
"pretest": "yarn run test-compile",
"test": "node ./out/test/runTest.js",
"test:web": "./scripts/run-web-test.sh",
Expand All @@ -5732,18 +5732,17 @@
"prepare": "husky install"
},
"devDependencies": {
"@eslint/js": "^9.2.0",
"@types/glob": "^8.0.1",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.12",
"@types/sinon": "^17.0.3",
"@types/vscode": "^1.89.0",
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vscode/test-electron": "^2.3.10",
"@vscode/test-web": "^0.0.54",
"assert": "^2.1.0",
"eslint": "^7.32.0",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"glob": "^8.1.0",
"husky": "^9.0.11",
Expand All @@ -5759,6 +5758,7 @@
"ts-patch": "^3.0.2",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.9.0",
"typescript-transform-paths": "^3.4.7",
"vsce": "^2.15.0",
"webpack": "^5.91.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/delete-blank-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DeleteBlankLines extends EmacsCommand {
// therefore, each selection must be obtained
// by indexing on each iteration.
// That's why for-of loop is not appropriate here.
const selection = textEditor.selections[iSel]!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const selection = textEditor.selections[iSel]!;

const curLineNum = selection.active.line;
const curLine = document.lineAt(curLineNum);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ abstract class EditRectangle extends RectangleKillYankCommand {
// multiple cursor not supported
return;
}
const selection = selections[0]!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const selection = selections[0]!;

const notReversedSelection = new vscode.Selection(selection.start, selection.end);

Expand Down Expand Up @@ -138,7 +138,7 @@ export class YankRectangle extends RectangleKillYankCommand {
}

const rectHeight = killedRect.length - 1;
const rectWidth = killedRect[rectHeight]!.length; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const rectWidth = killedRect[rectHeight]!.length;

const active = textEditor.selection.active; // Multi-cursor is not supported
await textEditor.edit((edit) => {
Expand Down Expand Up @@ -296,7 +296,7 @@ export class ReplaceKillRingToRectangle extends EmacsCommand {
// multiple cursor not supported
return;
}
const selection = selections[0]!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const selection = selections[0]!;

const insertChar = Math.min(selection.start.character, selection.end.character);
const finalCursorLine = selection.active.line;
Expand All @@ -319,7 +319,7 @@ export class ReplaceKillRingToRectangle extends EmacsCommand {
// Both `currentRect` and (`lineStart`, `lineEnd`) are calculated
// based on the same information from the `selection` and the `textEditor`'s range,
// so the `noUncheckedIndexedAccess` rule can be skipped here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

const rgn = currentRect[i - lineStart]!;
if (rgn.end.character < insertChar) {
const fill = insertChar - rgn.end.character;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/registers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class InsertRegister extends EmacsCommand {
if (!selection.isEmpty) {
editBuilder.delete(selection);
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

editBuilder.insert(selection.start, textToInsert);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export class EmacsEmulator implements IEmacsController, vscode.Disposable {
const affectedSelections = this.textEditor.selections.slice(0, affectedLen).map((selection, i) => {
// `i < affectedLen <= prevMarks.length`,
// so the `noUncheckedIndexedAccess` rule can be skipped here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

const prevMark = prevMarks[i]!;
return new vscode.Selection(selection.active, prevMark);
});
Expand Down
2 changes: 1 addition & 1 deletion src/kill-yank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class KillYanker implements vscode.Disposable {
// `canPasteSeparately = regionTexts.length === selections.length` has already been checked
// or `this.selections.length === 1` is confirmed, so regionTextsList[i] is not null
// and the `noUncheckedIndexedAccess` rule can be skipped here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

const regionTexts = regionTextsList[i]!;

let pasteCursor = selection.start;
Expand Down
4 changes: 2 additions & 2 deletions src/kill-yank/kill-ring-entity/editor-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AppendedRegionTexts {
}

public getLastRange(): Range {
return this.regionTexts[this.regionTexts.length - 1]!.range; // eslint-disable-line @typescript-eslint/no-non-null-assertion
return this.regionTexts[this.regionTexts.length - 1]!.range;
}

public hasRectModeText(): boolean {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class EditorTextKillRingEntity implements IKillRingEntity {
this.regionTextsList.map(
// `additional.length === this.regionTextsList.length` has already been checked,
// so noUncheckedIndexedAccess rule can be skipped here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

(appendedRegionTexts, i) => appendedRegionTexts.append(additional[i]!, appendDirection),
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/platform/node/loggerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ class NodeLogger implements ILogger {
public configChanged(configuration: IConfiguration) {
// `this.logger.transports` has 2 items as set at the constructor,
// so the `noUncheckedIndexedAccess` rule can be skipped here.
/* eslint-disable @typescript-eslint/no-non-null-assertion */

this.logger.transports[0]!.level = configuration.debug.loggingLevelForConsole;
this.logger.transports[0]!.silent = configuration.debug.silent;
this.logger.transports[1]!.level = configuration.debug.loggingLevelForAlert;
(this.logger.transports[1] as VsCodeMessage).configuration = configuration;
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function assertCursorsEqual(textEditor: TextEditor, ...positions: Array<[
textEditor.selections.forEach((selection, idx) => {
// `textEditor.selections.length === positions.length` has already been checked,
// so noUncheckedIndexedAccess rule can be skipped here.
const pos = positions[idx]!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
const pos = positions[idx]!;
const expectedRange = new Range(new Position(pos[0], pos[1]), new Position(pos[0], pos[1]));
assert.ok(
selection.isEqual(expectedRange),
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function equalPositions(positions1: Position[], positions2: Position[]):
if (positions1.length !== positions2.length) {
return false;
}
return positions1.every((p1, i) => p1.isEqual(positions2[i]!)); // eslint-disable-line @typescript-eslint/no-non-null-assertion
return positions1.every((p1, i) => p1.isEqual(positions2[i]!));
}

export function delay(time?: number): Promise<void> {
Expand Down
Loading

0 comments on commit 592fc96

Please sign in to comment.