From 1271c22aee0bcd2e6ae05f2baa263dba4b621382 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 17 Feb 2023 12:17:42 +0000 Subject: [PATCH] Separate linting and compiling src+test, scripts and hak Inspired by the failure of https://github.com/vector-im/element-desktop/pull/529 to lint our code with the @typescript-eslint/no-base-to-string rule turned on, I found we needed to add a parserOptions.project to our .eslintrc.js, pointing to the tsconfig.json. This led to more fixes, because we have 3 tsconfig.json files for src+test, scripts and hak and the single eslintrc was complaining that it could see more files than the tsconfig file knew about. So, I think the right split is to have one eslintrc file and one tsconfig for each of the three projects. --- .eslintrc-hak.js | 37 +++++++++++++++++++++++++++++++++++++ .eslintrc-scripts.js | 37 +++++++++++++++++++++++++++++++++++++ .eslintrc.js | 3 ++- package.json | 15 ++++++++++++--- tsconfig.json | 2 +- 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 .eslintrc-hak.js create mode 100644 .eslintrc-scripts.js diff --git a/.eslintrc-hak.js b/.eslintrc-hak.js new file mode 100644 index 0000000..7762909 --- /dev/null +++ b/.eslintrc-hak.js @@ -0,0 +1,37 @@ +module.exports = { + plugins: ["matrix-org"], + extends: ["plugin:matrix-org/javascript"], + parserOptions: { + ecmaVersion: 2021, + project: ["hak/tsconfig.json"], + }, + env: { + es6: true, + node: true, + // we also have some browser code (ie. the preload script) + browser: true, + }, + // NOTE: These rules are frozen and new rules should not be added here. + // New changes belong in https://github.com/matrix-org/eslint-plugin-matrix-org/ + rules: { + "quotes": "off", + "indent": "off", + "prefer-promise-reject-errors": "off", + "no-async-promise-executor": "off", + }, + overrides: [ + { + files: ["hak/**/*.ts"], + extends: ["plugin:matrix-org/typescript"], + rules: { + // Things we do that break the ideal style + "prefer-promise-reject-errors": "off", + "quotes": "off", + + "@typescript-eslint/no-explicit-any": "off", + // We're okay with assertion errors when we ask for them + "@typescript-eslint/no-non-null-assertion": "off", + }, + }, + ], +}; diff --git a/.eslintrc-scripts.js b/.eslintrc-scripts.js new file mode 100644 index 0000000..451822a --- /dev/null +++ b/.eslintrc-scripts.js @@ -0,0 +1,37 @@ +module.exports = { + plugins: ["matrix-org"], + extends: ["plugin:matrix-org/javascript"], + parserOptions: { + ecmaVersion: 2021, + project: ["scripts/tsconfig.json"], + }, + env: { + es6: true, + node: true, + // we also have some browser code (ie. the preload script) + browser: true, + }, + // NOTE: These rules are frozen and new rules should not be added here. + // New changes belong in https://github.com/matrix-org/eslint-plugin-matrix-org/ + rules: { + "quotes": "off", + "indent": "off", + "prefer-promise-reject-errors": "off", + "no-async-promise-executor": "off", + }, + overrides: [ + { + files: ["scripts/**/*.ts"], + extends: ["plugin:matrix-org/typescript"], + rules: { + // Things we do that break the ideal style + "prefer-promise-reject-errors": "off", + "quotes": "off", + + "@typescript-eslint/no-explicit-any": "off", + // We're okay with assertion errors when we ask for them + "@typescript-eslint/no-non-null-assertion": "off", + }, + }, + ], +}; diff --git a/.eslintrc.js b/.eslintrc.js index a65da72..930875f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,7 @@ module.exports = { extends: ["plugin:matrix-org/javascript"], parserOptions: { ecmaVersion: 2021, + project: ["tsconfig.json"], }, env: { es6: true, @@ -20,7 +21,7 @@ module.exports = { }, overrides: [ { - files: ["{src,scripts,hak}/**/*.{ts,tsx}"], + files: ["src/**/*.ts", "test/**/*.ts"], extends: ["plugin:matrix-org/typescript"], rules: { // Things we do that break the ideal style diff --git a/package.json b/package.json index 7660dbc..1f7ba1b 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,18 @@ "asar-webapp": "asar p webapp webapp.asar", "start": "yarn run build:ts && yarn run build:res && electron .", "lint": "yarn lint:types && yarn lint:js", - "lint:js": "eslint --max-warnings 0 src scripts hak", - "lint:js-fix": "eslint --fix src scripts hak", - "lint:types": "tsc --noEmit && tsc -p scripts/tsconfig.json --noEmit && tsc -p hak/tsconfig.json --noEmit", + "lint:js": "yarn lint:js:src && yarn lint:js:scripts && yarn lint:js:hak", + "lint:js:src": "eslint --max-warnings 0 src test", + "lint:js:scripts": "eslint --max-warnings 0 --config .eslintrc-scripts.js scripts", + "lint:js:hak": "eslint --max-warnings 0 --config .eslintrc-hak.js hak", + "lint:js-fix": "yarn lint:js-fix:src && yarn lint:js-fix:scripts && yarn lint:js-fix:hak", + "lint:js-fix:src": "eslint --fix --max-warnings 0 src test", + "lint:js-fix:scripts": "eslint --fix --max-warnings 0 --config .eslintrc-scripts.js scripts", + "lint:js-fix:hak": "eslint --fix --max-warnings 0 --config .eslintrc-hak.js hak", + "lint:types": "yarn lint:types:src && yarn lint:types:scripts && yarn lint:types:hak", + "lint:types:src": "tsc --noEmit", + "lint:types:scripts": "tsc --noEmit -p scripts/tsconfig.json", + "lint:types:hak": "tsc --noEmit -p hak/tsconfig.json", "build:native": "yarn run hak", "build:native:universal": "yarn run hak --target x86_64-apple-darwin fetchandbuild && yarn run hak --target aarch64-apple-darwin fetchandbuild && yarn run hak --target x86_64-apple-darwin --target aarch64-apple-darwin copyandlink", "build:32": "yarn run build:ts && yarn run build:res && electron-builder --ia32", diff --git a/tsconfig.json b/tsconfig.json index b7624d2..3f7c6f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ "types": ["jest", "node"], "strict": true }, - "include": ["./src/**/*.ts", "./tests/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts"] }