@naturalcycles/dev-lib 13.56.0 → 14.0.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/eslint.config.js +68 -48
- package/cfg/init/commitlint.config.js +3 -1
- package/cfg/init/eslint.config.js +4 -0
- package/cfg/init/lint-staged.config.js +3 -1
- package/cfg/lint-staged.config.js +60 -41
- package/dist/bin/lint-staged-def.js +6 -5
- package/dist/cmd/eslint-all.command.js +5 -9
- package/dist/util/jest.util.d.ts +1 -1
- package/dist/util/jest.util.js +5 -1
- package/dist/util/lint.util.d.ts +2 -2
- package/dist/util/lint.util.js +5 -14
- package/dist/util/prettier.util.js +3 -3
- package/dist/util/stylelint.util.js +3 -2
- package/package.json +4 -3
- package/readme.md +1 -1
- package/cfg/eslint-rules-post-prettier.js +0 -8
- package/cfg/eslint-vue2.config.js +0 -32
- package/cfg/eslint-vue3.config.js +0 -32
- package/cfg/init/.eslintrc.js +0 -3
package/cfg/eslint.config.js
CHANGED
|
@@ -1,64 +1,84 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @naturalcycles/dev-lib/cfg/eslint.config.js
|
|
3
3
|
*
|
|
4
|
-
* Shared eslint config.
|
|
4
|
+
* Shared eslint FLAT config.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const globals = require('globals')
|
|
8
|
+
const eslint = require('@eslint/js')
|
|
9
|
+
const tseslint = require('typescript-eslint')
|
|
10
|
+
|
|
7
11
|
// detect if jest is installed
|
|
8
12
|
const hasJest = require('node:fs').existsSync('./node_modules/jest')
|
|
9
|
-
// console.log({hasJest})
|
|
13
|
+
// console.log({ hasJest })
|
|
10
14
|
|
|
11
|
-
module.exports =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
module.exports = [
|
|
16
|
+
eslint.configs.recommended,
|
|
17
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts
|
|
18
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
19
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts
|
|
20
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
21
|
+
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/configs/recommended.js
|
|
22
|
+
require('eslint-plugin-unicorn').configs['flat/recommended'],
|
|
23
|
+
// https://eslint.vuejs.org/user-guide/#user-guide
|
|
24
|
+
...require('eslint-plugin-vue').configs['flat/recommended'],
|
|
25
|
+
{
|
|
26
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
27
|
+
...getConfig(),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
files: ['*.vue', '**/*.vue'],
|
|
31
|
+
languageOptions: {
|
|
32
|
+
parserOptions: {
|
|
33
|
+
project: 'tsconfig.json',
|
|
34
|
+
parser: tseslint.parser,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
plugins: getConfig().plugins,
|
|
38
|
+
rules: getConfig().rules,
|
|
17
39
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// testcafe
|
|
21
|
-
fixture: 'readable',
|
|
40
|
+
{
|
|
41
|
+
ignores: ['**/__exclude/**', '**/*.scss', '**/*.js'],
|
|
22
42
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
'
|
|
44
|
-
|
|
45
|
-
parser:
|
|
43
|
+
].filter(Boolean)
|
|
44
|
+
|
|
45
|
+
function getConfig() {
|
|
46
|
+
return {
|
|
47
|
+
plugins: {
|
|
48
|
+
'@typescript-eslint': tseslint.plugin,
|
|
49
|
+
import: require('eslint-plugin-import'),
|
|
50
|
+
'unused-imports': require('eslint-plugin-unused-imports'),
|
|
51
|
+
'simple-import-sort': require('eslint-plugin-simple-import-sort'),
|
|
52
|
+
jsdoc: require('eslint-plugin-jsdoc'),
|
|
53
|
+
jest: hasJest ? require('eslint-plugin-jest') : undefined,
|
|
54
|
+
},
|
|
55
|
+
languageOptions: {
|
|
56
|
+
ecmaVersion: 'latest',
|
|
57
|
+
globals: {
|
|
58
|
+
...globals.browser,
|
|
59
|
+
...globals.node,
|
|
60
|
+
...globals.jest,
|
|
61
|
+
NodeJS: 'readonly',
|
|
62
|
+
// testcafe
|
|
63
|
+
fixture: 'readonly',
|
|
64
|
+
},
|
|
65
|
+
parser: tseslint.parser,
|
|
46
66
|
parserOptions: {
|
|
47
|
-
project:
|
|
48
|
-
sourceType: 'module',
|
|
67
|
+
project: 'tsconfig.json',
|
|
49
68
|
ecmaVersion: 'latest',
|
|
50
69
|
extraFileExtensions: ['.vue', '.html'],
|
|
51
70
|
},
|
|
52
|
-
plugins: [
|
|
53
|
-
'jsdoc',
|
|
54
|
-
'import',
|
|
55
|
-
'simple-import-sort',
|
|
56
|
-
'@typescript-eslint',
|
|
57
|
-
// https://github.com/sweepline/eslint-plugin-unused-imports
|
|
58
|
-
'unused-imports',
|
|
59
|
-
hasJest && 'jest',
|
|
60
|
-
'unicorn',
|
|
61
|
-
].filter(Boolean),
|
|
62
71
|
},
|
|
63
|
-
|
|
72
|
+
linterOptions: {
|
|
73
|
+
reportUnusedDisableDirectives: 'error',
|
|
74
|
+
},
|
|
75
|
+
rules: {
|
|
76
|
+
...require('./eslint-rules').rules,
|
|
77
|
+
...require('./eslint-vue-rules').rules,
|
|
78
|
+
...(hasJest ? require('./eslint-jest-rules').rules : {}),
|
|
79
|
+
...require('eslint-config-prettier').rules,
|
|
80
|
+
// Override prettier-config:
|
|
81
|
+
curly: [2, 'multi-line'],
|
|
82
|
+
},
|
|
83
|
+
}
|
|
64
84
|
}
|
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
Supports default configs for `prettier`, `stylelint`, `eslint`, if they are not found in target project.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
// this probably doesn't work, but we're still trying
|
|
8
|
-
process.env['ESLINT_USE_FLAT_CONFIG'] = 'false'
|
|
9
|
-
|
|
10
|
-
const micromatch = require('micromatch')
|
|
11
7
|
const fs = require('node:fs')
|
|
8
|
+
const micromatch = require('micromatch')
|
|
12
9
|
const { execSync } = require('node:child_process')
|
|
13
10
|
const {
|
|
14
11
|
prettierDirs,
|
|
@@ -17,43 +14,53 @@ const {
|
|
|
17
14
|
stylelintExtensions,
|
|
18
15
|
lintExclude,
|
|
19
16
|
} = require('./_cnst')
|
|
20
|
-
const cfgDir = __dirname
|
|
21
17
|
|
|
22
|
-
const prettierConfigPath =
|
|
23
|
-
[`prettier.config.js`].find(fs.existsSync) || `${cfgDir}/prettier.config.js`
|
|
18
|
+
const prettierConfigPath = [`prettier.config.js`].find(fs.existsSync)
|
|
24
19
|
|
|
25
|
-
const stylelintConfigPath =
|
|
26
|
-
[`stylelint.config.js`].find(fs.existsSync) || `${cfgDir}/stylelint.config.js`
|
|
20
|
+
const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
|
|
27
21
|
|
|
28
22
|
// this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
|
|
29
23
|
// const tsconfigPathRoot = ['tsconfig.base.json'].find(p => fs.existsSync(p)) || 'tsconfig.json'
|
|
30
24
|
// const tsconfigPathRoot = 'tsconfig.json'
|
|
31
25
|
|
|
32
|
-
const eslintConfigPathRoot =
|
|
33
|
-
['.eslintrc.js'].find(p => fs.existsSync(p)) || `${cfgDir}/eslint.config.js`
|
|
26
|
+
const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
|
|
34
27
|
|
|
35
|
-
const prettierCmd = `prettier --write --config ${prettierConfigPath}`
|
|
28
|
+
const prettierCmd = !!prettierConfigPath && `prettier --write --config ${prettierConfigPath}`
|
|
36
29
|
const eslintCmd = `eslint --fix`
|
|
37
30
|
|
|
38
31
|
const stylelintExists =
|
|
32
|
+
!!stylelintConfigPath &&
|
|
39
33
|
fs.existsSync('node_modules/stylelint') &&
|
|
40
34
|
fs.existsSync('node_modules/stylelint-config-standard-scss')
|
|
41
35
|
const stylelintCmd = stylelintExists ? `stylelint --fix --config ${stylelintConfigPath}` : undefined
|
|
42
36
|
|
|
37
|
+
if (!eslintConfigPathRoot) {
|
|
38
|
+
console.log('eslint is skipped, because ./eslint.config.js is not present')
|
|
39
|
+
}
|
|
40
|
+
if (!prettierCmd) {
|
|
41
|
+
console.log('prettier is skipped, because ./prettier.config.js is not present')
|
|
42
|
+
}
|
|
43
|
+
if (!stylelintCmd) {
|
|
44
|
+
console.log(
|
|
45
|
+
'stylelint is skipped, because ./stylelint.config.js is not present, or stylelint and/or stylelint-config-standard-scss are not installed',
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
const linters = {
|
|
44
50
|
// *.{ts,tsx,vue} files: eslint, prettier
|
|
45
51
|
'./src/**/*.{ts,tsx,vue}': match => {
|
|
46
|
-
const filesList =
|
|
52
|
+
const filesList = getFilesList(match)
|
|
47
53
|
if (!filesList) return []
|
|
48
|
-
return [`${eslintCmd} --config ${eslintConfigPathRoot}`, prettierCmd]
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
return [eslintConfigPathRoot && `${eslintCmd} --config ${eslintConfigPathRoot}`, prettierCmd]
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.map(s => `${s} ${filesList}`)
|
|
51
57
|
},
|
|
52
58
|
|
|
53
59
|
// For all other files we run only Prettier (because e.g eslint screws *.scss files)
|
|
60
|
+
// todo: this should be no longer needed when flat eslint config is default and it has global ignore of scss files
|
|
54
61
|
[`./{${prettierDirs}}/**/*.{${prettierExtensionsExclusive}}`]: match => {
|
|
55
|
-
const filesList =
|
|
56
|
-
if (!filesList) return []
|
|
62
|
+
const filesList = getFilesList(match)
|
|
63
|
+
if (!filesList || !prettierCmd) return []
|
|
57
64
|
return [prettierCmd].map(s => `${s} ${filesList}`)
|
|
58
65
|
},
|
|
59
66
|
|
|
@@ -69,20 +76,20 @@ const linters = {
|
|
|
69
76
|
|
|
70
77
|
// Files for Stylelint + Prettier
|
|
71
78
|
[`./{${prettierDirs}}/**/*.{${stylelintExtensions}}`]: match => {
|
|
72
|
-
const filesList =
|
|
79
|
+
const filesList = getFilesList(match)
|
|
73
80
|
if (!filesList) return []
|
|
74
81
|
return [stylelintCmd, prettierCmd].filter(Boolean).map(s => `${s} ${filesList}`)
|
|
75
82
|
},
|
|
76
83
|
|
|
77
84
|
// Files in root dir
|
|
78
85
|
[`./*.{${prettierExtensionsAll}}`]: match => {
|
|
79
|
-
const filesList =
|
|
80
|
-
if (!filesList) return []
|
|
86
|
+
const filesList = getFilesList(match)
|
|
87
|
+
if (!filesList || !prettierCmd) return []
|
|
81
88
|
return [prettierCmd].map(s => `${s} ${filesList}`)
|
|
82
89
|
},
|
|
83
90
|
|
|
84
91
|
'**/*.{kt,kts}': match => {
|
|
85
|
-
const filesList =
|
|
92
|
+
const filesList = getFilesList(match)
|
|
86
93
|
if (!filesList) return []
|
|
87
94
|
const dir = './node_modules/@naturalcycles/ktlint'
|
|
88
95
|
|
|
@@ -111,61 +118,73 @@ const linters = {
|
|
|
111
118
|
|
|
112
119
|
// /scripts are separate, cause they require separate tsconfig.json
|
|
113
120
|
if (fs.existsSync(`./scripts`)) {
|
|
114
|
-
const eslintConfigPathScripts =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p =>
|
|
122
|
+
fs.existsSync(p),
|
|
123
|
+
)
|
|
118
124
|
Object.assign(linters, {
|
|
119
125
|
// eslint, Prettier
|
|
120
126
|
'./scripts/**/*.{ts,tsx}': match => {
|
|
121
|
-
const filesList =
|
|
127
|
+
const filesList = getFilesList(match)
|
|
122
128
|
if (!filesList) return []
|
|
123
129
|
return [
|
|
124
|
-
|
|
130
|
+
eslintConfigPathScripts &&
|
|
131
|
+
`${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json`,
|
|
125
132
|
prettierCmd,
|
|
126
|
-
]
|
|
133
|
+
]
|
|
134
|
+
.filter(Boolean)
|
|
135
|
+
.map(s => `${s} ${filesList}`)
|
|
127
136
|
},
|
|
128
137
|
})
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
// /e2e
|
|
132
141
|
if (fs.existsSync(`./e2e`)) {
|
|
133
|
-
const eslintConfigPathE2e =
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p =>
|
|
143
|
+
fs.existsSync(p),
|
|
144
|
+
)
|
|
136
145
|
|
|
137
146
|
Object.assign(linters, {
|
|
138
147
|
// eslint, Prettier
|
|
139
148
|
'./e2e/**/*.{ts,tsx}': match => {
|
|
140
|
-
const filesList =
|
|
149
|
+
const filesList = getFilesList(match)
|
|
141
150
|
if (!filesList) return []
|
|
142
151
|
return [
|
|
143
|
-
|
|
152
|
+
eslintConfigPathE2e &&
|
|
153
|
+
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json`,
|
|
144
154
|
prettierCmd,
|
|
145
|
-
]
|
|
155
|
+
]
|
|
156
|
+
.filter(Boolean)
|
|
157
|
+
.map(s => `${s} ${filesList}`)
|
|
146
158
|
},
|
|
147
159
|
})
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
// /playwright
|
|
151
163
|
if (fs.existsSync(`./playwright`)) {
|
|
152
|
-
const eslintConfigPathE2e =
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
const eslintConfigPathE2e = ['./playwright/eslint.config.js', './eslint.config.js'].find(p =>
|
|
165
|
+
fs.existsSync(p),
|
|
166
|
+
)
|
|
155
167
|
|
|
156
168
|
Object.assign(linters, {
|
|
157
169
|
// eslint, Prettier
|
|
158
170
|
'./playwright/**/*.{ts,tsx}': match => {
|
|
159
|
-
const filesList =
|
|
171
|
+
const filesList = getFilesList(match)
|
|
160
172
|
if (!filesList) return []
|
|
161
173
|
return [
|
|
162
|
-
|
|
174
|
+
eslintConfigPathE2e &&
|
|
175
|
+
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./playwright/tsconfig.json`,
|
|
163
176
|
prettierCmd,
|
|
164
|
-
]
|
|
177
|
+
]
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.map(s => `${s} ${filesList}`)
|
|
165
180
|
},
|
|
166
181
|
})
|
|
167
182
|
}
|
|
168
183
|
|
|
184
|
+
function getFilesList(match) {
|
|
185
|
+
return micromatch.not(match, lintExclude).join(' ')
|
|
186
|
+
}
|
|
187
|
+
|
|
169
188
|
function canRunBinary(name) {
|
|
170
189
|
try {
|
|
171
190
|
execSync(`which ${name}`)
|
|
@@ -4,14 +4,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
|
-
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
8
7
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
9
8
|
// const cwd = process.cwd()
|
|
10
9
|
const localConfig = `./lint-staged.config.js`;
|
|
11
|
-
const sharedConfig = `${
|
|
12
|
-
const config = node_fs_1.default.existsSync(localConfig) ? localConfig :
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
// const sharedConfig = `${cfgDir}/lint-staged.config.js`
|
|
11
|
+
const config = node_fs_1.default.existsSync(localConfig) ? localConfig : undefined;
|
|
12
|
+
if (!config) {
|
|
13
|
+
console.log(`lint-staged is skipped, because no ${localConfig} is found`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
15
16
|
// await execWithArgs(`lint-staged`, [`--config`, config])
|
|
16
17
|
// const lintStaged = require('lint-staged')
|
|
17
18
|
// lint-staged is ESM since 12.0
|
|
@@ -6,7 +6,6 @@ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
|
6
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
9
|
-
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
10
9
|
const lint_util_1 = require("../util/lint.util");
|
|
11
10
|
/**
|
|
12
11
|
* Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
|
|
@@ -24,13 +23,10 @@ async function eslintAllCommand() {
|
|
|
24
23
|
},
|
|
25
24
|
}).argv;
|
|
26
25
|
const extensions = ext.split(',');
|
|
27
|
-
const eslintConfigPathRoot = ['
|
|
28
|
-
const eslintConfigPathScripts = ['./scripts
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
`${paths_cnst_1.cfgDir}/eslint.config.js`;
|
|
32
|
-
const eslintConfigPathPlaywright = ['./playwright/.eslintrc.js', './.eslintrc.js'].find(p => node_fs_1.default.existsSync(p)) ||
|
|
33
|
-
`${paths_cnst_1.cfgDir}/eslint.config.js`;
|
|
26
|
+
const eslintConfigPathRoot = ['./eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
27
|
+
const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
28
|
+
const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
29
|
+
const eslintConfigPathPlaywright = ['./playwright/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
34
30
|
// const tsconfigPath = getTSConfigPath()
|
|
35
31
|
const tsconfigPathScripts = (0, lint_util_1.getTSConfigPathScripts)();
|
|
36
32
|
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
@@ -44,7 +40,7 @@ async function eslintAllCommand() {
|
|
|
44
40
|
(0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix),
|
|
45
41
|
// /e2e
|
|
46
42
|
(0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix),
|
|
47
|
-
// /playwright
|
|
43
|
+
// /playwright // todo: remove after migration to e2e folder is completed
|
|
48
44
|
(0, lint_util_1.runESLintAsync)(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix),
|
|
49
45
|
]);
|
|
50
46
|
}
|
package/dist/util/jest.util.d.ts
CHANGED
package/dist/util/jest.util.js
CHANGED
|
@@ -13,7 +13,7 @@ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
|
13
13
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
14
14
|
const test_util_1 = require("./test.util");
|
|
15
15
|
function getJestConfigPath() {
|
|
16
|
-
return node_fs_1.default.existsSync(`./jest.config.js`) ? './jest.config.js' :
|
|
16
|
+
return node_fs_1.default.existsSync(`./jest.config.js`) ? './jest.config.js' : undefined;
|
|
17
17
|
}
|
|
18
18
|
function getJestIntegrationConfigPath() {
|
|
19
19
|
return node_fs_1.default.existsSync(`./jest.integration-test.config.js`)
|
|
@@ -57,6 +57,10 @@ function runJest(opt = {}) {
|
|
|
57
57
|
else {
|
|
58
58
|
jestConfig = getJestConfigPath();
|
|
59
59
|
}
|
|
60
|
+
if (!jestConfig) {
|
|
61
|
+
console.log((0, nodejs_lib_1.dimGrey)(`./jest.config.js not found, skipping jest`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
60
64
|
// Allow to override --maxWorkers
|
|
61
65
|
let maxWorkers = processArgs.find(a => a.startsWith('--maxWorkers'));
|
|
62
66
|
const args = [
|
package/dist/util/lint.util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function getTSConfigPath(): string;
|
|
2
2
|
export declare function getTSConfigPathScripts(): string;
|
|
3
|
-
export declare function runESLint(dir: string, eslintConfigPath: string, tsconfigPath?: string, extensions?: string[], fix?: boolean): void;
|
|
4
|
-
export declare function runESLintAsync(dir: string, eslintConfigPath: string, tsconfigPath?: string, extensions?: string[], fix?: boolean): Promise<void>;
|
|
3
|
+
export declare function runESLint(dir: string, eslintConfigPath: string | undefined, tsconfigPath?: string, extensions?: string[], fix?: boolean): void;
|
|
4
|
+
export declare function runESLintAsync(dir: string, eslintConfigPath: string | undefined, tsconfigPath?: string, extensions?: string[], fix?: boolean): Promise<void>;
|
package/dist/util/lint.util.js
CHANGED
|
@@ -8,7 +8,6 @@ const tslib_1 = require("tslib");
|
|
|
8
8
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
9
9
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
10
10
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
11
|
-
const ESLINT_USE_FLAT_CONFIG = 'false';
|
|
12
11
|
function getTSConfigPath() {
|
|
13
12
|
// this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
|
|
14
13
|
// return [`./tsconfig.base.json`].find(p => fs.existsSync(p)) || `./tsconfig.json`
|
|
@@ -18,22 +17,14 @@ function getTSConfigPathScripts() {
|
|
|
18
17
|
return [`./scripts/tsconfig.json`].find(p => node_fs_1.default.existsSync(p)) || `${paths_cnst_1.scriptsDir}/tsconfig.json`;
|
|
19
18
|
}
|
|
20
19
|
function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
21
|
-
if (!node_fs_1.default.existsSync(dir))
|
|
20
|
+
if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
|
|
22
21
|
return; // faster to bail-out like this
|
|
23
|
-
(0, nodejs_lib_1.execVoidCommandSync)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix)
|
|
24
|
-
env: {
|
|
25
|
-
ESLINT_USE_FLAT_CONFIG,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
22
|
+
(0, nodejs_lib_1.execVoidCommandSync)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
|
|
28
23
|
}
|
|
29
24
|
async function runESLintAsync(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
30
|
-
if (!node_fs_1.default.existsSync(dir))
|
|
25
|
+
if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
|
|
31
26
|
return; // faster to bail-out like this
|
|
32
|
-
await (0, nodejs_lib_1.execVoidCommand)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix)
|
|
33
|
-
env: {
|
|
34
|
-
ESLINT_USE_FLAT_CONFIG,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
27
|
+
await (0, nodejs_lib_1.execVoidCommand)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
|
|
37
28
|
}
|
|
38
29
|
function getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
39
30
|
return [
|
|
@@ -42,7 +33,7 @@ function getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions = ['ts',
|
|
|
42
33
|
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
43
34
|
...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
|
|
44
35
|
`--no-error-on-unmatched-pattern`,
|
|
45
|
-
`--report-unused-disable-directives`,
|
|
36
|
+
`--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
|
|
46
37
|
fix ? `--fix` : '',
|
|
47
38
|
].filter(Boolean);
|
|
48
39
|
}
|
|
@@ -4,7 +4,6 @@ exports.runPrettier = runPrettier;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
6
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
|
-
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
8
7
|
const { prettierDirs, prettierExtensionsAll, lintExclude } = require('../../cfg/_cnst');
|
|
9
8
|
const prettierPaths = [
|
|
10
9
|
// Everything inside these folders
|
|
@@ -15,8 +14,9 @@ const prettierPaths = [
|
|
|
15
14
|
...lintExclude.map((s) => `!${s}`),
|
|
16
15
|
];
|
|
17
16
|
function runPrettier() {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const prettierConfigPath = [`./prettier.config.js`].find(f => node_fs_1.default.existsSync(f));
|
|
18
|
+
if (!prettierConfigPath)
|
|
19
|
+
return;
|
|
20
20
|
// prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
|
|
21
21
|
const args = [`--write`, `--log-level=warn`, `--config`, prettierConfigPath, ...prettierPaths];
|
|
22
22
|
(0, nodejs_lib_1.execVoidCommandSync)('prettier', args);
|
|
@@ -6,7 +6,6 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
9
|
-
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
10
9
|
const { prettierDirs, stylelintExtensions, lintExclude } = require('../../cfg/_cnst');
|
|
11
10
|
exports.stylelintPaths = [
|
|
12
11
|
// Everything inside these folders
|
|
@@ -21,7 +20,9 @@ function stylelintAll() {
|
|
|
21
20
|
default: true,
|
|
22
21
|
},
|
|
23
22
|
}).argv;
|
|
24
|
-
const config = [`./stylelint.config.js
|
|
23
|
+
const config = [`./stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
|
|
24
|
+
if (!config)
|
|
25
|
+
return;
|
|
25
26
|
const args = [
|
|
26
27
|
fix ? `--fix` : '',
|
|
27
28
|
`--allow-empty-input`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"tsn-debug": "tsn testScript.ts",
|
|
@@ -31,14 +31,13 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@commitlint/cli": "^19.0.0",
|
|
33
33
|
"@commitlint/config-conventional": "^19.0.0",
|
|
34
|
+
"@eslint/js": "^9.7.0",
|
|
34
35
|
"@naturalcycles/cli": "^1.0.0",
|
|
35
36
|
"@naturalcycles/js-lib": "^14.0.0",
|
|
36
37
|
"@naturalcycles/nodejs-lib": "^13.0.1",
|
|
37
38
|
"@types/jest": "^29.0.0",
|
|
38
39
|
"@types/node": "^20.1.0",
|
|
39
40
|
"@types/yargs": "^16.0.0",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
41
|
-
"@typescript-eslint/parser": "^7.0.1",
|
|
42
41
|
"eslint": "^9.0.0",
|
|
43
42
|
"eslint-config-prettier": "^9.0.0",
|
|
44
43
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -49,6 +48,7 @@
|
|
|
49
48
|
"eslint-plugin-unused-imports": "^4.0.0",
|
|
50
49
|
"eslint-plugin-vue": "^9.0.0",
|
|
51
50
|
"expect-type": "^0.19.0",
|
|
51
|
+
"globals": "^15.8.0",
|
|
52
52
|
"husky": "^9.0.2",
|
|
53
53
|
"jest-junit": "^16.0.0",
|
|
54
54
|
"lint-staged": "^15.0.1",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"timekeeper": "^2.2.0",
|
|
59
59
|
"ts-jest": "^29.0.0",
|
|
60
60
|
"typescript": "^5.0.2",
|
|
61
|
+
"typescript-eslint": "^7.16.1",
|
|
61
62
|
"yargs": "^17.0.0"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -24,7 +24,7 @@ This unlocks all commands listed below, e.g:
|
|
|
24
24
|
|
|
25
25
|
By default, it uses default configs for Prettier, ESLint, Stylelint, that are included in this
|
|
26
26
|
package (for convenience). You can override them by putting your own `prettier.config.js`,
|
|
27
|
-
|
|
27
|
+
`eslint.config.js`, `stylelint.config.json` in the root folder of your project.
|
|
28
28
|
|
|
29
29
|
## Conventions
|
|
30
30
|
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @naturalcycles/dev-lib/cfg/eslint-vue2.config.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
overrides: [
|
|
7
|
-
{
|
|
8
|
-
files: ['*.vue'],
|
|
9
|
-
extends: [
|
|
10
|
-
'eslint:recommended',
|
|
11
|
-
'plugin:@typescript-eslint/recommended-type-checked',
|
|
12
|
-
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
13
|
-
'plugin:unicorn/recommended',
|
|
14
|
-
'plugin:vue/recommended',
|
|
15
|
-
'./eslint-rules.js',
|
|
16
|
-
'./eslint-vue-rules.js',
|
|
17
|
-
'prettier', // must go last
|
|
18
|
-
],
|
|
19
|
-
env: {
|
|
20
|
-
browser: true,
|
|
21
|
-
},
|
|
22
|
-
parser: 'vue-eslint-parser',
|
|
23
|
-
parserOptions: {
|
|
24
|
-
parser: '@typescript-eslint/parser',
|
|
25
|
-
project: ['tsconfig.json'],
|
|
26
|
-
sourceType: 'module',
|
|
27
|
-
ecmaVersion: 'latest',
|
|
28
|
-
extraFileExtensions: ['.vue'],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @naturalcycles/dev-lib/cfg/eslint-vue3.config.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
overrides: [
|
|
7
|
-
{
|
|
8
|
-
files: ['*.vue'],
|
|
9
|
-
extends: [
|
|
10
|
-
'eslint:recommended',
|
|
11
|
-
'plugin:@typescript-eslint/recommended-type-checked',
|
|
12
|
-
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
13
|
-
'plugin:unicorn/recommended',
|
|
14
|
-
'plugin:vue/vue3-recommended',
|
|
15
|
-
'./eslint-rules.js',
|
|
16
|
-
'./eslint-vue-rules.js',
|
|
17
|
-
'prettier', // must go last
|
|
18
|
-
],
|
|
19
|
-
env: {
|
|
20
|
-
browser: true,
|
|
21
|
-
},
|
|
22
|
-
parser: 'vue-eslint-parser',
|
|
23
|
-
parserOptions: {
|
|
24
|
-
parser: '@typescript-eslint/parser',
|
|
25
|
-
project: ['tsconfig.json'],
|
|
26
|
-
sourceType: 'module',
|
|
27
|
-
ecmaVersion: 'latest',
|
|
28
|
-
extraFileExtensions: ['.vue'],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
}
|
package/cfg/init/.eslintrc.js
DELETED