Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .husky/pre-commit
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
82 changes: 82 additions & 0 deletions .lintstagedrc.js
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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 lint commands entirely? Or can we make package.json and this script both refer to the same source of truth?

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(
" "
)}`,
];
},
};
Loading