-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path.lintstagedrc.js
More file actions
67 lines (63 loc) · 2.57 KB
/
Copy path.lintstagedrc.js
File metadata and controls
67 lines (63 loc) · 2.57 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
/* eslint-env node */
// ⚠️ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
// This file is automatically generated and updated by `@diplodoc/infra update`
// Any manual changes will be overwritten on the next update
// To customize lint-staged configuration, see: https://github.com/diplodoc-platform/infra#configuration
const {readFileSync} = require('node:fs');
const {join} = require('node:path');
// Check if this is the @diplodoc/infra package itself
const isInfraPkg = (() => {
try {
const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));
return pkg.name === '@diplodoc/infra';
} catch {
return false;
}
})();
module.exports = {
// Exclude config files from linting (they use CommonJS)
'**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}': (filenames) => {
// Filter out config files
const configFiles = [
'.lintstagedrc.js',
'.eslintrc.js',
'.prettierrc.js',
'.stylelintrc.js',
'prettier-common-config.js',
];
const filtered = filenames.filter(
(f) =>
!configFiles.some((config) => f.includes(config)) &&
// For @diplodoc/infra package itself: exclude bin/ and scripts/ (in .eslintignore)
!(isInfraPkg && (f.includes('bin/') || f.includes('scripts/'))),
);
if (filtered.length === 0) {
return [];
}
return [
`prettier --write ${filtered.join(' ')}`,
`env ESLINT_USE_FLAT_CONFIG=false npx eslint --max-warnings=0 --fix`,
];
},
// Handle .lintstagedrc.js separately (only prettier, no eslint)
'.lintstagedrc.js': (filenames) => filenames.map((f) => `prettier --write ${f}`),
'**/*.{css,scss}': (filenames) => [
`prettier --write ${filenames.join(' ')}`,
`stylelint --fix ${filenames.join(' ')}`,
],
'**/*.{json,yaml,yml,md}': (filenames) => `prettier --write ${filenames.join(' ')}`,
'**/*.{svg,svgx}': ['svgo'],
// Run unit tests when test files or source files change
'**/*.{ts,tsx}': (filenames) => {
const testFiles = filenames.filter((f) => f.includes('.test.') || f.includes('.spec.'));
const sourceFiles = filenames.filter(
(f) => !f.includes('.test.') && !f.includes('.spec.') && f.includes('src/'),
);
const commands = [];
// Run tests if test files or source files changed
if (testFiles.length > 0 || sourceFiles.length > 0) {
commands.push('npm test');
}
return commands;
},
};