Skip to content

Commit 6bc8080

Browse files
authored
Merge pull request #28387 from element-hq/t3chguy/knip2
2 parents db30bc5 + 1c64080 commit 6bc8080

File tree

67 files changed

+353
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+353
-538
lines changed

.eslintrc-module_system.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

.eslintrc.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,60 @@ module.exports = {
270270
"react-hooks/rules-of-hooks": ["off"],
271271
},
272272
},
273+
{
274+
files: ["module_system/**/*.{ts,tsx}"],
275+
parserOptions: {
276+
project: ["./tsconfig.module_system.json"],
277+
},
278+
extends: ["plugin:matrix-org/typescript", "plugin:matrix-org/react"],
279+
// NOTE: These rules are frozen and new rules should not be added here.
280+
// New changes belong in https://github.com/matrix-org/eslint-plugin-matrix-org/
281+
rules: {
282+
// Things we do that break the ideal style
283+
"prefer-promise-reject-errors": "off",
284+
"quotes": "off",
285+
286+
// We disable this while we're transitioning
287+
"@typescript-eslint/no-explicit-any": "off",
288+
// We're okay with assertion errors when we ask for them
289+
"@typescript-eslint/no-non-null-assertion": "off",
290+
291+
// Ban matrix-js-sdk/src imports in favour of matrix-js-sdk/src/matrix imports to prevent unleashing hell.
292+
"no-restricted-imports": [
293+
"error",
294+
{
295+
paths: [
296+
{
297+
name: "matrix-js-sdk",
298+
message: "Please use matrix-js-sdk/src/matrix instead",
299+
},
300+
{
301+
name: "matrix-js-sdk/",
302+
message: "Please use matrix-js-sdk/src/matrix instead",
303+
},
304+
{
305+
name: "matrix-js-sdk/src",
306+
message: "Please use matrix-js-sdk/src/matrix instead",
307+
},
308+
{
309+
name: "matrix-js-sdk/src/",
310+
message: "Please use matrix-js-sdk/src/matrix instead",
311+
},
312+
{
313+
name: "matrix-js-sdk/src/index",
314+
message: "Please use matrix-js-sdk/src/matrix instead",
315+
},
316+
],
317+
patterns: [
318+
{
319+
group: ["matrix-js-sdk/lib", "matrix-js-sdk/lib/", "matrix-js-sdk/lib/**"],
320+
message: "Please use matrix-js-sdk/src/* instead",
321+
},
322+
],
323+
},
324+
],
325+
},
326+
},
273327
],
274328
settings: {
275329
react: {

.github/workflows/static_analysis.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ jobs:
123123
cache: "yarn"
124124
node-version: "lts/*"
125125

126+
- name: Install Deps
127+
run: "yarn install --frozen-lockfile"
128+
129+
- name: Run linter
130+
run: "yarn run lint:knip"
131+
126132
- name: Install Deps
127133
run: "scripts/layered.sh"
128134

.lintstagedrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"*": "prettier --write",
33
"src/**/*.(ts|tsx)": ["eslint --fix"],
44
"scripts/**/*.(ts|tsx)": ["eslint --fix"],
5-
"module_system/**/*.(ts|tsx)": ["eslint --fix --config .eslintrc-module_system.js module_system"],
5+
"module_system/**/*.(ts|tsx)": ["eslint --fix"],
66
"*.pcss": ["stylelint --fix"]
77
}

.stylelintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
extends: ["stylelint-config-standard"],
3-
customSyntax: require("postcss-scss"),
3+
customSyntax: "postcss-scss",
44
plugins: ["stylelint-scss"],
55
rules: {
66
"comment-empty-line-before": null,

knip.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { KnipConfig } from "knip";
2+
3+
export default {
4+
entry: [
5+
"src/vector/index.ts",
6+
"src/serviceworker/index.ts",
7+
"src/workers/*.worker.ts",
8+
"src/utils/exportUtils/exportJS.js",
9+
"scripts/**",
10+
"playwright/**",
11+
"test/**",
12+
"res/decoder-ring/**",
13+
],
14+
project: ["**/*.{js,ts,jsx,tsx}"],
15+
ignore: [
16+
"docs/**",
17+
"res/jitsi_external_api.min.js",
18+
// Used by jest
19+
"__mocks__/maplibre-gl.js",
20+
// Keep for now
21+
"src/hooks/useLocalStorageState.ts",
22+
"src/components/views/elements/InfoTooltip.tsx",
23+
"src/components/views/elements/StyledCheckbox.tsx",
24+
],
25+
ignoreDependencies: [
26+
// Required for `action-validator`
27+
"@action-validator/*",
28+
// Used for git pre-commit hooks
29+
"husky",
30+
// Used by jest
31+
"babel-jest",
32+
// Used by babel
33+
"@babel/runtime",
34+
"@babel/plugin-transform-class-properties",
35+
// Referenced in PCSS
36+
"github-markdown-css",
37+
// False positive
38+
"sw.js",
39+
// Used by webpack
40+
"buffer",
41+
"process",
42+
"util",
43+
// Used by workflows
44+
"ts-prune",
45+
// Required due to bug in bloom-filters https://github.com/Callidon/bloom-filters/issues/75
46+
"@types/seedrandom",
47+
],
48+
ignoreBinaries: [
49+
// Used in scripts & workflows
50+
"jq",
51+
],
52+
ignoreExportsUsedInFile: true,
53+
} satisfies KnipConfig;

package.json

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"i18n:lint": "matrix-i18n-lint && prettier --log-level=silent --write src/i18n/strings/ --ignore-path /dev/null",
3636
"i18n:diff": "cp src/i18n/strings/en_EN.json src/i18n/strings/en_EN_orig.json && yarn i18n && matrix-compare-i18n-files src/i18n/strings/en_EN_orig.json src/i18n/strings/en_EN.json",
3737
"make-component": "node scripts/make-react-component.js",
38-
"rethemendex": "res/css/rethemendex.sh",
38+
"rethemendex": "./res/css/rethemendex.sh",
3939
"clean": "rimraf lib webapp",
4040
"build": "yarn clean && yarn build:genfiles && yarn build:bundle",
4141
"build-stats": "yarn clean && yarn build:genfiles && yarn build:bundle-stats",
@@ -45,23 +45,20 @@
4545
"build:bundle": "webpack --progress --mode production",
4646
"build:bundle-stats": "webpack --progress --mode production --json > webpack-stats.json",
4747
"build:module_system": "ts-node --project ./tsconfig.module_system.json module_system/scripts/install.ts",
48-
"dist": "scripts/package.sh",
48+
"dist": "./scripts/package.sh",
4949
"start": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n modules,res \"yarn build:module_system\" \"yarn build:res\" && concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js\"",
5050
"start:https": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js --server-type https\"",
5151
"start:res": "ts-node scripts/copy-res.ts -w",
5252
"start:js": "webpack serve --output-path webapp --output-filename=bundles/_dev_/[name].js --output-chunk-filename=bundles/_dev_/[name].js --mode development",
5353
"lint": "yarn lint:types && yarn lint:js && yarn lint:style && yarn lint:workflows",
54-
"lint:js": "yarn lint:js:src && yarn lint:js:module_system",
55-
"lint:js:src": "eslint --max-warnings 0 src test playwright && prettier --check .",
56-
"lint:js:module_system": "eslint --max-warnings 0 --config .eslintrc-module_system.js module_system",
57-
"lint:js-fix": "yarn lint:js-fix:src && yarn lint:js-fix:module_system",
58-
"lint:js-fix:src": "prettier --log-level=warn --write . && eslint --fix src test playwright",
59-
"lint:js-fix:module_system": "eslint --fix --config .eslintrc-module_system.js module_system",
54+
"lint:js": "eslint --max-warnings 0 src test playwright module_system && prettier --check .",
55+
"lint:js-fix": "prettier --log-level=warn --write . && eslint --fix src test playwright module_system",
6056
"lint:types": "yarn lint:types:src && yarn lint:types:module_system",
6157
"lint:types:src": "tsc --noEmit --jsx react && tsc --noEmit --jsx react -p playwright",
6258
"lint:types:module_system": "tsc --noEmit --project ./tsconfig.module_system.json",
6359
"lint:style": "stylelint \"res/css/**/*.pcss\"",
6460
"lint:workflows": "find .github/workflows -type f \\( -iname '*.yaml' -o -iname '*.yml' \\) | xargs -I {} sh -c 'echo \"Linting {}\"; action-validator \"{}\"'",
61+
"lint:knip": "knip",
6562
"test": "jest",
6663
"test:playwright": "playwright test",
6764
"test:playwright:open": "yarn test:playwright --ui",
@@ -74,7 +71,6 @@
7471
"update:jitsi": "curl -s https://meet.element.io/libs/external_api.min.js > ./res/jitsi_external_api.min.js"
7572
},
7673
"resolutions": {
77-
"@types/seedrandom": "3.0.8",
7874
"oidc-client-ts": "3.1.0",
7975
"jwt-decode": "4.0.0",
8076
"caniuse-lite": "1.0.30001668",
@@ -96,7 +92,7 @@
9692
"@zxcvbn-ts/language-common": "^3.0.4",
9793
"@zxcvbn-ts/language-en": "^3.0.2",
9894
"await-lock": "^2.1.0",
99-
"bloom-filters": "^3.0.1",
95+
"bloom-filters": "^3.0.2",
10096
"blurhash": "^2.0.3",
10197
"browserslist": "^4.23.2",
10298
"classnames": "^2.2.6",
@@ -155,11 +151,9 @@
155151
"@action-validator/cli": "^0.6.0",
156152
"@action-validator/core": "^0.6.0",
157153
"@axe-core/playwright": "^4.8.1",
158-
"@babel/cli": "^7.12.10",
159154
"@babel/core": "^7.12.10",
160155
"@babel/eslint-parser": "^7.12.10",
161156
"@babel/eslint-plugin": "^7.12.10",
162-
"@babel/parser": "^7.12.11",
163157
"@babel/plugin-proposal-export-default-from": "^7.12.1",
164158
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
165159
"@babel/plugin-transform-class-properties": "^7.12.1",
@@ -172,7 +166,6 @@
172166
"@babel/preset-env": "^7.12.11",
173167
"@babel/preset-react": "^7.12.10",
174168
"@babel/preset-typescript": "^7.12.7",
175-
"@babel/register": "^7.12.10",
176169
"@babel/runtime": "^7.12.5",
177170
"@casualbot/jest-sonar-reporter": "2.2.7",
178171
"@peculiar/webcrypto": "^1.4.3",
@@ -186,7 +179,6 @@
186179
"@testing-library/react": "^16.0.0",
187180
"@testing-library/user-event": "^14.5.2",
188181
"@types/commonmark": "^0.27.4",
189-
"@types/content-type": "^1.1.5",
190182
"@types/counterpart": "^0.18.1",
191183
"@types/css-tree": "^2.3.8",
192184
"@types/diff-match-patch": "^1.0.32",
@@ -211,15 +203,13 @@
211203
"@types/react-dom": "18.3.1",
212204
"@types/react-transition-group": "^4.4.0",
213205
"@types/sanitize-html": "2.13.0",
214-
"@types/sdp-transform": "^2.4.6",
215206
"@types/seedrandom": "3.0.8",
216207
"@types/semver": "^7.5.8",
217208
"@types/tar-js": "^0.3.5",
218209
"@types/ua-parser-js": "^0.7.36",
219210
"@types/uuid": "^10.0.0",
220211
"@typescript-eslint/eslint-plugin": "^8.0.0",
221212
"@typescript-eslint/parser": "^8.0.0",
222-
"axe-core": "4.10.2",
223213
"babel-jest": "^29.0.0",
224214
"babel-loader": "^9.0.0",
225215
"babel-plugin-jsx-remove-data-test-id": "^3.0.0",
@@ -259,14 +249,12 @@
259249
"jest-mock": "^29.6.2",
260250
"jest-raw-loader": "^1.0.1",
261251
"jsqr": "^1.4.0",
252+
"knip": "^5.36.2",
262253
"lint-staged": "^15.0.2",
263254
"mailhog": "^4.16.0",
264-
"matrix-mock-request": "^2.5.0",
265255
"matrix-web-i18n": "^3.2.1",
266256
"mini-css-extract-plugin": "2.9.0",
267257
"minimist": "^1.2.6",
268-
"mkdirp": "^3.0.0",
269-
"mocha-junit-reporter": "^2.2.0",
270258
"modernizr": "^3.12.0",
271259
"node-fetch": "^2.6.7",
272260
"playwright-core": "^1.45.1",

src/@types/common.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor
1414

1515
export type { Leaves } from "matrix-web-i18n";
1616

17-
export type RecursivePartial<T> = {
18-
[P in keyof T]?: T[P] extends (infer U)[]
19-
? RecursivePartial<U>[]
20-
: T[P] extends object
21-
? RecursivePartial<T[P]>
22-
: T[P];
23-
};
24-
2517
export type KeysStartingWith<Input extends object, Str extends string> = {
2618
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2719
[P in keyof Input]: P extends `${Str}${infer _X}` ? P : never; // we don't use _X

src/BlurhashEncoder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
// @ts-ignore - `.ts` is needed here to make TS happy
109
import { Request, Response } from "./workers/blurhash.worker.ts";
1110
import { WorkerManager } from "./WorkerManager";
1211
import blurhashWorkerFactory from "./workers/blurhashWorkerFactory";

src/Modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IDeferred, defer } from "matrix-js-sdk/src/utils";
1414
import { TypedEventEmitter } from "matrix-js-sdk/src/matrix";
1515
import { Glass, TooltipProvider } from "@vector-im/compound-web";
1616

17-
import dis, { defaultDispatcher } from "./dispatcher/dispatcher";
17+
import defaultDispatcher from "./dispatcher/dispatcher";
1818
import AsyncWrapper from "./AsyncWrapper";
1919
import { Defaultize } from "./@types/common";
2020
import { ActionPayload } from "./dispatcher/payloads";
@@ -396,7 +396,7 @@ export class ModalManager extends TypedEventEmitter<ModalManagerEvent, HandlerMa
396396
if (this.modals.length === 0 && !this.priorityModal && !this.staticModal) {
397397
// If there is no modal to render, make all of Element available
398398
// to screen reader users again
399-
dis.dispatch({
399+
defaultDispatcher.dispatch({
400400
action: "aria_unhide_main_app",
401401
});
402402
ModalManager.getOrCreateRoot().render(<></>);
@@ -407,7 +407,7 @@ export class ModalManager extends TypedEventEmitter<ModalManagerEvent, HandlerMa
407407
// Hide the content outside the modal to screen reader users
408408
// so they won't be able to navigate into it and act on it using
409409
// screen reader specific features
410-
dis.dispatch({
410+
defaultDispatcher.dispatch({
411411
action: "aria_hide_main_app",
412412
});
413413

src/PlaybackEncoder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
// @ts-ignore - `.ts` is needed here to make TS happy
109
import { Request, Response } from "./workers/playback.worker";
1110
import { WorkerManager } from "./WorkerManager";
1211
import playbackWorkerFactory from "./workers/playbackWorkerFactory";

src/components/structures/BackdropPanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ export const BackdropPanel: React.FC<IProps> = ({ backgroundImage, blurMultiplie
3131
</div>
3232
);
3333
};
34-
export default BackdropPanel;

0 commit comments

Comments
 (0)