@naturalcycles/dev-lib 13.55.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.
@@ -153,7 +153,6 @@ module.exports = {
153
153
  },
154
154
  ],
155
155
  'constructor-super': 2,
156
- curly: [2, 'multi-line'],
157
156
  'eol-last': 2,
158
157
  eqeqeq: [2, 'smart'],
159
158
  'for-direction': 2,
@@ -171,8 +170,16 @@ module.exports = {
171
170
  'undefined',
172
171
  ],
173
172
  'id-match': 2,
174
- 'import/order': [
173
+ 'simple-import-sort/imports': [
175
174
  2,
175
+ {
176
+ // This is what "removes any newlines between imports":
177
+ groups: [['^\\u0000', '^node:', '^@?\\w', '^', '^\\.']],
178
+ },
179
+ ],
180
+ 'simple-import-sort/exports': 2,
181
+ 'import/order': [
182
+ 0, // disabled in favor of `simple-import-sort`
176
183
  {
177
184
  alphabetize: {
178
185
  order: 'asc',
@@ -1,62 +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
- env: {
13
- es2024: true,
14
- node: true,
15
- jest: true,
16
- // 'jest/globals': true,
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
- globals: {
19
- NodeJS: 'readable',
20
- // testcafe
21
- fixture: 'readable',
40
+ {
41
+ ignores: ['**/__exclude/**', '**/*.scss', '**/*.js'],
22
42
  },
23
- ignorePatterns: ['**/__exclude/**'],
24
- overrides: [
25
- {
26
- files: ['*.ts', '*.tsx'],
27
- extends: [
28
- 'eslint:recommended',
29
- // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts
30
- 'plugin:@typescript-eslint/recommended-type-checked',
31
- // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts
32
- 'plugin:@typescript-eslint/stylistic-type-checked',
33
- // 'plugin:jest/recommended', // add manually if needed!
34
- // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/configs/recommended.js
35
- 'plugin:unicorn/recommended',
36
- // https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
37
- // 'plugin:import/recommended',
38
- // https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js
39
- // 'plugin:import/typescript',
40
- hasJest && './eslint-jest-rules.js',
41
- './eslint-rules.js',
42
- 'prettier', // must be last! it only turns off eslint rules that conflict with prettier
43
- ].filter(Boolean),
44
- parser: '@typescript-eslint/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,
45
66
  parserOptions: {
46
- project: ['tsconfig.json'],
47
- sourceType: 'module',
67
+ project: 'tsconfig.json',
48
68
  ecmaVersion: 'latest',
49
69
  extraFileExtensions: ['.vue', '.html'],
50
70
  },
51
- plugins: [
52
- 'jsdoc',
53
- 'import',
54
- '@typescript-eslint',
55
- // https://github.com/sweepline/eslint-plugin-unused-imports
56
- 'unused-imports',
57
- hasJest && 'jest',
58
- 'unicorn',
59
- ].filter(Boolean),
60
71
  },
61
- ],
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
+ }
62
84
  }
@@ -1 +1,3 @@
1
- module.exports = require('@naturalcycles/dev-lib/cfg/commitlint.config')
1
+ module.exports = {
2
+ ...require('@naturalcycles/dev-lib/cfg/commitlint.config'),
3
+ }
@@ -0,0 +1,4 @@
1
+ // prettier-ignore
2
+ module.exports = [
3
+ ...require('@naturalcycles/dev-lib/cfg/eslint.config'),
4
+ ]
@@ -1 +1,3 @@
1
- module.exports = require('@naturalcycles/dev-lib/cfg/lint-staged.config')
1
+ module.exports = {
2
+ ...require('@naturalcycles/dev-lib/cfg/lint-staged.config'),
3
+ }
@@ -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 = micromatch.not(match, lintExclude).join(' ')
52
+ const filesList = getFilesList(match)
47
53
  if (!filesList) return []
48
- return [`${eslintCmd} --config ${eslintConfigPathRoot}`, prettierCmd].map(
49
- s => `${s} ${filesList}`,
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 = micromatch.not(match, lintExclude).join(' ')
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 = micromatch.not(match, lintExclude).join(' ')
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 = micromatch.not(match, lintExclude).join(' ')
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 = micromatch.not(match, lintExclude).join(' ')
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
- ['./scripts/.eslintrc.js', './.eslintrc.js'].find(p => fs.existsSync(p)) ||
116
- `${cfgDir}/eslint.config.js`
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 = micromatch.not(match, lintExclude).join(' ')
127
+ const filesList = getFilesList(match)
122
128
  if (!filesList) return []
123
129
  return [
124
- `${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json`,
130
+ eslintConfigPathScripts &&
131
+ `${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json`,
125
132
  prettierCmd,
126
- ].map(s => `${s} ${filesList}`)
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
- ['./e2e/.eslintrc.js', './.eslintrc.js'].find(p => fs.existsSync(p)) ||
135
- `${cfgDir}/eslint.config.js`
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 = micromatch.not(match, lintExclude).join(' ')
149
+ const filesList = getFilesList(match)
141
150
  if (!filesList) return []
142
151
  return [
143
- `${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json`,
152
+ eslintConfigPathE2e &&
153
+ `${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json`,
144
154
  prettierCmd,
145
- ].map(s => `${s} ${filesList}`)
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
- ['./playwright/.eslintrc.js', './.eslintrc.js'].find(p => fs.existsSync(p)) ||
154
- `${cfgDir}/eslint.config.js`
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 = micromatch.not(match, lintExclude).join(' ')
171
+ const filesList = getFilesList(match)
160
172
  if (!filesList) return []
161
173
  return [
162
- `${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./playwright/tsconfig.json`,
174
+ eslintConfigPathE2e &&
175
+ `${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./playwright/tsconfig.json`,
163
176
  prettierCmd,
164
- ].map(s => `${s} ${filesList}`)
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 = `${paths_cnst_1.cfgDir}/lint-staged.config.js`;
12
- const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
13
- // this probably doesn't work, but we're still trying
14
- process.env['ESLINT_USE_FLAT_CONFIG'] = 'false';
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 = ['./.eslintrc.js'].find(p => node_fs_1.default.existsSync(p)) || `${paths_cnst_1.cfgDir}/eslint.config.js`;
28
- const eslintConfigPathScripts = ['./scripts/.eslintrc.js', './.eslintrc.js'].find(p => node_fs_1.default.existsSync(p)) ||
29
- `${paths_cnst_1.cfgDir}/eslint.config.js`;
30
- const eslintConfigPathE2e = ['./e2e/.eslintrc.js', './.eslintrc.js'].find(p => node_fs_1.default.existsSync(p)) ||
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
  }
@@ -5,4 +5,4 @@ export * from './expect.util';
5
5
  export * from './mockAllKindsOfThings';
6
6
  export * from './testing.util';
7
7
  export * from './time.util';
8
- export { timekeeper, expectTypeOf };
8
+ export { expectTypeOf, timekeeper };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expectTypeOf = exports.timekeeper = void 0;
3
+ exports.timekeeper = exports.expectTypeOf = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const expect_type_1 = require("expect-type");
6
6
  Object.defineProperty(exports, "expectTypeOf", { enumerable: true, get: function () { return expect_type_1.expectTypeOf; } });
@@ -1,4 +1,4 @@
1
- export declare function getJestConfigPath(): string;
1
+ export declare function getJestConfigPath(): string | undefined;
2
2
  export declare function getJestIntegrationConfigPath(): string;
3
3
  export declare function getJestManualConfigPath(): string;
4
4
  /**
@@ -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' : `${paths_cnst_1.cfgDir}/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 = [
@@ -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>;
@@ -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
- // If there's no `prettier.config.js` in target project - pass `./cfg/prettier.config.js`
19
- const prettierConfigPath = [`./prettier.config.js`].find(f => node_fs_1.default.existsSync(f)) || `${paths_cnst_1.cfgDir}/prettier.config.js`;
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`, `${paths_cnst_1.cfgDir}/stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
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": "13.55.0",
3
+ "version": "14.0.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "tsn-debug": "tsn testScript.ts",
@@ -31,23 +31,24 @@
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",
45
44
  "eslint-plugin-jest": "^28.0.0",
46
45
  "eslint-plugin-jsdoc": "^48.0.1",
46
+ "eslint-plugin-simple-import-sort": "^12.1.1",
47
47
  "eslint-plugin-unicorn": "^54.0.0",
48
48
  "eslint-plugin-unused-imports": "^4.0.0",
49
49
  "eslint-plugin-vue": "^9.0.0",
50
50
  "expect-type": "^0.19.0",
51
+ "globals": "^15.8.0",
51
52
  "husky": "^9.0.2",
52
53
  "jest-junit": "^16.0.0",
53
54
  "lint-staged": "^15.0.1",
@@ -57,6 +58,7 @@
57
58
  "timekeeper": "^2.2.0",
58
59
  "ts-jest": "^29.0.0",
59
60
  "typescript": "^5.0.2",
61
+ "typescript-eslint": "^7.16.1",
60
62
  "yargs": "^17.0.0"
61
63
  },
62
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
- `.eslintrc.js`, `stylelint.config.json` in the root folder of your project.
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
- }
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- extends: './node_modules/@naturalcycles/dev-lib/cfg/eslint.config.js',
3
- }