-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add lint-staged to pre-commit #3321
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
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
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| npm run lint && \ | ||
| (cd components/dash-core-components && npm run lint) && \ | ||
| (cd components/dash-table && npm run lint) | ||
| #!/usr/bin/env sh | ||
| . "$(dirname -- "$0")/_/husky.sh" | ||
|
|
||
| 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,82 @@ | ||
| // .lintstagedrc.js | ||
| const path = require("path"); | ||
| const fs = require('fs') | ||
|
|
||
| // Helper to resolve path to venv executables | ||
| const venvBin = (command) => { | ||
| let bin = "bin"; | ||
| if (process.platform == "win32") { | ||
| bin = "Scripts"; | ||
| } | ||
| if (fs.existsSync("venv")) { | ||
| return path.join("venv", bin, command); | ||
| } | ||
| if (fs.existsSync(".venv")) { | ||
| return path.join(".venv", bin, command); | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| // Python checks (run from root, using root venv) | ||
| "*.py": (filenames) => [ | ||
| `${venvBin("python")} -m pylint --rcfile=.pylintrc ${filenames.join( | ||
| " " | ||
| )}`, // Add your pylintrc if you have one | ||
| `${venvBin("flake8")} ${filenames.join(" ")}`, | ||
| `${venvBin("black")} --check ${filenames.join(" ")}`, | ||
| ], | ||
|
|
||
| // ESLint and Prettier for 'components/dash-core-components' | ||
| "components/dash-core-components/**/*.{js,jsx,ts,tsx}": (filenames) => { | ||
| const relativeFilePaths = filenames.map((f) => | ||
| path.relative(path.join("components", "dash-core-components"), f) | ||
| ); | ||
| return [ | ||
| `cd components/dash-core-components && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| `cd components/dash-core-components && npx prettier --check ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| ]; | ||
| }, | ||
|
|
||
| "components/dash-html-components/**/*.{js,jsx,ts,tsx}": (filenames) => { | ||
| const relativeFilePaths = filenames.map((f) => | ||
| path.relative(path.join("components", "dash-html-components"), f) | ||
| ); | ||
| return [ | ||
| `cd components/dash-html-components && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| ]; | ||
| }, | ||
|
|
||
| "components/dash-table/**/*.{js,jsx,ts,tsx}": (filenames) => { | ||
| const relativeFilePaths = filenames.map((f) => | ||
| path.relative(path.join("components", "dash-table"), f) | ||
| ); | ||
| return [ | ||
| `cd components/dash-table && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| `cd components/dash-table && npx prettier --check ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| ]; | ||
| }, | ||
|
|
||
| "dash/dash-renderer/**/*.{js,jsx,ts,tsx}": (filenames) => { | ||
| const relativeFilePaths = filenames.map((f) => | ||
| path.relative(path.join("dash", "dash-renderer"), f) | ||
| ); | ||
| return [ | ||
| `cd dash/dash-renderer && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| `cd dash/dash-renderer && npx prettier --check ${relativeFilePaths.join( | ||
| " " | ||
| )}`, | ||
| ]; | ||
| }, | ||
| }; |
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.
@T4rk1n Are these linting steps the same as what is triggered by
npm run lint?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.
Not really, it just lint the files that are staged and run the commands with fail-fast. But in the end it runs the proper linting for the files that changed, it cd to the proper sub npm package for eslint/prettier config of those.
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.
Gotcha. Just want to make sure we don't end up in a situation where this script lints the files differently than
npm run lint.Is there a risk of that happening in the future if someone edits this file but not
package.json?Should we remove the
npm run lintcommands entirely? Or can we makepackage.jsonand this script both refer to the same source of truth?