-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy path.lintstagedrc.js
More file actions
113 lines (105 loc) · 3.54 KB
/
.lintstagedrc.js
File metadata and controls
113 lines (105 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// .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);
}
};
// Allow to cd into a subdirectory
const sh_cd = (directory, command) => {
if (process.platform == "win32") {
return `cmd /k 'cd ${directory} && ${command}'`;
}
return `sh -c 'cd ${directory} && ${command}'`;
};
module.exports = {
// Python checks (run from root, using root venv)
"dash/*.py": (filenames) => [
`${venvBin("python")} -m pylint --rcfile=.pylintrc ${filenames.join(
" "
)}`,
`${venvBin("flake8")} ${filenames.join(" ")}`,
`${venvBin("black")} --check ${filenames.join(" ")}`,
],
"**/tests/**/*.py": (filenames) => [
`${venvBin("python")} -m pylint -d all -e C0410,C0413,W0109 --rcfile=.pylintrc ${filenames.join(
" "
)}`,
`${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 [
sh_cd(
"components/dash-core-components",
`npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join(
" "
)}`
),
sh_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 [
sh_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 [
sh_cd(
"components/dash-table",
`npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join(
" "
)}`
),
sh_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 [
sh_cd(
"dash/dash-renderer",
`npx eslint --no-error-on-unmatched-pattern ${relativeFilePaths.join(
" "
)}`
),
sh_cd(
"dash/dash-renderer",
`npx prettier --check ${relativeFilePaths.join(" ")}`
),
];
},
};