-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.lintstagedrc.js
More file actions
100 lines (90 loc) · 2.86 KB
/
.lintstagedrc.js
File metadata and controls
100 lines (90 loc) · 2.86 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
/**
* @filename: lint-staged.config.js
* @type {import('lint-staged').Configuration}
*/
export default {
/** Javascript codefiles: */
'*.{mjs,js,jsx,cjs}': (files) => {
const found = files
.filter(
(f) => f.endsWith('.js') || f.endsWith('.jsx') || f.endsWith('.mjs') || f.endsWith('.cjs')
)
.map((f) => `"${f}"`)
return [
`npx prettier --write ${found.join(' ')}`,
`npx eslint ${found.join(' ')} --fix`,
`node scripts/lint.js --js --fix --only -- ${found.join(' ')}`,
`npx standard ${found.join(' ')} --fix`
]
},
/** Typescript codefiles (excluding typings): */
'*.{mts,ts,tsx,cts}': (files) => {
const found = files
.filter(
(f) =>
f.endsWith('.ts') ||
f.endsWith('.tsx') ||
f.endsWith('.mts') ||
(f.endsWith('.cts') && !f.endsWith('.d.ts'))
)
.map((f) => `"${f}"`)
return [
`npx prettier --write ${found.join(' ')}`,
`npx eslint ${found.join(' ')} --fix`,
`npx ts-standard ${found.join(' ')} --fix`
]
},
/** Typescript typings: */
'*.d.ts': (files) => {
const found = files.filter((f) => f.endsWith('.d.ts')).map((f) => `"${f}"`)
return [`npx prettier --write ${found.join(' ')}`]
},
/** Markdown files: */
'*.md': (files) => {
const EXCLUDING = ['CHANGELOG.md', 'UNSUPPORTED_VERSIONS.md']
const found = files
.filter(
(f) =>
f.endsWith('.md') &&
!EXCLUDING.some((name) => f.endsWith(name)) &&
!f.match(/^.*\/changes\/v[^/]+/)
)
.map((f) => `"${f}"`)
return [
`npx textlint ${found.join(' ')} --fix`,
`npx markdownlint-cli2 "!{CHANGELOG.md,node_modules/**,out/**}" ${found.join(' ')} --fix`
]
},
'*.{gn,gni}': ['npm run gn-check', 'npm run gn-format'],
/** Media: */
'*.{png,jpeg,jpg,gif,svg}': 'imagemin-lint-staged',
/** Styles: */
'*.*css': (files) => {
const found = files
.filter((f) => f.endsWith('.css') || f.endsWith('.scss'))
.map((f) => `"${f}"`)
return [`stylelint --fix ${found.join(' ')}`, `prettier --write ${found.join(' ')}`]
},
/** Patches: */
'{*.patch,.patches}': (files) => {
const found = files
.filter((f) => f.endsWith('.patch') || f.endsWith('.patches'))
.map((f) => `"${f}"`)
return [
`node scripts/lint.js --patches --only -- ${found.join(' ')}`,
`ts-node scripts/js/check-patch-diff.ts ${found.join(' ')}`
]
},
/** YAML: */
'*.{yml,yaml}': (files) => {
const found = files.filter((f) => f.endsWith('yml') || f.endsWith('yaml')).map((f) => `"${f}"`)
return [`npx prettier ${found.join(' ')} --write`]
},
/** JSON: */
'*.{json,jsonc}': (files) => {
const found = files
.filter((f) => f.endsWith('json') || f.endsWith('jsonc'))
.map((f) => `"${f}"`)
return [`npx eslint ${found.join(' ')} --fix`]
}
}