From 4f1b8f0606070093adb2bb565ebd9f926822d00a Mon Sep 17 00:00:00 2001 From: Todd Schiller Date: Tue, 12 Nov 2024 11:54:18 -0500 Subject: [PATCH 1/2] Add eslintrc for libraries/utils --- libraries/utils/.eslintrc.js | 18 ++++++++++++++++++ libraries/utils/package.json | 1 + libraries/utils/src/debugUtils.ts | 2 +- libraries/utils/src/globals.d.ts | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 libraries/utils/.eslintrc.js create mode 100644 libraries/utils/src/globals.d.ts diff --git a/libraries/utils/.eslintrc.js b/libraries/utils/.eslintrc.js new file mode 100644 index 0000000000..614c32bb30 --- /dev/null +++ b/libraries/utils/.eslintrc.js @@ -0,0 +1,18 @@ +module.exports = { + root: true, + extends: [ + // Full config: https://github.com/pixiebrix/eslint-config-pixiebrix/blob/main/index.js + // XXX: use exact configuration for now because applications/browser-extension has a lot of local configuration. + // When we bring eslint-config-pixiebrix into the monorepo, we can iterate on code sharing across configs. + "pixiebrix", + ], +}; + +// `npm run lint:fast` will skip the (slow) import/* rules +// Useful if you're trying to iterate fixes over other rules +if (process.env.ESLINT_NO_IMPORTS) { + const importRules = Object.keys(require("eslint-plugin-import").rules); + for (const ruleName of importRules) { + module.exports.rules[`import/${ruleName}`] = "off"; + } +} diff --git a/libraries/utils/package.json b/libraries/utils/package.json index f831dd0c27..a1ca4319ce 100644 --- a/libraries/utils/package.json +++ b/libraries/utils/package.json @@ -19,6 +19,7 @@ "@swc/core": "^1.9.2", "@swc/jest": "^0.2.37", "eslint": "^8.57.0", + "eslint-config-pixiebrix": "^0.41.1", "jest": "^29.7.0", "typescript": "^5.6.3" } diff --git a/libraries/utils/src/debugUtils.ts b/libraries/utils/src/debugUtils.ts index 313185d726..4ce97421fd 100644 --- a/libraries/utils/src/debugUtils.ts +++ b/libraries/utils/src/debugUtils.ts @@ -28,7 +28,7 @@ type InvalidPathInformation = { * @param path period separated path */ export function getInvalidPath( - value: Record, + value: UnknownObject, path: string, ): InvalidPathInformation { const parts = path.split("."); diff --git a/libraries/utils/src/globals.d.ts b/libraries/utils/src/globals.d.ts new file mode 100644 index 0000000000..6cfe9604c3 --- /dev/null +++ b/libraries/utils/src/globals.d.ts @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 PixieBrix, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/* eslint-disable-next-line no-restricted-syntax -- + * Type to be preferred over a plain `object` + * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md */ +type UnknownObject = Record; From e02e7b3b13ea1f4d3200416a7ab8e579d4cea4eb Mon Sep 17 00:00:00 2001 From: Todd Schiller Date: Tue, 12 Nov 2024 11:54:37 -0500 Subject: [PATCH 2/2] Add eslintrc for libraries/utils --- .github/workflows/ci.yml | 4 ++-- package.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4479f49ae4..60348aaad7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,10 +160,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version-file: applications/browser-extension/package.json + node-version-file: package.json cache: npm - run: npm ci - - run: npm run lint:full --workspace=applications/browser-extension + - run: npm run lint:full dead-code: runs-on: ubuntu-latest diff --git a/package.json b/package.json index fe6c4e0e27..22170d65b1 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "scripts": { "test": "npm run test --workspaces", "lint": "npm run lint --workspaces", + "lint:full": "npm run lint:full --workspaces", "build": "npm run build --workspaces", "build:typecheck": "npm run build:typecheck --workspaces", "dead-code": "npm run dead-code:base -- --include files,duplicates,dependencies,classMembers,binaries,enumMembers,nsTypes,exports,nsExports",