Skip to content

Commit 2a929cf

Browse files
authored
chore: fix all lint errors and add mechanisms to prevent them from appearing again (#12401)
I think it's easier to review this PR commit by commit, so I'll explain it this way: ## Commits 1. [parallelize eslint script (still showing logs results in serial)](c9ac49c): Previously, `--concurrency 1` was added to the script to make the logs more readable. However, turborepo has an option specifically for these use cases: `--log-order=grouped` runs the tasks in parallel but outputs them serially. As a result, the lint script is now significantly faster. 2. [run pnpm lint:fix](9c128c2) The auto-fix was run, which resolved some eslint errors that were slipped in due to the use of `no-verify`. Most of these were `perfectionist` fixes (property ordering) and the removal of unnecessary assertions. Starting with this PR, this won't happen again in the future, as we'll be verifying the linter in every PR across the entire codebase (see commit 7). 3. [fix eslint non-autofixable errors](700f412) All manual errors have been resolved except for the configuration errors addressed in commit 5. Most were React compiler violations, which have been disabled and commented out "TODO" for now. There's also an unused `use no memo` and a couple of `require` errors. 4. [move react-compiler linter to eslint-config package](4f7cb4d) To simplify the eslint configuration. My concern was that there would be a performance regression when used in non-react related packages, but none was experienced. This is probably because it only runs on .tsx files. 5. [remove redundant eslint config files and fix allowDefaultProject](a943479) The main feature introduced by `typescript-eslint` v8 was `projectService`, which automatically searches each file for the closest `tsconfig`, greatly simplifying configuration in monorepos ([source](https://typescript-eslint.io/blog/announcing-typescript-eslint-v8#project-service)). Once I moved `projectService` to `packages/eslint-config`, all the other configuration files could be easily removed. I confirmed that pnpm lint still works on individual packages. The other important change was that the pending eslint errors from commits 2 and 3 were resolved. That is, some files were giving the error: "[File] was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject." Below I copy the explanatory comment I left in the code: ```ts // This is necessary because `tsconfig.base.json` defines `"rootDir": "${configDir}/src"`, // And the following files aren't in src because they aren't transpiled. // This is typescript-eslint's way of adding files that aren't included in tsconfig. // See: https://typescript-eslint.io/troubleshooting/typed-linting/#i-get-errors-telling-me--was-not-found-by-the-project-service-consider-either-including-it-in-the-tsconfigjson-or-including-it-in-allowdefaultproject // The best practice is to have a tsconfig.json that covers ALL files and is used for // typechecking (with noEmit), and a `tsconfig.build.json` that is used for the build // (or alternatively, swc, tsup or tsdown). That's what we should ideally do, in which case // this hardcoded list wouldn't be necessary. Note that these files don't currently go // through ts, only through eslint. ``` 6. [Differentiate errors from warnings in VScode ESLint Rules](5914d2f) There's no reason to do that. If an eslint rule isn't an error, it should be disabled or converted to a warning. 7. [Disable skip lint, and lint over the entire repo now that it's faster](e4b28f1) The GitHub action linted only the files that had changed in the PR. While this seems like a good idea, once exceptions were introduced with [skip lint], they opened the door to propagating more and more errors. Often, the linter was skipped, not because someone introduced new errors, but because they were trying to avoid those that had already crept in, sometimes accidentally introducing new ones. On the other hand, `pnpm lint` now runs in parallel (commit 1), so it's not that slow. Additionally, it runs in parallel with other GitHub actions like e2e tests, which take much longer, so it can't represent a bottleneck in CI. 8. [fix lint in next package](4506595) Small fix missing from commit 5 9. [Merge remote-tracking branch 'origin/main' into fix-eslint](563d490) 10. [add again eslint.config.js in payload package](78f6ffc) The comment in the code explains it. Basically, after the merge from main, the payload package runs out of memory when linting, probably because it grew in recent PRs. That package will sooner or later collapse for our tooling, so we may have to split it. It's already too big. ## Future Actions - Resolve React compiler violations, as mentioned in commit 3. - Decouple the `tsconfig` used for typechecking and build across the entire monorepo (as explained in point 5) to ensure ts coverage even for files that aren't transpiled (such as scripts). - Remove the few remaining `eslint.config.js`. I had to leave the `richtext-lexical` and `next` ones for now. They could be moved to the root config and scoped to their packages, as we do for example with `templates/vercel-postgres/**`. However, I couldn't get it to work, I don't know why. - Make eslint in the test folder usable. Not only are we not linting `test` in CI, but now the `pnpm eslint .` command is so large that my computer freezes. If each suite were its own package, this would be solved, and dynamic codegen + git hooks to modify tsconfig.base.json wouldn't be necessary ([related](#11984)).
1 parent 38029cd commit 2a929cf

File tree

129 files changed

+118
-1912
lines changed

Some content is hidden

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

129 files changed

+118
-1912
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ jobs:
6262
echo "templates: ${{ steps.filter.outputs.templates }}"
6363
6464
lint:
65-
# Follows same github's ci skip: [skip lint], [lint skip], [no lint]
66-
if: >
67-
github.event_name == 'pull_request' &&
68-
!contains(github.event.pull_request.title, '[skip lint]') &&
69-
!contains(github.event.pull_request.title, '[lint skip]') &&
70-
!contains(github.event.pull_request.title, '[no lint]')
7165
runs-on: ubuntu-24.04
7266
steps:
7367
- uses: actions/checkout@v4
@@ -81,10 +75,8 @@ jobs:
8175
pnpm-version: ${{ env.PNPM_VERSION }}
8276
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
8377

84-
- name: Lint staged
85-
run: |
86-
git diff --name-only --diff-filter=d origin/${GITHUB_BASE_REF}...${GITHUB_SHA}
87-
npx lint-staged --diff="origin/${GITHUB_BASE_REF}...${GITHUB_SHA}"
78+
- name: Lint
79+
run: pnpm lint -- --quiet
8880

8981
build:
9082
needs: changes

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
},
88
"editor.formatOnSaveMode": "file",
99
"eslint.rules.customizations": [
10-
// Defaultt all ESLint errors to 'warn' to differentate from TypeScript's 'error' level
11-
{ "rule": "*", "severity": "warn" },
12-
1310
// Silence some warnings that will get auto-fixed
1411
{ "rule": "perfectionist/*", "severity": "off", "fixable": true },
1512
{ "rule": "curly", "severity": "off", "fixable": true },

eslint.config.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ export const rootEslintConfig = [
8181

8282
export default [
8383
...rootEslintConfig,
84-
{
85-
languageOptions: {
86-
parserOptions: {
87-
...rootParserOptions,
88-
projectService: true,
89-
tsconfigRootDir: import.meta.dirname,
90-
},
91-
},
92-
},
9384
{
9485
files: ['packages/eslint-config/**/*.ts'],
9586
rules: {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
"docker:start": "docker compose -f test/docker-compose.yml up -d",
7575
"docker:stop": "docker compose -f test/docker-compose.yml down",
7676
"force:build": "pnpm run build:core:force",
77-
"lint": "turbo run lint --concurrency 1 --continue",
77+
"lint": "turbo run lint --log-order=grouped --continue",
7878
"lint-staged": "lint-staged",
79-
"lint:fix": "turbo run lint:fix --concurrency 1 --continue",
79+
"lint:fix": "turbo run lint:fix --log-order=grouped --continue",
8080
"obliterate-playwright-cache-macos": "rm -rf ~/Library/Caches/ms-playwright && find /System/Volumes/Data/private/var/folders -type d -name 'playwright*' -exec rm -rf {} +",
8181
"prepare": "husky",
8282
"prepare-run-test-against-prod": "pnpm bf && rm -rf test/packed && rm -rf test/node_modules && rm -rf app && rm -f test/pnpm-lock.yaml && pnpm run script:pack --all --no-build --dest test/packed && pnpm runts test/setupProd.ts && cd test && pnpm i --ignore-workspace && cd ..",

packages/admin-bar/eslint.config.js

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

packages/create-payload-app/eslint.config.js

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

packages/db-mongodb/eslint.config.js

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

packages/db-postgres/eslint.config.js

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

packages/db-sqlite/eslint.config.js

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

packages/db-vercel-postgres/eslint.config.js

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

0 commit comments

Comments
 (0)