Repository navigation
chore: remove kbd-scripts in favor of native linting config with ESlint #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00bb40b
chore(lint): migrate eslint config to native vs kcd-scripts
lwasser 0daf666
Apply suggestion from @JoshuaKGoldberg
lwasser 6864d99
chore(ci): somehow when i pushed the branch diverged
lwasser d64a014
Merge branch 'main'
JoshuaKGoldberg a5f9246
cleanups: remove pnpm and rushstack
JoshuaKGoldberg 54f8884
align lint.yml to test-deploy
JoshuaKGoldberg a693b3f
whoops, switch lint to npm
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Lint | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Run ESLint | ||
| run: npm run lint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| _ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| npx lint-staged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Development Documentation | ||
|
|
||
| ## Linting | ||
|
|
||
| 2026 update: The project is now using ESLint 9 and the flat config format. As we | ||
|
lwasser marked this conversation as resolved.
Resolved
|
||
| update things from the old config we will update this document to reflect the | ||
| changes. Once the code base is stable and things work, we can delete some of the | ||
| historical documentation. But for now this document can help us track design | ||
| decisions and changes made. | ||
|
|
||
| ### Overview | ||
|
|
||
| The project uses a native ESLint configuration that was migrated from | ||
| kcd-scripts. The setup supports both CommonJS source files and ES module test | ||
| files, using ESLint 9's flat config format. | ||
|
|
||
| ### What changed | ||
|
|
||
| Previously, the project used `kcd-scripts` for linting configuration. Because | ||
| that project is no longer actively maintained, we migrated to a native ESLint | ||
| setup that replicates the same behavior. | ||
|
|
||
| **Migration details:** | ||
|
|
||
| - Replaced `kcd-scripts lint` with native ESLint | ||
| - Created `eslint.config.mjs` using ESLint 9 flat config format | ||
| - Extracted rules from `eslint-config-kentcdodds` to create a simplified, | ||
| maintainable config. This included removing a lot of the custom rules and | ||
| leaning more on the recommended rules. | ||
| - Preserved some custom rule overrides from the original setup | ||
| - Supports both CommonJS (source files) and ES modules (test files) | ||
|
|
||
| Note: We should consider refacting the project to use ES modules instead of | ||
| CommonJS (if everyone supports that) in the future for consistency. | ||
|
|
||
| ### How to run the linter | ||
|
|
||
| To check for linting errors you can run: | ||
|
|
||
| ```bash | ||
| npm run lint | ||
| ``` | ||
|
|
||
| ESlint can automatically fix some errors. to fix errors automatically run: | ||
|
|
||
| ```bash | ||
| npm run lint -- --fix | ||
| ``` | ||
|
|
||
| The `--fix` flag will automatically fix many common issues like: | ||
|
|
||
| - Jest method aliases (e.g., `toThrowError()` → `toThrow()`) | ||
| - Unused eslint-disable directives | ||
| - Some formatting issues | ||
|
|
||
| **Note:** Some errors require manual fixes (e.g., unused variables, tests | ||
| without assertions). | ||
|
|
||
| ### Pre-commit hooks | ||
|
|
||
| The project uses Husky to run pre-commit hooks that automatically lint and fix | ||
| staged files before each commit. | ||
|
|
||
| **How it works:** | ||
|
|
||
| 1. When you run `git commit`, Husky intercepts the commit | ||
| 2. The pre-commit hook runs `lint-staged` | ||
| 3. `lint-staged` runs `eslint --fix` on all staged JavaScript/TypeScript files | ||
|
lwasser marked this conversation as resolved.
Resolved
|
||
| 4. If linting passes, the commit proceeds; if it fails, the commit is blocked | ||
|
|
||
| What this means... this workflow ensures that code is automatically linted and | ||
| fixed before it's committed to version control. | ||
|
|
||
| If you are encountering issues with the pre-commit hook, you can run the | ||
| following command to manually lint and fix the files: | ||
|
|
||
| ```bash | ||
| npm run lint -- --fix | ||
| ``` | ||
|
|
||
| Or if it's really problematic, you can skip verification and commit anyway with | ||
| the `--no-verify` flag. | ||
|
|
||
| ```bash | ||
| git commit --no-verify | ||
| ``` | ||
|
|
||
| If you do this please ping one of the maintainers in the PR that you open so | ||
| they can help you fix the issues! | ||
|
|
||
| **Configuration:** | ||
|
|
||
| - Husky configuration is in `package.json` under the `husky.hooks.pre-commit` | ||
| field | ||
| - `lint-staged` configuration is in `package.json` under the `lint-staged` field | ||
| - The setup uses the native ESLint configuration (`eslint.config.mjs`) | ||
|
|
||
| **Note:** Previously, the project used `kcd-scripts pre-commit` which handled | ||
| both hook management and linting. We migrated to using `lint-staged` directly | ||
| with our native ESLint config to avoid version conflicts. | ||
|
|
||
| ### Dependencies | ||
|
|
||
| The following packages are typical starters for linting a JavaScript project: | ||
|
|
||
| - **eslint** — ESLint core | ||
| - **@eslint/js** — ESLint recommended rules configuration | ||
| - **eslint-plugin-import** — Import/export rules for module resolution and best | ||
| practices | ||
| - **eslint-plugin-jest** — Jest-specific rules for test files | ||
| - **globals** — Provides properly formatted global variables for Node.js and | ||
| Jest environments | ||
|
|
||
| ### Configuration file | ||
|
|
||
| The ESLint configuration is in `eslint.config.mjs` at the project root. It uses | ||
| ESLint 9's flat config format and includes: | ||
|
|
||
| - Base rules from `eslint:recommended` | ||
| - Import plugin rules | ||
| - Jest plugin rules (for test files only) | ||
| - Custom overrides for project-specific needs | ||
| - Support for both CommonJS and ES module syntax | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import js from '@eslint/js' | ||
| import {defineConfig, globalIgnores} from 'eslint/config' | ||
| import importPlugin from 'eslint-plugin-import' | ||
| import jestPlugin from 'eslint-plugin-jest' | ||
| import globals from 'globals' | ||
|
|
||
| export default defineConfig([ | ||
| globalIgnores(['coverage/**', 'dist/**']), | ||
| {linterOptions: {reportUnusedDisableDirectives: 'error'}}, | ||
| { | ||
| extends: [js.configs.recommended, importPlugin.flatConfigs.recommended], | ||
| files: ['**/*.{mjs,js}'], | ||
| languageOptions: { | ||
| ecmaVersion: 'latest', | ||
| globals: globals.node, | ||
| }, | ||
| rules: { | ||
| 'import/no-unresolved': ['error', {ignore: ['^eslint/', '^prettier$']}], | ||
| 'import/no-extraneous-dependencies': 'error', | ||
| 'import/default': 'off', | ||
| 'import/namespace': 'off', | ||
| }, | ||
| }, | ||
| { | ||
| extends: [jestPlugin.configs['flat/recommended']], | ||
| files: ['**/__tests__/**/*.js'], | ||
| languageOptions: { | ||
| globals: globals.jest, | ||
| }, | ||
| rules: { | ||
| 'jest/no-disabled-tests': 'error', | ||
| 'jest/prefer-to-have-length': 'error', | ||
| }, | ||
| }, | ||
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,5 @@ module.exports = Object.assign(jestConfig, { | |
| statements: 50, | ||
| }, | ||
| }, | ||
| forceExit: true | ||
| forceExit: true, | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I was in the area, I fixed up the Husky + lint-staged config. This should work to run
lint-stagedon precommits now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!