From bd8c69ec74cef9fc10e35758111900f4899cafe1 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Fri, 17 Feb 2023 12:14:53 +0000 Subject: [PATCH 1/7] Include the test directory in tsconfig. --- tsconfig.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 964552d..b7624d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,9 +7,7 @@ "target": "es2016", "sourceMap": false, "outDir": "./lib", - "rootDir": "./src", "declaration": true, - "typeRoots": ["src/@types"], "lib": ["es2019", "dom"], "types": ["jest", "node"], "strict": true From 1271c22aee0bcd2e6ae05f2baa263dba4b621382 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Fri, 17 Feb 2023 12:17:42 +0000 Subject: [PATCH 2/7] 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"] } From a0034c1ade0e3eac415eb6a255b938099f85fa46 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Mon, 20 Feb 2023 16:08:11 +0000 Subject: [PATCH 3/7] Add a rootDir to try and appease the CI --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 3f7c6f8..f8ef235 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "target": "es2016", "sourceMap": false, "outDir": "./lib", + "rootDir": ".", "declaration": true, "lib": ["es2019", "dom"], "types": ["jest", "node"], From 26a308d8c692de2c8d5b4214f8b8fc66b312f61c Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Mon, 20 Feb 2023 16:25:17 +0000 Subject: [PATCH 4/7] Add typeRoots to try and appease CI --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index f8ef235..3d5d02a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "outDir": "./lib", "rootDir": ".", "declaration": true, + "typeRoots": ["src/@types", "node_modules/@types"], "lib": ["es2019", "dom"], "types": ["jest", "node"], "strict": true From f960700a2ac396fd3820daf512921813c4d253c0 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Thu, 23 Feb 2023 17:10:06 +0000 Subject: [PATCH 5/7] Exclude test from eslint checking since it always was excluded, and I can't get it to check --- .eslintrc.js | 2 +- package.json | 4 ++-- tsconfig.json | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 930875f..6e498f6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,7 +21,7 @@ module.exports = { }, overrides: [ { - files: ["src/**/*.ts", "test/**/*.ts"], + files: ["src/**/*.ts"], extends: ["plugin:matrix-org/typescript"], rules: { // Things we do that break the ideal style diff --git a/package.json b/package.json index 1f7ba1b..eb775eb 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,11 @@ "start": "yarn run build:ts && yarn run build:res && electron .", "lint": "yarn lint:types && yarn lint:js", "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:src": "eslint --max-warnings 0 src", "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:src": "eslint --fix --max-warnings 0 src", "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", diff --git a/tsconfig.json b/tsconfig.json index 3d5d02a..008a811 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,12 @@ "target": "es2016", "sourceMap": false, "outDir": "./lib", - "rootDir": ".", + "rootDir": "./src", "declaration": true, "typeRoots": ["src/@types", "node_modules/@types"], "lib": ["es2019", "dom"], - "types": ["jest", "node"], + "types": ["node"], "strict": true }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts"] } From 51a8667b890fbd412bc3a14f0cbd31641e28a9d5 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Thu, 23 Feb 2023 17:33:06 +0000 Subject: [PATCH 6/7] Share what we can with extends in eslintrc --- .eslintrc-hak.js | 17 +---------------- .eslintrc-scripts.js | 17 +---------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/.eslintrc-hak.js b/.eslintrc-hak.js index 7762909..28a4224 100644 --- a/.eslintrc-hak.js +++ b/.eslintrc-hak.js @@ -1,24 +1,9 @@ module.exports = { plugins: ["matrix-org"], - extends: ["plugin:matrix-org/javascript"], + extends: [".eslintrc.js"], 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"], diff --git a/.eslintrc-scripts.js b/.eslintrc-scripts.js index 451822a..ee75006 100644 --- a/.eslintrc-scripts.js +++ b/.eslintrc-scripts.js @@ -1,24 +1,9 @@ module.exports = { plugins: ["matrix-org"], - extends: ["plugin:matrix-org/javascript"], + extends: [".eslintrc.js"], 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"], From 3eeb8c14a9abc8d778325775189c4d8a6ead1589 Mon Sep 17 00:00:00 2001 From: Andy Balaam <andy.balaam@matrix.org> Date: Fri, 24 Feb 2023 09:39:14 +0000 Subject: [PATCH 7/7] Lint the test directory --- .eslintrc-test.js | 22 ++++++++++++++++++++++ package.json | 9 ++++++--- test/tsconfig.json | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 .eslintrc-test.js create mode 100644 test/tsconfig.json diff --git a/.eslintrc-test.js b/.eslintrc-test.js new file mode 100644 index 0000000..c072c64 --- /dev/null +++ b/.eslintrc-test.js @@ -0,0 +1,22 @@ +module.exports = { + plugins: ["matrix-org"], + extends: [".eslintrc.js"], + parserOptions: { + project: ["test/tsconfig.json"], + }, + overrides: [ + { + files: ["test/**/*.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/package.json b/package.json index eb775eb..f3888ff 100644 --- a/package.json +++ b/package.json @@ -20,16 +20,19 @@ "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": "yarn lint:js:src && yarn lint:js:scripts && yarn lint:js:hak", + "lint:js": "yarn lint:js:src && yarn lint:js:test && yarn lint:js:scripts && yarn lint:js:hak", "lint:js:src": "eslint --max-warnings 0 src", + "lint:js:test": "eslint --max-warnings 0 --config .eslintrc-test.js 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": "yarn lint:js-fix:src &&yarn lint:js-fix:test && yarn lint:js-fix:scripts && yarn lint:js-fix:hak", "lint:js-fix:src": "eslint --fix --max-warnings 0 src", + "lint:js-fix:test": "eslint --fix --max-warnings 0 --config .eslintrc-test.js 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": "yarn lint:types:src && yarn lint:types:test && yarn lint:types:scripts && yarn lint:types:hak", "lint:types:src": "tsc --noEmit", + "lint:types:test": "tsc --noEmit -p test/tsconfig.json", "lint:types:scripts": "tsc --noEmit -p scripts/tsconfig.json", "lint:types:hak": "tsc --noEmit -p hak/tsconfig.json", "build:native": "yarn run hak", diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000..f032c77 --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "resolveJsonModule": true, + "moduleResolution": "node", + "esModuleInterop": true, + "target": "es2017", + "module": "commonjs", + "sourceMap": false, + "strict": true, + "lib": ["es2019", "dom"] + }, + "include": ["./**/*.ts"], + "ts-node": { + "transpileOnly": true + } +}