aberlaas-lint 2.20.2 → 2.22.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/configs/eslint/docs.js +6 -0
- package/configs/eslint/index.js +15 -0
- package/configs/{eslint.js → eslint/js.js} +0 -80
- package/configs/eslint/json.js +129 -0
- package/configs/eslint/react.js +23 -0
- package/configs/eslint/scripts.js +7 -0
- package/configs/eslint/vitest.js +55 -0
- package/lib/helpers/eslintRun.js +68 -0
- package/lib/js.js +6 -38
- package/lib/json.js +26 -28
- package/lib/main.js +24 -12
- package/package.json +24 -20
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import configDocs from './docs.js';
|
|
2
|
+
import configJs from './js.js';
|
|
3
|
+
import configJson from './json.js';
|
|
4
|
+
import configReact from './react.js';
|
|
5
|
+
import configScripts from './scripts.js';
|
|
6
|
+
import configVitest from './vitest.js';
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
...configJs,
|
|
10
|
+
...configVitest,
|
|
11
|
+
...configReact,
|
|
12
|
+
...configJson,
|
|
13
|
+
...configScripts,
|
|
14
|
+
...configDocs,
|
|
15
|
+
];
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import js from '@eslint/js';
|
|
2
|
-
// @vitest/plugins requires @typescript-eslint/utils and typescripts as deps
|
|
3
|
-
// See: https://github.com/vitest-dev/eslint-plugin-vitest/issues/543
|
|
4
|
-
import pluginVitest from '@vitest/eslint-plugin';
|
|
5
2
|
import { nodeVersion } from 'aberlaas-versions';
|
|
6
3
|
import pluginImport from 'eslint-plugin-import';
|
|
7
4
|
import pluginJsdoc from 'eslint-plugin-jsdoc';
|
|
8
5
|
import pluginN from 'eslint-plugin-n';
|
|
9
6
|
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
10
|
-
import pluginReact from 'eslint-plugin-react';
|
|
11
7
|
import globals from 'globals';
|
|
12
8
|
|
|
13
9
|
export default [
|
|
@@ -207,80 +203,4 @@ export default [
|
|
|
207
203
|
},
|
|
208
204
|
},
|
|
209
205
|
},
|
|
210
|
-
{
|
|
211
|
-
name: 'aberlaas/vitest',
|
|
212
|
-
files: ['**/__tests__/**/*.{js,ts}'],
|
|
213
|
-
languageOptions: {
|
|
214
|
-
globals: {
|
|
215
|
-
afterAll: true,
|
|
216
|
-
afterEach: true,
|
|
217
|
-
beforeAll: true,
|
|
218
|
-
beforeEach: true,
|
|
219
|
-
describe: true,
|
|
220
|
-
expect: true,
|
|
221
|
-
it: true,
|
|
222
|
-
test: true,
|
|
223
|
-
vitest: true,
|
|
224
|
-
vi: true,
|
|
225
|
-
captureOutput: false,
|
|
226
|
-
dedent: false,
|
|
227
|
-
fdescribe: false,
|
|
228
|
-
fit: false,
|
|
229
|
-
testName: false,
|
|
230
|
-
xdescribe: false,
|
|
231
|
-
xit: false,
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
plugins: {
|
|
235
|
-
vitest: pluginVitest,
|
|
236
|
-
},
|
|
237
|
-
rules: {
|
|
238
|
-
...pluginVitest.configs.recommended.rules,
|
|
239
|
-
'no-restricted-globals': [
|
|
240
|
-
'error',
|
|
241
|
-
{ name: 'fit', message: 'No focused test' },
|
|
242
|
-
{ name: 'fdescribe', message: 'No focused tests' },
|
|
243
|
-
{ name: 'xit', message: 'No skipped test' },
|
|
244
|
-
{ name: 'xdescribe', message: 'No skipped tests' },
|
|
245
|
-
],
|
|
246
|
-
// In tests, we like to have the variable 'current' hold the object
|
|
247
|
-
// under test. The import/no-named-as-default-member would have warned
|
|
248
|
-
// us about using current.foo rather than foo directly, so we disable
|
|
249
|
-
// it.
|
|
250
|
-
'import/no-named-as-default-member': ['off'],
|
|
251
|
-
'vitest/consistent-test-it': ['warn', { fn: 'it' }],
|
|
252
|
-
// Disabling vitest/no-identical-title
|
|
253
|
-
// It can make eslint crash when used with fit/xit/fdescribe/xdescribe
|
|
254
|
-
// See: https://github.com/veritem/eslint-plugin-vitest/issues/310
|
|
255
|
-
'vitest/no-identical-title': ['off'],
|
|
256
|
-
'vitest/prefer-to-contain': ['error'],
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
name: 'aberlaas/react',
|
|
261
|
-
files: ['**/*.{jsx,tsx}'],
|
|
262
|
-
plugins: {
|
|
263
|
-
react: pluginReact,
|
|
264
|
-
},
|
|
265
|
-
languageOptions: {
|
|
266
|
-
parserOptions: {
|
|
267
|
-
ecmaFeatures: {
|
|
268
|
-
jsx: true,
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
rules: {
|
|
273
|
-
'react/jsx-uses-react': ['error'],
|
|
274
|
-
'react/jsx-uses-vars': ['error'],
|
|
275
|
-
'import/extensions': ['error', 'always', { ignorePackages: true }],
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
name: 'aberlaas/scripts',
|
|
280
|
-
files: ['**/scripts/**/*.{js,ts}'],
|
|
281
|
-
rules: { 'no-process-exit': ['off'] },
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
ignores: ['**/docs/**/*.js'],
|
|
285
|
-
},
|
|
286
206
|
];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import pluginJson from '@eslint/json';
|
|
2
|
+
import packageJson from 'eslint-plugin-package-json';
|
|
3
|
+
import jsoncParser from 'jsonc-eslint-parser';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
name: 'aberlaas/json',
|
|
8
|
+
files: ['**/*.json'],
|
|
9
|
+
ignores: ['**/package.json'],
|
|
10
|
+
plugins: {
|
|
11
|
+
json: pluginJson,
|
|
12
|
+
},
|
|
13
|
+
language: 'json/json',
|
|
14
|
+
rules: {
|
|
15
|
+
'json/no-duplicate-keys': ['error'],
|
|
16
|
+
'json/no-empty-keys': ['error'],
|
|
17
|
+
'json/no-unnormalized-keys': ['error'],
|
|
18
|
+
'json/no-unsafe-values': ['error'],
|
|
19
|
+
'json/top-level-interop': ['error'],
|
|
20
|
+
'json/sort-keys': ['off'],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'aberlaas/packageJson',
|
|
25
|
+
files: ['**/package.json'],
|
|
26
|
+
plugins: {
|
|
27
|
+
'package-json': packageJson,
|
|
28
|
+
},
|
|
29
|
+
languageOptions: {
|
|
30
|
+
parser: jsoncParser,
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
'package-json/bin-name-casing': ['error'],
|
|
34
|
+
'package-json/exports-subpaths-style': ['error'],
|
|
35
|
+
'package-json/no-empty-fields': ['error'],
|
|
36
|
+
'package-json/no-redundant-files': ['error'],
|
|
37
|
+
'package-json/no-redundant-publishConfig': ['error'],
|
|
38
|
+
'package-json/order-properties': [
|
|
39
|
+
'error',
|
|
40
|
+
{
|
|
41
|
+
// See: https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/docs/rules/order-properties.md
|
|
42
|
+
order: [
|
|
43
|
+
// Name
|
|
44
|
+
'name',
|
|
45
|
+
'version',
|
|
46
|
+
// Dev info
|
|
47
|
+
'private',
|
|
48
|
+
'type',
|
|
49
|
+
'workspaces',
|
|
50
|
+
// Metadata
|
|
51
|
+
'description',
|
|
52
|
+
'author',
|
|
53
|
+
'homepage',
|
|
54
|
+
'keywords',
|
|
55
|
+
'repository',
|
|
56
|
+
// Compatibility
|
|
57
|
+
'sideEffects',
|
|
58
|
+
'license',
|
|
59
|
+
'engines',
|
|
60
|
+
'packageManager',
|
|
61
|
+
// Exports
|
|
62
|
+
'files',
|
|
63
|
+
'exports',
|
|
64
|
+
'main',
|
|
65
|
+
'bin',
|
|
66
|
+
// Dependencies
|
|
67
|
+
'devDependencies',
|
|
68
|
+
'dependencies',
|
|
69
|
+
'peerDependencies',
|
|
70
|
+
// Scripts
|
|
71
|
+
'scripts',
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
'package-json/repository-shorthand': ['error'],
|
|
76
|
+
'package-json/require-description': ['error'],
|
|
77
|
+
'package-json/require-license': ['error'],
|
|
78
|
+
'package-json/require-name': ['error'],
|
|
79
|
+
'package-json/require-type': ['error'],
|
|
80
|
+
'package-json/require-version': ['error'],
|
|
81
|
+
'package-json/scripts-name-casing': ['error'],
|
|
82
|
+
'package-json/sort-collections': ['error'],
|
|
83
|
+
'package-json/specify-peers-locally': ['error'],
|
|
84
|
+
'package-json/unique-dependencies': ['error'],
|
|
85
|
+
'package-json/valid-author': ['error'],
|
|
86
|
+
'package-json/valid-bin': ['error'],
|
|
87
|
+
'package-json/valid-bundleDependencies': ['error'],
|
|
88
|
+
'package-json/valid-config': ['error'],
|
|
89
|
+
'package-json/valid-contributors': ['error'],
|
|
90
|
+
'package-json/valid-cpu': ['error'],
|
|
91
|
+
'package-json/valid-dependencies': ['error'],
|
|
92
|
+
'package-json/valid-description': ['error'],
|
|
93
|
+
'package-json/valid-devDependencies': ['error'],
|
|
94
|
+
'package-json/valid-directories': ['error'],
|
|
95
|
+
'package-json/valid-engines': ['error'],
|
|
96
|
+
'package-json/valid-exports': ['error'],
|
|
97
|
+
'package-json/valid-files': ['error'],
|
|
98
|
+
'package-json/valid-homepage': ['error'],
|
|
99
|
+
'package-json/valid-keywords': ['error'],
|
|
100
|
+
'package-json/valid-license': ['error'],
|
|
101
|
+
'package-json/valid-main': ['error'],
|
|
102
|
+
'package-json/valid-man': ['error'],
|
|
103
|
+
'package-json/valid-module': ['error'],
|
|
104
|
+
'package-json/valid-name': ['error'],
|
|
105
|
+
'package-json/valid-optionalDependencies': ['error'],
|
|
106
|
+
'package-json/valid-os': ['error'],
|
|
107
|
+
'package-json/valid-peerDependencies': ['error'],
|
|
108
|
+
'package-json/valid-private': ['error'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'aberlaas/packageJsonPublishable',
|
|
113
|
+
files: ['**/lib/package.json', '**/modules/*/package.json'],
|
|
114
|
+
ignores: ['**/docs/package.json'],
|
|
115
|
+
plugins: {
|
|
116
|
+
'package-json': packageJson,
|
|
117
|
+
},
|
|
118
|
+
languageOptions: {
|
|
119
|
+
parser: jsoncParser,
|
|
120
|
+
},
|
|
121
|
+
rules: {
|
|
122
|
+
'package-json/require-attribution': ['error'],
|
|
123
|
+
'package-json/require-exports': ['error'],
|
|
124
|
+
'package-json/require-files': ['error'],
|
|
125
|
+
'package-json/require-repository': ['error'],
|
|
126
|
+
'package-json/require-sideEffects': ['error'],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import pluginReact from 'eslint-plugin-react';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
name: 'aberlaas/react',
|
|
6
|
+
files: ['**/*.{jsx,tsx}'],
|
|
7
|
+
plugins: {
|
|
8
|
+
react: pluginReact,
|
|
9
|
+
},
|
|
10
|
+
languageOptions: {
|
|
11
|
+
parserOptions: {
|
|
12
|
+
ecmaFeatures: {
|
|
13
|
+
jsx: true,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
rules: {
|
|
18
|
+
'react/jsx-uses-react': ['error'],
|
|
19
|
+
'react/jsx-uses-vars': ['error'],
|
|
20
|
+
'import/extensions': ['error', 'always', { ignorePackages: true }],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @vitest/plugins requires @typescript-eslint/utils and typescripts as deps
|
|
2
|
+
// See: https://github.com/vitest-dev/eslint-plugin-vitest/issues/543
|
|
3
|
+
import pluginVitest from '@vitest/eslint-plugin';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
name: 'aberlaas/vitest',
|
|
8
|
+
files: ['**/__tests__/**/*.{js,ts}'],
|
|
9
|
+
languageOptions: {
|
|
10
|
+
globals: {
|
|
11
|
+
afterAll: true,
|
|
12
|
+
afterEach: true,
|
|
13
|
+
beforeAll: true,
|
|
14
|
+
beforeEach: true,
|
|
15
|
+
describe: true,
|
|
16
|
+
expect: true,
|
|
17
|
+
it: true,
|
|
18
|
+
test: true,
|
|
19
|
+
vitest: true,
|
|
20
|
+
vi: true,
|
|
21
|
+
captureOutput: false,
|
|
22
|
+
dedent: false,
|
|
23
|
+
fdescribe: false,
|
|
24
|
+
fit: false,
|
|
25
|
+
testName: false,
|
|
26
|
+
xdescribe: false,
|
|
27
|
+
xit: false,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
plugins: {
|
|
31
|
+
vitest: pluginVitest,
|
|
32
|
+
},
|
|
33
|
+
rules: {
|
|
34
|
+
...pluginVitest.configs.recommended.rules,
|
|
35
|
+
'no-restricted-globals': [
|
|
36
|
+
'error',
|
|
37
|
+
{ name: 'fit', message: 'No focused test' },
|
|
38
|
+
{ name: 'fdescribe', message: 'No focused tests' },
|
|
39
|
+
{ name: 'xit', message: 'No skipped test' },
|
|
40
|
+
{ name: 'xdescribe', message: 'No skipped tests' },
|
|
41
|
+
],
|
|
42
|
+
// In tests, we like to have the variable 'current' hold the object
|
|
43
|
+
// under test. The import/no-named-as-default-member would have warned
|
|
44
|
+
// us about using current.foo rather than foo directly, so we disable
|
|
45
|
+
// it.
|
|
46
|
+
'import/no-named-as-default-member': ['off'],
|
|
47
|
+
'vitest/consistent-test-it': ['warn', { fn: 'it' }],
|
|
48
|
+
// Disabling vitest/no-identical-title
|
|
49
|
+
// It can make eslint crash when used with fit/xit/fdescribe/xdescribe
|
|
50
|
+
// See: https://github.com/veritem/eslint-plugin-vitest/issues/310
|
|
51
|
+
'vitest/no-identical-title': ['off'],
|
|
52
|
+
'vitest/prefer-to-contain': ['error'],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { _ } from 'golgoth';
|
|
2
|
+
import { firostError, run } from 'firost';
|
|
3
|
+
import { getConfig } from 'aberlaas-helper';
|
|
4
|
+
import { ESLint } from 'eslint';
|
|
5
|
+
import eslintConfig from '../../configs/eslint/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Lint all files and display results.
|
|
9
|
+
* @param {Array} files Files to lint
|
|
10
|
+
* @param {string} userConfigFile Custom config file to use
|
|
11
|
+
* @param {object} userOptions Options to pass to ESLint, including fix
|
|
12
|
+
* @returns {boolean} True on success
|
|
13
|
+
*/
|
|
14
|
+
export async function eslintRun(files, userConfigFile, userOptions = {}) {
|
|
15
|
+
// Files
|
|
16
|
+
if (_.isEmpty(files)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Config file
|
|
21
|
+
const config = await getConfig(
|
|
22
|
+
userConfigFile,
|
|
23
|
+
'eslint.config.js',
|
|
24
|
+
eslintConfig,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Options
|
|
28
|
+
const options = { fix: false, warnIgnored: false, ...userOptions };
|
|
29
|
+
|
|
30
|
+
// Run the actual lint
|
|
31
|
+
const eslint = new ESLint({
|
|
32
|
+
...options,
|
|
33
|
+
overrideConfigFile: true,
|
|
34
|
+
overrideConfig: config,
|
|
35
|
+
});
|
|
36
|
+
const results = await eslint.lintFiles(files);
|
|
37
|
+
|
|
38
|
+
// Fix
|
|
39
|
+
if (options.fix) {
|
|
40
|
+
await ESLint.outputFixes(results);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// All good, we can stop
|
|
44
|
+
const errorCount = _.chain(results).map('errorCount').sum().value();
|
|
45
|
+
if (errorCount == 0) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Format errors
|
|
50
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
51
|
+
const errorText = formatter.format(results);
|
|
52
|
+
throw firostError('ABERLAAS_LINT_ESLINT', errorText);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Autofix files in place
|
|
57
|
+
* @param {Array} userPatterns Patterns to narrow the search down
|
|
58
|
+
* @param {string} userConfigFile Custom config file to use
|
|
59
|
+
* @returns {boolean} True on success
|
|
60
|
+
*/
|
|
61
|
+
export async function fix(userPatterns, userConfigFile) {
|
|
62
|
+
return await run(userPatterns, userConfigFile, { fix: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default {
|
|
66
|
+
run,
|
|
67
|
+
fix,
|
|
68
|
+
};
|
package/lib/js.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { _ } from 'golgoth';
|
|
2
2
|
import { firostError } from 'firost';
|
|
3
|
-
import { findHostPackageFiles
|
|
4
|
-
import {
|
|
5
|
-
import eslintConfig from '../configs/eslint.js';
|
|
3
|
+
import { findHostPackageFiles } from 'aberlaas-helper';
|
|
4
|
+
import { eslintRun } from './helpers/eslintRun.js';
|
|
6
5
|
|
|
7
6
|
export let __;
|
|
8
7
|
|
|
@@ -14,45 +13,14 @@ export let __;
|
|
|
14
13
|
* @returns {boolean} True on success
|
|
15
14
|
*/
|
|
16
15
|
export async function run(userPatterns, userConfigFile, userOptions = {}) {
|
|
17
|
-
// Options
|
|
18
|
-
const options = { fix: false, warnIgnored: false, ...userOptions };
|
|
19
|
-
|
|
20
|
-
// Files to lint
|
|
21
16
|
const files = await __.getInputFiles(userPatterns);
|
|
22
|
-
if (_.isEmpty(files)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Config file
|
|
27
|
-
const config = await getConfig(
|
|
28
|
-
userConfigFile,
|
|
29
|
-
'eslint.config.js',
|
|
30
|
-
eslintConfig,
|
|
31
|
-
);
|
|
32
17
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
...options,
|
|
36
|
-
overrideConfigFile: true,
|
|
37
|
-
overrideConfig: config,
|
|
38
|
-
});
|
|
39
|
-
const results = await eslint.lintFiles(files);
|
|
40
|
-
|
|
41
|
-
// Fix
|
|
42
|
-
if (options.fix) {
|
|
43
|
-
await ESLint.outputFixes(results);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// All good, we can stop
|
|
47
|
-
const errorCount = _.chain(results).map('errorCount').sum().value();
|
|
48
|
-
if (errorCount == 0) {
|
|
18
|
+
try {
|
|
19
|
+
await eslintRun(files, userConfigFile, userOptions);
|
|
49
20
|
return true;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
throw firostError('ABERLAAS_LINT_JS', err.message);
|
|
50
23
|
}
|
|
51
|
-
|
|
52
|
-
// Format errors
|
|
53
|
-
const formatter = await eslint.loadFormatter('stylish');
|
|
54
|
-
const errorText = formatter.format(results);
|
|
55
|
-
throw firostError('ABERLAAS_LINT_JS', errorText);
|
|
56
24
|
}
|
|
57
25
|
|
|
58
26
|
/**
|
package/lib/json.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { _ } from 'golgoth';
|
|
2
|
+
import { firostError } from 'firost';
|
|
3
|
+
import { findHostPackageFiles } from 'aberlaas-helper';
|
|
4
|
+
import { eslintRun } from './helpers/eslintRun.js';
|
|
5
5
|
import { prettierFix } from './helpers/prettierFix.js';
|
|
6
6
|
|
|
7
7
|
export let __;
|
|
@@ -9,44 +9,42 @@ export let __;
|
|
|
9
9
|
/**
|
|
10
10
|
* Lint all files and display results.
|
|
11
11
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
12
|
+
* @param {string} userConfigFile Custom config file to use
|
|
13
|
+
* @param {object} userOptions Options to pass to ESLint, including fix
|
|
12
14
|
* @returns {boolean} True on success
|
|
13
15
|
*/
|
|
14
|
-
export async function run(userPatterns) {
|
|
16
|
+
export async function run(userPatterns, userConfigFile, userOptions = {}) {
|
|
15
17
|
const files = await __.getInputFiles(userPatterns);
|
|
16
|
-
if (_.isEmpty(files)) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let hasErrors = false;
|
|
21
|
-
const errorMessages = [];
|
|
22
|
-
await pMap(files, async (filepath) => {
|
|
23
|
-
try {
|
|
24
|
-
JSON.parse(await read(filepath));
|
|
25
|
-
} catch (error) {
|
|
26
|
-
hasErrors = true;
|
|
27
|
-
const relativePath = path.relative(hostGitRoot(), filepath);
|
|
28
|
-
errorMessages.push(`Invalid JSON: ${relativePath}`);
|
|
29
|
-
errorMessages.push(error.message);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
try {
|
|
20
|
+
await eslintRun(files, userConfigFile, userOptions);
|
|
21
|
+
return true;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw firostError('ABERLAAS_LINT_JSON', err.message);
|
|
35
24
|
}
|
|
36
|
-
return true;
|
|
37
25
|
}
|
|
38
26
|
|
|
39
27
|
/**
|
|
40
28
|
* Autofix files in place
|
|
41
29
|
* @param {Array} userPatterns Patterns to narrow the search down
|
|
30
|
+
* @param {string} userConfigFile Custom config file to use
|
|
42
31
|
* @returns {boolean} True on success
|
|
43
32
|
*/
|
|
44
|
-
export async function fix(userPatterns) {
|
|
33
|
+
export async function fix(userPatterns, userConfigFile) {
|
|
45
34
|
const files = await __.getInputFiles(userPatterns);
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
|
|
36
|
+
// Note: The @eslint/json plugin doesn't seem to support fixing the JSON and
|
|
37
|
+
// chokes on malformed JSON (like trailing commas).
|
|
38
|
+
// Prettier, on the other hand, can fix trailing commas.
|
|
39
|
+
// So we run both.
|
|
40
|
+
try {
|
|
41
|
+
// To fix most issues ESLint can't fix
|
|
42
|
+
await __.prettierFix(files);
|
|
43
|
+
// To warn about leftover issues
|
|
44
|
+
return await run(userPatterns, userConfigFile, { fix: true });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
throw firostError('ABERLAAS_LINT_JSON_FIX', err.message);
|
|
48
47
|
}
|
|
49
|
-
await __.prettierFix(files);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
__ = {
|
package/lib/main.js
CHANGED
|
@@ -12,24 +12,36 @@ export async function run(cliArgs = {}) {
|
|
|
12
12
|
const allTypesKeys = _.keys(__.linters);
|
|
13
13
|
const userTypes = _.intersection(_.keys(cliArgs), allTypesKeys);
|
|
14
14
|
const typesToLint = _.isEmpty(userTypes) ? allTypesKeys : userTypes;
|
|
15
|
+
const shouldFailFast = cliArgs.failFast;
|
|
16
|
+
const errors = [];
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
await pMap(
|
|
19
|
+
typesToLint,
|
|
20
|
+
async (type) => {
|
|
21
|
+
const methodName = cliArgs.fix ? 'fix' : 'run';
|
|
20
22
|
const linter = await __.getLinter(type);
|
|
21
|
-
|
|
22
23
|
const configFile = _.get(cliArgs, `config.${type}`);
|
|
23
24
|
const userPatterns = _.get(cliArgs, '_');
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
try {
|
|
27
|
+
await linter[methodName](userPatterns, configFile);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
errors.push(error);
|
|
30
|
+
|
|
31
|
+
if (shouldFailFast) {
|
|
32
|
+
if (errors.length == 1) {
|
|
33
|
+
__.consoleError(error.message);
|
|
34
|
+
}
|
|
35
|
+
throw firostError('ABERLAAS_LINT_FAIL_FAST', 'Fail to lint files');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
__.consoleError(error.message);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{ stopOnError: shouldFailFast },
|
|
42
|
+
);
|
|
31
43
|
|
|
32
|
-
if (
|
|
44
|
+
if (!_.isEmpty(errors)) {
|
|
33
45
|
throw firostError('ABERLAAS_LINT_FAIL', 'Fail to lint files');
|
|
34
46
|
}
|
|
35
47
|
|
package/package.json
CHANGED
|
@@ -1,47 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberlaas-lint",
|
|
3
|
+
"version": "2.22.0",
|
|
3
4
|
"type": "module",
|
|
4
|
-
"sideEffects": false,
|
|
5
5
|
"description": "aberlaas lint command: Lint files",
|
|
6
|
-
"
|
|
7
|
-
"repository": "pixelastic/aberlaas",
|
|
6
|
+
"author": "Tim Carry <tim@pixelastic.com>",
|
|
8
7
|
"homepage": "https://projects.pixelastic.com/aberlaas/",
|
|
9
|
-
"
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/pixelastic/aberlaas"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
10
13
|
"license": "MIT",
|
|
11
14
|
"files": [
|
|
12
15
|
"lib/*.js",
|
|
13
16
|
"lib/helpers/*.js",
|
|
14
|
-
"configs/*.js"
|
|
17
|
+
"configs/*.js",
|
|
18
|
+
"configs/eslint/*.js"
|
|
15
19
|
],
|
|
16
20
|
"exports": {
|
|
17
21
|
".": "./lib/main.js",
|
|
18
|
-
"./configs/eslint": "./configs/eslint.js",
|
|
22
|
+
"./configs/eslint": "./configs/eslint/index.js",
|
|
19
23
|
"./configs/prettier": "./configs/prettier.js",
|
|
20
24
|
"./configs/stylelint": "./configs/stylelint.js"
|
|
21
25
|
},
|
|
22
26
|
"main": "./lib/main.js",
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=18.18.0"
|
|
25
|
-
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@eslint/js": "9.39.2",
|
|
29
|
+
"@eslint/json": "1.0.0",
|
|
28
30
|
"@typescript-eslint/utils": "8.54.0",
|
|
29
31
|
"@vitest/eslint-plugin": "1.6.6",
|
|
30
|
-
"aberlaas-helper": "
|
|
31
|
-
"aberlaas-versions": "
|
|
32
|
+
"aberlaas-helper": "2.22.0",
|
|
33
|
+
"aberlaas-versions": "2.22.0",
|
|
32
34
|
"ci-info": "4.4.0",
|
|
33
35
|
"eslint": "9.39.2",
|
|
34
36
|
"eslint-config-prettier": "10.1.8",
|
|
35
37
|
"eslint-plugin-import": "2.32.0",
|
|
36
38
|
"eslint-plugin-jsdoc": "62.5.0",
|
|
37
39
|
"eslint-plugin-n": "17.23.2",
|
|
40
|
+
"eslint-plugin-package-json": "0.88.2",
|
|
38
41
|
"eslint-plugin-prettier": "5.5.5",
|
|
39
42
|
"eslint-plugin-react": "7.37.5",
|
|
40
43
|
"firost": "5.5.1",
|
|
41
|
-
"globals": "17.
|
|
44
|
+
"globals": "17.3.0",
|
|
42
45
|
"golgoth": "3.1.0",
|
|
46
|
+
"jsonc-eslint-parser": "2.4.2",
|
|
43
47
|
"prettier": "3.8.1",
|
|
44
|
-
"stylelint": "17.
|
|
48
|
+
"stylelint": "17.1.0",
|
|
45
49
|
"typescript": "5.9.3",
|
|
46
50
|
"yaml-lint": "1.7.0"
|
|
47
51
|
},
|
|
@@ -49,13 +53,13 @@
|
|
|
49
53
|
"build": "cd ../docs && yarn run build",
|
|
50
54
|
"build:prod": "cd ../docs && yarn run build:prod",
|
|
51
55
|
"cms": "cd ../docs && yarn run cms",
|
|
52
|
-
"serve": "cd ../docs && yarn run serve",
|
|
53
|
-
"release": "cd ../.. && ./scripts/release",
|
|
54
|
-
"test:meta": "cd ../.. && ./scripts/test-meta",
|
|
55
|
-
"test": "cd ../.. && ./scripts/test",
|
|
56
|
-
"test:watch": "cd ../.. && ./scripts/test-watch",
|
|
57
56
|
"compress": "cd ../.. && ./scripts/compress",
|
|
58
57
|
"lint": "cd ../.. && ./scripts/lint",
|
|
59
|
-
"lint:fix": "cd ../.. && ./scripts/lint-fix"
|
|
58
|
+
"lint:fix": "cd ../.. && ./scripts/lint-fix",
|
|
59
|
+
"release": "cd ../.. && ./scripts/release",
|
|
60
|
+
"serve": "cd ../docs && yarn run serve",
|
|
61
|
+
"test": "cd ../.. && ./scripts/test",
|
|
62
|
+
"test:meta": "cd ../.. && ./scripts/test-meta",
|
|
63
|
+
"test:watch": "cd ../.. && ./scripts/test-watch"
|
|
60
64
|
}
|
|
61
|
-
}
|
|
65
|
+
}
|