@naturalcycles/dev-lib 19.27.0 → 19.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cfg/_cnst.js +1 -1
- package/cfg/biome.jsonc +3 -1
- package/cfg/lint-staged.config.js +96 -98
- package/dist/bin/dev-lib.js +1 -0
- package/dist/lint.util.js +3 -2
- package/package.json +3 -2
- package/cfg/init/biome.jsonc +0 -5
package/cfg/_cnst.js
CHANGED
|
@@ -7,7 +7,7 @@ const prettierExtensionsAll =
|
|
|
7
7
|
const eslintExtensions = 'ts,tsx,cts,mts,vue,html'
|
|
8
8
|
const stylelintExtensions = 'css,scss'
|
|
9
9
|
const lintExclude = ['./**/__exclude/**', './**/dist/**', './**/cache/**', './CHANGELOG.md']
|
|
10
|
-
const minActionlintVersion = '1.7.
|
|
10
|
+
const minActionlintVersion = '1.7.7'
|
|
11
11
|
|
|
12
12
|
export {
|
|
13
13
|
prettierDirs,
|
package/cfg/biome.jsonc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/2.
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
|
|
3
3
|
"root": false,
|
|
4
4
|
"files": {
|
|
5
5
|
"includes": [
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"correctness": {
|
|
37
37
|
"useImportExtensions": "error",
|
|
38
|
+
"useParseIntRadix": "off",
|
|
38
39
|
"noUnusedFunctionParameters": "error",
|
|
39
40
|
// noUnusedImports + noUnusedVariables can replace eslint-plugin-unused-vars!
|
|
40
41
|
"noUnusedImports": "error",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
},
|
|
74
75
|
"suspicious": {
|
|
75
76
|
"useNumberToFixedDigitsArgument": "error",
|
|
77
|
+
"useIterableCallbackReturn": "off",
|
|
76
78
|
"useErrorMessage": "error",
|
|
77
79
|
"noEvolvingTypes": "error",
|
|
78
80
|
"noExplicitAny": "off",
|
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
platform,
|
|
9
9
|
arch,
|
|
10
10
|
versions: { node },
|
|
11
|
+
// env: { ESLINT_CONCURRENCY },
|
|
11
12
|
} = process
|
|
12
13
|
|
|
13
14
|
console.log(`lint-staged.config.js runs on node ${node} ${platform} ${arch}`)
|
|
@@ -36,12 +37,21 @@ const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
|
|
|
36
37
|
// const tsconfigPathRoot = ['tsconfig.base.json'].find(p => fs.existsSync(p)) || 'tsconfig.json'
|
|
37
38
|
// const tsconfigPathRoot = 'tsconfig.json'
|
|
38
39
|
|
|
39
|
-
const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
|
|
40
|
+
// const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
|
|
40
41
|
|
|
41
42
|
const prettierCmd =
|
|
42
43
|
!!prettierConfigPath &&
|
|
43
44
|
`prettier --write --experimental-cli --config-path ${prettierConfigPath} --cache-location node_modules/.cache/prettier`
|
|
44
|
-
const eslintCmd =
|
|
45
|
+
const eslintCmd = [
|
|
46
|
+
'eslint',
|
|
47
|
+
'--fix',
|
|
48
|
+
'--cache',
|
|
49
|
+
// concurrency is disabled here, as it's not expected to help,
|
|
50
|
+
// since we're running on a limited set of files already
|
|
51
|
+
// ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
|
|
52
|
+
]
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.join(' ')
|
|
45
55
|
|
|
46
56
|
const stylelintExists =
|
|
47
57
|
!!stylelintConfigPath &&
|
|
@@ -53,40 +63,25 @@ const stylelintCmd = stylelintExists ? `stylelint --fix --config ${stylelintConf
|
|
|
53
63
|
const biomeConfigPath = ['biome.jsonc'].find(p => fs.existsSync(p))
|
|
54
64
|
const biomeCmd = biomeConfigPath && `biome lint --write --unsafe --no-errors-on-unmatched`
|
|
55
65
|
|
|
56
|
-
if (!eslintConfigPathRoot) {
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
if (!prettierCmd) {
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if (!stylelintCmd) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
66
|
+
// if (!eslintConfigPathRoot) {
|
|
67
|
+
// console.log('eslint is skipped, because ./eslint.config.js is not present')
|
|
68
|
+
// }
|
|
69
|
+
// if (!prettierCmd) {
|
|
70
|
+
// console.log('prettier is skipped, because ./prettier.config.js is not present')
|
|
71
|
+
// }
|
|
72
|
+
// if (!stylelintCmd) {
|
|
73
|
+
// console.log(
|
|
74
|
+
// 'stylelint is skipped, because ./stylelint.config.js is not present, or stylelint and/or stylelint-config-standard-scss are not installed',
|
|
75
|
+
// )
|
|
76
|
+
// }
|
|
67
77
|
|
|
68
78
|
const linters = {
|
|
69
79
|
// biome, eslint, prettier
|
|
70
|
-
'./src/**/*.{ts,tsx,cts,mts,vue,html}': match =>
|
|
71
|
-
const filesList = getFilesList(match)
|
|
72
|
-
if (!filesList) return []
|
|
73
|
-
return [
|
|
74
|
-
biomeCmd,
|
|
75
|
-
eslintConfigPathRoot &&
|
|
76
|
-
`${eslintCmd} --config ${eslintConfigPathRoot} --parser-options=tsconfigRootDir:. --cache-location node_modules/.cache/eslint_src`,
|
|
77
|
-
prettierCmd,
|
|
78
|
-
]
|
|
79
|
-
.filter(Boolean)
|
|
80
|
-
.map(s => `${s} ${filesList}`)
|
|
81
|
-
},
|
|
80
|
+
'./src/**/*.{ts,tsx,cts,mts,vue,html}': match => runBiomeEslintPrettier(match, 'src'),
|
|
82
81
|
|
|
83
82
|
// For all other files we run only Prettier (because e.g eslint screws *.scss files)
|
|
84
83
|
// todo: this should be no longer needed when flat eslint config is default and it has global ignore of scss files
|
|
85
|
-
[`./{${prettierDirs}}/**/*.{${prettierExtensionsExclusive}}`]:
|
|
86
|
-
const filesList = getFilesList(match)
|
|
87
|
-
if (!filesList || !prettierCmd) return []
|
|
88
|
-
return [prettierCmd].map(s => `${s} ${filesList}`)
|
|
89
|
-
},
|
|
84
|
+
[`./{${prettierDirs}}/**/*.{${prettierExtensionsExclusive}}`]: runPrettier,
|
|
90
85
|
|
|
91
86
|
// Files for ESLint + Prettier
|
|
92
87
|
// doesn't work, cause typescript parser+rules are conflicting
|
|
@@ -99,92 +94,95 @@ const linters = {
|
|
|
99
94
|
// },
|
|
100
95
|
|
|
101
96
|
// Files for Biome + Stylelint + Prettier
|
|
102
|
-
[`./{${prettierDirs}}/**/*.{${stylelintExtensions}}`]:
|
|
103
|
-
const filesList = getFilesList(match)
|
|
104
|
-
if (!filesList) return []
|
|
105
|
-
// Biome's css/scss support is still in nursery, so Biome is disabled for now
|
|
106
|
-
return [stylelintCmd, prettierCmd].filter(Boolean).map(s => `${s} ${filesList}`)
|
|
107
|
-
},
|
|
97
|
+
[`./{${prettierDirs}}/**/*.{${stylelintExtensions}}`]: runBiomeStylelintPrettier,
|
|
108
98
|
|
|
109
99
|
// Files in root dir: prettier
|
|
110
|
-
[`./*.{${prettierExtensionsAll}}`]:
|
|
111
|
-
const filesList = getFilesList(match)
|
|
112
|
-
if (!filesList || !prettierCmd) return []
|
|
113
|
-
return [prettierCmd].map(s => `${s} ${filesList}`)
|
|
114
|
-
},
|
|
100
|
+
[`./*.{${prettierExtensionsAll}}`]: runPrettier,
|
|
115
101
|
|
|
116
102
|
// ktlint
|
|
117
|
-
'**/*.{kt,kts}':
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const dir = './node_modules/@naturalcycles/ktlint'
|
|
121
|
-
|
|
122
|
-
if (!fs.existsSync(dir)) {
|
|
123
|
-
console.log(`!!\n!! Please install @naturalcycles/ktlint to lint *.kt files\n!!\n`, filesList)
|
|
124
|
-
return []
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return [`${dir}/resources/ktlint -F ${filesList}`]
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
'./.github/**/*.{yml,yaml}': match => {
|
|
131
|
-
if (!match.length) return []
|
|
132
|
-
|
|
133
|
-
if (!canRunBinary('actionlint')) {
|
|
134
|
-
console.log(
|
|
135
|
-
`actionlint is not installed and won't be run.\nThis is how to install it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`,
|
|
136
|
-
)
|
|
137
|
-
return []
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
requireActionlintVersion()
|
|
141
|
-
|
|
142
|
-
// run actionlint on all files at once, as it's fast anyway
|
|
143
|
-
return [`actionlint`]
|
|
144
|
-
},
|
|
103
|
+
'**/*.{kt,kts}': runKtlint,
|
|
104
|
+
|
|
105
|
+
'./.github/**/*.{yml,yaml}': runActionlint,
|
|
145
106
|
}
|
|
146
107
|
|
|
147
108
|
// /scripts are separate, cause they require separate tsconfig.json
|
|
148
109
|
if (fs.existsSync(`./scripts`)) {
|
|
149
|
-
const eslintConfigPathScripts = ['scripts/eslint.config.js'].find(p => fs.existsSync(p))
|
|
150
110
|
Object.assign(linters, {
|
|
151
|
-
|
|
152
|
-
'./scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => {
|
|
153
|
-
const filesList = getFilesList(match)
|
|
154
|
-
if (!filesList) return []
|
|
155
|
-
return [
|
|
156
|
-
biomeCmd,
|
|
157
|
-
eslintConfigPathScripts &&
|
|
158
|
-
`${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:scripts/tsconfig.json --parser-options=tsconfigRootDir:. --cache-location node_modules/.cache/eslint_scripts`,
|
|
159
|
-
prettierCmd,
|
|
160
|
-
]
|
|
161
|
-
.filter(Boolean)
|
|
162
|
-
.map(s => `${s} ${filesList}`)
|
|
163
|
-
},
|
|
111
|
+
'./scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => runBiomeEslintPrettier(match, 'scripts'),
|
|
164
112
|
})
|
|
165
113
|
}
|
|
166
114
|
|
|
167
115
|
// /e2e
|
|
168
116
|
if (fs.existsSync(`./e2e`)) {
|
|
169
|
-
const eslintConfigPathE2e = ['e2e/eslint.config.js'].find(p => fs.existsSync(p))
|
|
170
|
-
|
|
171
117
|
Object.assign(linters, {
|
|
172
|
-
|
|
173
|
-
'./e2e/**/*.{ts,tsx,cts,mts}': match => {
|
|
174
|
-
const filesList = getFilesList(match)
|
|
175
|
-
if (!filesList) return []
|
|
176
|
-
return [
|
|
177
|
-
biomeCmd,
|
|
178
|
-
eslintConfigPathE2e &&
|
|
179
|
-
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:e2e/tsconfig.json --parser-options=tsconfigRootDir:. --cache-location ./node_modules/.cache/eslint_e2e`,
|
|
180
|
-
prettierCmd,
|
|
181
|
-
]
|
|
182
|
-
.filter(Boolean)
|
|
183
|
-
.map(s => `${s} ${filesList}`)
|
|
184
|
-
},
|
|
118
|
+
'./e2e/**/*.{ts,tsx,cts,mts}': match => runBiomeEslintPrettier(match, 'e2e'),
|
|
185
119
|
})
|
|
186
120
|
}
|
|
187
121
|
|
|
122
|
+
export function runBiomeEslintPrettier(match, dir) {
|
|
123
|
+
const filesList = getFilesList(match)
|
|
124
|
+
if (!filesList) return []
|
|
125
|
+
|
|
126
|
+
let configDir = dir
|
|
127
|
+
if (dir === 'src') {
|
|
128
|
+
configDir = '.'
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const eslintConfigPath = `${configDir}/eslint.config.js`
|
|
132
|
+
const tsconfigPath = `${configDir}/tsconfig.json`
|
|
133
|
+
|
|
134
|
+
return [
|
|
135
|
+
biomeCmd,
|
|
136
|
+
eslintConfigPath &&
|
|
137
|
+
`${eslintCmd} --config ${eslintConfigPath} --parser-options=tsconfigRootDir:. --parser-options=project:${tsconfigPath} --cache-location node_modules/.cache/eslint_${dir}`,
|
|
138
|
+
prettierCmd,
|
|
139
|
+
]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.map(s => `${s} ${filesList}`)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function runPrettier(match) {
|
|
145
|
+
const filesList = getFilesList(match)
|
|
146
|
+
if (!filesList || !prettierCmd) return []
|
|
147
|
+
return [prettierCmd].map(s => `${s} ${filesList}`)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function runBiomeStylelintPrettier(match) {
|
|
151
|
+
const filesList = getFilesList(match)
|
|
152
|
+
if (!filesList) return []
|
|
153
|
+
// Biome's css/scss support is still in nursery, so Biome is disabled for now
|
|
154
|
+
return [stylelintCmd, prettierCmd].filter(Boolean).map(s => `${s} ${filesList}`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function runKtlint(match) {
|
|
158
|
+
const filesList = getFilesList(match)
|
|
159
|
+
if (!filesList) return []
|
|
160
|
+
const dir = './node_modules/@naturalcycles/ktlint'
|
|
161
|
+
|
|
162
|
+
if (!fs.existsSync(dir)) {
|
|
163
|
+
console.log(`!!\n!! Please install @naturalcycles/ktlint to lint *.kt files\n!!\n`, filesList)
|
|
164
|
+
return []
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return [`${dir}/resources/ktlint -F ${filesList}`]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function runActionlint(match) {
|
|
171
|
+
if (!match.length) return []
|
|
172
|
+
|
|
173
|
+
if (!canRunBinary('actionlint')) {
|
|
174
|
+
console.log(
|
|
175
|
+
`actionlint is not installed and won't be run.\nThis is how to install it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`,
|
|
176
|
+
)
|
|
177
|
+
return []
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
requireActionlintVersion()
|
|
181
|
+
|
|
182
|
+
// run actionlint on all files at once, as it's fast anyway
|
|
183
|
+
return [`actionlint`]
|
|
184
|
+
}
|
|
185
|
+
|
|
188
186
|
function getFilesList(match) {
|
|
189
187
|
return micromatch.not(match, lintExclude).join(' ')
|
|
190
188
|
}
|
package/dist/bin/dev-lib.js
CHANGED
package/dist/lint.util.js
CHANGED
|
@@ -15,7 +15,7 @@ import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
|
15
15
|
import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
|
|
16
16
|
import { eslintExtensions, lintExclude, minActionlintVersion, prettierDirs, prettierExtensionsAll, stylelintExtensions, } from '../cfg/_cnst.js';
|
|
17
17
|
import { cfgDir } from './paths.js';
|
|
18
|
-
const { CI } = process.env;
|
|
18
|
+
const { CI, ESLINT_CONCURRENCY } = process.env;
|
|
19
19
|
/**
|
|
20
20
|
* Run all linters.
|
|
21
21
|
*/
|
|
@@ -132,13 +132,14 @@ async function runESLint(dir, extensions = eslintExtensions.split(','), fix = tr
|
|
|
132
132
|
`--parser-options=project:${tsconfigPath}`,
|
|
133
133
|
// The next line fixes the `typescript-eslint` 8.37 bug of resolving tsconfig.json
|
|
134
134
|
`--parser-options=tsconfigRootDir:.`,
|
|
135
|
+
ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
|
|
135
136
|
'--cache',
|
|
136
137
|
'--cache-location',
|
|
137
138
|
cacheLocation,
|
|
138
139
|
`--no-error-on-unmatched-pattern`,
|
|
139
140
|
`--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
|
|
140
141
|
fix ? `--fix` : '',
|
|
141
|
-
].filter(
|
|
142
|
+
].filter(_isTruthy),
|
|
142
143
|
shell: false,
|
|
143
144
|
env: _filterFalsyValues({
|
|
144
145
|
// Print eslint plugin timing, but only in CI
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "19.
|
|
4
|
+
"version": "19.29.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@biomejs/biome": "2
|
|
6
|
+
"@biomejs/biome": "^2",
|
|
7
7
|
"@commitlint/cli": "^19",
|
|
8
8
|
"@commitlint/config-conventional": "^19",
|
|
9
9
|
"@eslint/js": "^9",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"lint": "tsx ./src/bin/dev-lib.ts lint",
|
|
104
104
|
"eslint": "tsx ./src/bin/dev-lib.ts eslint",
|
|
105
105
|
"eslint-no-fix": "tsx ./src/bin/dev-lib.ts eslint-no-fix",
|
|
106
|
+
"biome-no-fix": "tsx ./src/bin/dev-lib.ts biome-no-fix",
|
|
106
107
|
"lint-staged-debug": "tsx ./src/bin/dev-lib.ts lint-staged"
|
|
107
108
|
}
|
|
108
109
|
}
|