From 81dc476a0c6a20e3e0c4bef2838f08667a0953c5 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 29 Mar 2026 15:28:22 +0200 Subject: [PATCH] Added additional lint plugins --- .oxlintrc.json | 157 ------------- .vscode/settings.json | 1 + oxlint.config.mts | 222 ++++++++++++++++++ package.json | 8 +- .../lib-common/src/testUtil/asyncSafety.ts | 2 + 5 files changed, 229 insertions(+), 161 deletions(-) delete mode 100644 .oxlintrc.json create mode 100644 oxlint.config.mts diff --git a/.oxlintrc.json b/.oxlintrc.json deleted file mode 100644 index 9388ec771d..0000000000 --- a/.oxlintrc.json +++ /dev/null @@ -1,157 +0,0 @@ -{ - "$schema": "./node_modules/oxlint/configuration_schema.json", - "plugins": [ - "eslint", - "typescript", - "unicorn", - "oxc", - "import", - "react", - "react-perf" - ], - "jsPlugins": [ - { - "name": "mocha", - "specifier": "eslint-plugin-mocha" - } - ], - - "ignorePatterns": [ - "resources/playground/**", - "packages/app-neovim/cursorless.nvim/**", - "packages/app-vscode/src/keyboard/grammar/generated/**", - "packages/lib-engine/src/customCommandGrammar/generated/**", - "packages/lib-engine/src/snippets/vendor/**" - ], - - "options": { - "typeAware": true, - "typeCheck": false - }, - - "rules": { - "curly": "warn", - "eqeqeq": [ - "warn", - "always", - { - "null": "never" - } - ], - "eslint/no-constant-condition": [ - "warn", - { - "checkLoops": false - } - ], - "eslint/no-restricted-imports": [ - "warn", - { - "paths": [ - { - "name": "node:assert", - "message": "Use node:assert/strict instead" - } - ], - "patterns": [ - { - "group": ["../*/src", "../*/src/*", "../../*/src", "../../*/src/*"], - "message": "Relative package imports are not allowed" - } - ] - } - ], - "eslint/no-throw-literal": "warn", - "eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_", - "ignoreRestSiblings": true - } - ], - "import/no-duplicates": "warn", - "mocha/no-exclusive-tests": "warn", - "mocha/no-pending-tests": "warn", - "no-warning-comments": [ - "warn", - { - "terms": ["todo"] - } - ], - "typescript/consistent-type-assertions": [ - "warn", - { - "assertionStyle": "as" - } - ], - "typescript/consistent-type-imports": "warn", - "typescript/no-base-to-string": "off", - "typescript/restrict-template-expressions": "off", - "typescript/unbound-method": "off", - "unicorn/prefer-module": "warn", - "unicorn/prefer-node-protocol": "warn", - "unicorn/throw-new-error": "warn" - }, - "overrides": [ - { - "files": ["packages/app-vscode/src/scripts/**/*.ts"], - "rules": { - "no-restricted-imports": [ - "warn", - { - "paths": [ - { - "name": "vscode", - "message": "Scripts shouldn't depend on vscode" - } - ] - } - ] - } - }, - - { - "files": ["packages/lib-common/**/*.ts", "packages/lib-engine/**/*.ts"], - "rules": { - "import/no-nodejs-modules": "warn" - } - }, - - { - "files": [ - "packages/lib-common/**/*.test.ts", - "packages/lib-engine/**/*.test.ts", - "packages/lib-engine/src/scripts/**/*.ts", - "packages/lib-engine/src/testUtil/**/*.ts" - ], - "rules": { - "import/no-nodejs-modules": "off" - } - }, - - { - "files": ["packages/lib-common/src/types/command/**/*.ts"], - "rules": { - "eslint/no-restricted-imports": [ - "warn", - { - "patterns": [ - { - "group": ["@cursorless/*", "../*"], - "message": "API types shouldn't have any dependencies" - } - ], - "paths": [ - { - "name": "@*", - "message": "API types shouldn't have any dependencies" - } - ] - } - ] - } - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json index 7fb8d6e2d2..69614647fa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "files.eol": "\n", "js/ts.tsdk.promptToUseWorkspaceVersion": true, "js/ts.tsdk": "node_modules/typescript/lib", + "oxc.configPath": "./oxlint.config.mts", "python.analysis.diagnosticMode": "workspace", // Turn off tsc task auto detection since we have the necessary tasks as npm scripts "js/ts.tsc.autoDetect": "off" diff --git a/oxlint.config.mts b/oxlint.config.mts new file mode 100644 index 0000000000..409ca2f010 --- /dev/null +++ b/oxlint.config.mts @@ -0,0 +1,222 @@ +import { defineConfig } from "oxlint"; + +const disabledRules = [ + "eslint/arrow-body-style", + "eslint/capitalized-comments", + "eslint/class-methods-use-this", + "eslint/complexity", + "eslint/id-length", + "eslint/init-declarations", + "eslint/max-classes-per-file", + "eslint/max-lines-per-function", + "eslint/max-lines", + "eslint/max-params", + "eslint/max-statements", + "eslint/no-console", + "eslint/no-continue", + "eslint/no-eq-null", + "eslint/no-magic-numbers", + "eslint/no-negated-condition", + "eslint/no-plusplus", + "eslint/no-ternary", + "eslint/no-undefined", + "eslint/no-use-before-define", + "eslint/no-void", + "eslint/prefer-destructuring", + "eslint/sort-imports", + "eslint/sort-keys", + "eslint/sort-vars", + "func-style", + "import/exports-last", + "import/group-exports", + "import/max-dependencies", + "import/no-named-export", + "import/no-namespace", + "import/no-nodejs-modules", + "import/no-relative-parent-imports", + "import/prefer-default-export", + "oxc/no-async-await", + "oxc/no-optional-chaining", + "oxc/no-rest-spread-properties", + "promise/avoid-new", + "promise/prefer-await-to-callbacks", + "react-perf/jsx-no-new-function-as-prop", + "react/jsx-max-depth", + "react/no-multi-comp", + "react/only-export-components", + "react/react-in-jsx-scope", + "typescript/explicit-function-return-type", + "typescript/parameter-properties", + "typescript/prefer-readonly-parameter-types", + "typescript/promise-function-async", + "typescript/strict-void-return", + "unicorn/filename-case", + "unicorn/no-array-callback-reference", + "unicorn/no-array-for-each", + "unicorn/no-null", + "unicorn/prefer-at", + "unicorn/prefer-module", + "unicorn/prefer-spread", + "unicorn/prefer-ternary", + "unicorn/switch-case-braces", +]; + +// oxlint-disable-next-line import/no-default-export +export default defineConfig({ + ignorePatterns: [ + "resources/playground/**", + "packages/app-neovim/cursorless.nvim/**", + "packages/app-vscode/src/keyboard/grammar/generated/**", + "packages/lib-engine/src/customCommandGrammar/generated/**", + "packages/lib-engine/src/snippets/vendor/**", + ], + options: { + typeAware: true, + typeCheck: false, + }, + plugins: [ + "eslint", + "typescript", + "unicorn", + "oxc", + "import", + "node", + "promise", + "react", + "react-perf", + ], + jsPlugins: [ + { + name: "mocha", + specifier: "eslint-plugin-mocha", + }, + ], + + rules: { + ...Object.fromEntries(disabledRules.map((r) => [r, "off"])), + curly: "warn", + eqeqeq: [ + "warn", + "always", + { + null: "never", + }, + ], + "eslint/no-constant-condition": [ + "warn", + { + checkLoops: false, + }, + ], + "eslint/no-restricted-imports": [ + "warn", + { + paths: [ + { + name: "node:assert", + message: "Use node:assert/strict instead", + }, + ], + patterns: [ + { + group: ["../*/src", "../*/src/*", "../../*/src", "../../*/src/*"], + message: "Relative package imports are not allowed", + }, + ], + }, + ], + "eslint/no-throw-literal": "warn", + "eslint/no-unused-vars": [ + "warn", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + caughtErrorsIgnorePattern: "^_", + ignoreRestSiblings: true, + }, + ], + "import/no-duplicates": "warn", + "mocha/no-exclusive-tests": "warn", + "mocha/no-pending-tests": "warn", + "no-warning-comments": [ + "warn", + { + terms: ["todo"], + }, + ], + "typescript/consistent-type-assertions": [ + "warn", + { + assertionStyle: "as", + }, + ], + "typescript/consistent-type-imports": "warn", + "typescript/no-base-to-string": "off", + "typescript/restrict-template-expressions": "off", + "typescript/unbound-method": "off", + "unicorn/prefer-module": "warn", + "unicorn/prefer-node-protocol": "warn", + "unicorn/throw-new-error": "warn", + }, + + overrides: [ + { + files: ["packages/app-vscode/src/scripts/**/*.ts"], + rules: { + "no-restricted-imports": [ + "warn", + { + paths: [ + { + name: "vscode", + message: "Scripts shouldn't depend on vscode", + }, + ], + }, + ], + }, + }, + + { + files: ["packages/lib-common/**/*.ts", "packages/lib-engine/**/*.ts"], + rules: { + "import/no-nodejs-modules": "warn", + }, + }, + + { + files: [ + "packages/lib-common/**/*.test.ts", + "packages/lib-engine/**/*.test.ts", + "packages/lib-engine/src/scripts/**/*.ts", + "packages/lib-engine/src/testUtil/**/*.ts", + ], + rules: { + "import/no-nodejs-modules": "off", + }, + }, + + { + files: ["packages/lib-common/src/types/command/**/*.ts"], + rules: { + "eslint/no-restricted-imports": [ + "warn", + { + patterns: [ + { + group: ["@cursorless/*", "../*"], + message: "API types shouldn't have any dependencies", + }, + ], + paths: [ + { + name: "@*", + message: "API types shouldn't have any dependencies", + }, + ], + }, + ], + }, + }, + ], +}); diff --git a/package.json b/package.json index 4e42a009a8..f18ebed0a9 100644 --- a/package.json +++ b/package.json @@ -14,14 +14,14 @@ "typecheck": "pnpm -r typecheck", "lint:meta": "pnpm meta-updater --test", "lint:syncpack": "syncpack lint", - "lint:ts": "oxlint --deny-warnings .", - "lint:style": "stylelint '**/*.{css,scss}' --ignore-path .gitignore", + "lint:ts": "oxlint -c oxlint.config.mts --deny-warnings .", + "lint:style": "stylelint --ignore-path .gitignore '**/*.{css,scss}'", "lint:fmt": "oxfmt --check .", "lint": "pnpm typecheck &&pnpm lint:meta && pnpm lint:syncpack && pnpm lint:ts && pnpm lint:style && pnpm lint:fmt", "fix:meta": "pnpm meta-updater && pnpm -r exec oxfmt tsconfig.json package.json", "fix:syncpack": "syncpack fix", - "fix:ts": "oxlint --fix .", - "fix:style": "stylelint '**/*.{css,scss}' --ignore-path .gitignore --fix", + "fix:ts": "oxlint -c oxlint.config.mts --fix .", + "fix:style": "stylelint --ignore-path .gitignore --fix '**/*.{css,scss}'", "fix:fmt": "oxfmt .", "init-vscode-sandbox": "pnpm -F @cursorless/app-vscode init-launch-sandbox", "meta-updater": "env NODE_OPTIONS=--import=tsx meta-updater", diff --git a/packages/lib-common/src/testUtil/asyncSafety.ts b/packages/lib-common/src/testUtil/asyncSafety.ts index b1b7a0880c..5cbfc553b9 100644 --- a/packages/lib-common/src/testUtil/asyncSafety.ts +++ b/packages/lib-common/src/testUtil/asyncSafety.ts @@ -1,5 +1,7 @@ import type { Context, Done } from "mocha"; +// oxlint-disable promise/no-callback-in-promise + /** * if an async returns after the method times out, * it will cause a "done() called multiple times" error.