|
| 1 | +// .lintstagedrc.js |
| 2 | +const path = require("path"); |
| 3 | +const fs = require('fs') |
| 4 | + |
| 5 | +// Helper to resolve path to venv executables |
| 6 | +const venvBin = (command) => { |
| 7 | + let bin = "bin"; |
| 8 | + if (process.platform == "win32") { |
| 9 | + bin = "Scripts"; |
| 10 | + } |
| 11 | + if (fs.existsSync("venv")) { |
| 12 | + return path.join("venv", bin, command); |
| 13 | + } |
| 14 | + if (fs.existsSync(".venv")) { |
| 15 | + return path.join(".venv", bin, command); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +module.exports = { |
| 20 | + // Python checks (run from root, using root venv) |
| 21 | + "*.py": (filenames) => [ |
| 22 | + `${venvBin("python")} -m pylint --rcfile=.pylintrc ${filenames.join( |
| 23 | + " " |
| 24 | + )}`, // Add your pylintrc if you have one |
| 25 | + `${venvBin("flake8")} ${filenames.join(" ")}`, |
| 26 | + `${venvBin("black")} --check ${filenames.join(" ")}`, |
| 27 | + ], |
| 28 | + |
| 29 | + // ESLint and Prettier for 'components/dash-core-components' |
| 30 | + "components/dash-core-components/**/*.{js,jsx,ts,tsx}": (filenames) => { |
| 31 | + const relativeFilePaths = filenames.map((f) => |
| 32 | + path.relative(path.join("components", "dash-core-components"), f) |
| 33 | + ); |
| 34 | + return [ |
| 35 | + `cd components/dash-core-components && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( |
| 36 | + " " |
| 37 | + )}`, |
| 38 | + `cd components/dash-core-components && npx prettier --check ${relativeFilePaths.join( |
| 39 | + " " |
| 40 | + )}`, |
| 41 | + ]; |
| 42 | + }, |
| 43 | + |
| 44 | + "components/dash-html-components/**/*.{js,jsx,ts,tsx}": (filenames) => { |
| 45 | + const relativeFilePaths = filenames.map((f) => |
| 46 | + path.relative(path.join("components", "dash-html-components"), f) |
| 47 | + ); |
| 48 | + return [ |
| 49 | + `cd components/dash-html-components && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( |
| 50 | + " " |
| 51 | + )}`, |
| 52 | + ]; |
| 53 | + }, |
| 54 | + |
| 55 | + "components/dash-table/**/*.{js,jsx,ts,tsx}": (filenames) => { |
| 56 | + const relativeFilePaths = filenames.map((f) => |
| 57 | + path.relative(path.join("components", "dash-table"), f) |
| 58 | + ); |
| 59 | + return [ |
| 60 | + `cd components/dash-table && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( |
| 61 | + " " |
| 62 | + )}`, |
| 63 | + `cd components/dash-table && npx prettier --check ${relativeFilePaths.join( |
| 64 | + " " |
| 65 | + )}`, |
| 66 | + ]; |
| 67 | + }, |
| 68 | + |
| 69 | + "dash/dash-renderer/**/*.{js,jsx,ts,tsx}": (filenames) => { |
| 70 | + const relativeFilePaths = filenames.map((f) => |
| 71 | + path.relative(path.join("dash", "dash-renderer"), f) |
| 72 | + ); |
| 73 | + return [ |
| 74 | + `cd dash/dash-renderer && npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join( |
| 75 | + " " |
| 76 | + )}`, |
| 77 | + `cd dash/dash-renderer && npx prettier --check ${relativeFilePaths.join( |
| 78 | + " " |
| 79 | + )}`, |
| 80 | + ]; |
| 81 | + }, |
| 82 | +}; |
0 commit comments