@naturalcycles/dev-lib 12.4.1 → 12.7.1
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/CHANGELOG.md +29 -0
- package/cfg/eslint-rules.js +63 -4
- package/cfg/eslint.config.js +5 -0
- package/cfg/jest.config.js +1 -0
- package/cfg/lint-staged.config.js +11 -24
- package/cfg/overwrite/.codeclimate.yml +1 -0
- package/dist/bin/bt.js +1 -1
- package/dist/bin/build.js +1 -1
- package/dist/bin/commitlint-def.js +1 -1
- package/dist/bin/lint-staged-def.js +1 -1
- package/dist/cmd/build-prod-esm-cjs.command.js +1 -1
- package/dist/cmd/eslint-all.command.js +10 -6
- package/dist/cmd/lint-all.command.d.ts +1 -5
- package/dist/cmd/lint-all.command.js +1 -7
- package/dist/cmd/tsc-scripts.command.js +1 -1
- package/dist/jestOffline.util.js +2 -2
- package/dist/testing/mockAllKindsOfThings.js +1 -1
- package/dist/util/git.util.js +1 -1
- package/dist/util/jest.util.js +1 -1
- package/dist/util/{tslint.util.d.ts → lint.util.d.ts} +1 -3
- package/dist/util/{tslint.util.js → lint.util.js} +5 -28
- package/dist/util/prettier.util.js +1 -1
- package/dist/util/stylelint.util.js +15 -2
- package/dist/util/tsc.util.js +1 -1
- package/package.json +1 -4
- package/readme.md +11 -6
- package/cfg/init/tslint.json +0 -6
- package/cfg/tslint.config.js +0 -36
- package/dist/bin/tslint-all.d.ts +0 -2
- package/dist/bin/tslint-all.js +0 -6
- package/dist/cmd/tslint-all.command.d.ts +0 -4
- package/dist/cmd/tslint-all.command.js +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## [12.7.1](https://github.com/NaturalCycles/dev-lib/compare/v12.7.0...v12.7.1) (2021-10-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* eslint typeParameter to allow UPPER_CASE ([5972be3](https://github.com/NaturalCycles/dev-lib/commit/5972be3a9d78877d3a52c9087eb87db456b473a5))
|
|
7
|
+
|
|
8
|
+
# [12.7.0](https://github.com/NaturalCycles/dev-lib/compare/v12.6.0...v12.7.0) (2021-10-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* adopt `@typescript-eslint/naming-convention` ([de2d0a6](https://github.com/NaturalCycles/dev-lib/commit/de2d0a6c2b9c2119a909ac4c8f4378289ac16c38))
|
|
14
|
+
* finally remove tslint in favor of eslint ([39451c9](https://github.com/NaturalCycles/dev-lib/commit/39451c96ba4844468d178af680a02a108d148c7f))
|
|
15
|
+
|
|
16
|
+
# [12.6.0](https://github.com/NaturalCycles/dev-lib/compare/v12.5.0...v12.6.0) (2021-09-22)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* exclude `src/vendor` from test coverage ([75fe084](https://github.com/NaturalCycles/dev-lib/commit/75fe0849306225915d25faf392f9e516113c6fe9))
|
|
22
|
+
|
|
23
|
+
# [12.5.0](https://github.com/NaturalCycles/dev-lib/compare/v12.4.1...v12.5.0) (2021-09-18)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* support `--fix=false` to debug behaving linters ([4fa996b](https://github.com/NaturalCycles/dev-lib/commit/4fa996b9bd40ee1ee7fd793997367167cd365a90))
|
|
29
|
+
|
|
1
30
|
## [12.4.1](https://github.com/NaturalCycles/dev-lib/compare/v12.4.0...v12.4.1) (2021-09-18)
|
|
2
31
|
|
|
3
32
|
|
package/cfg/eslint-rules.js
CHANGED
|
@@ -26,12 +26,71 @@ module.exports = {
|
|
|
26
26
|
],
|
|
27
27
|
'@typescript-eslint/consistent-type-assertions': 2,
|
|
28
28
|
'@typescript-eslint/consistent-type-definitions': 2,
|
|
29
|
+
// Doc: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
|
|
30
|
+
// Loosely based on this: https://github.com/xojs/eslint-config-xo-typescript/blob/main/index.js
|
|
29
31
|
'@typescript-eslint/naming-convention': [
|
|
30
|
-
|
|
32
|
+
2,
|
|
31
33
|
{
|
|
32
|
-
// todo: clarify later, currently disabled
|
|
33
34
|
selector: 'default',
|
|
35
|
+
format: ['camelCase'],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
selector: ['function', 'parameter', 'property', 'method', 'memberLike'],
|
|
39
|
+
format: ['camelCase'],
|
|
40
|
+
leadingUnderscore: 'allowSingleOrDouble',
|
|
41
|
+
trailingUnderscore: 'forbid',
|
|
42
|
+
// Ignore `{'Retry-After': retryAfter}` type properties.
|
|
43
|
+
filter: {
|
|
44
|
+
regex: '[- ]',
|
|
45
|
+
match: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
selector: ['variable', 'classProperty'],
|
|
34
50
|
format: ['camelCase', 'UPPER_CASE'],
|
|
51
|
+
leadingUnderscore: 'allowSingleOrDouble',
|
|
52
|
+
trailingUnderscore: 'allow',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
selector: ['objectLiteralProperty', 'objectLiteralMethod', 'typeProperty', 'enumMember'],
|
|
56
|
+
format: [
|
|
57
|
+
'camelCase',
|
|
58
|
+
'UPPER_CASE',
|
|
59
|
+
// only for 3rd-party code/api compatibility! Try to avoid in our code
|
|
60
|
+
'PascalCase',
|
|
61
|
+
'snake_case',
|
|
62
|
+
],
|
|
63
|
+
leadingUnderscore: 'allow',
|
|
64
|
+
trailingUnderscore: 'forbid',
|
|
65
|
+
},
|
|
66
|
+
// Allow destructured variables to not follow the rules
|
|
67
|
+
{
|
|
68
|
+
selector: ['variable', 'parameter'],
|
|
69
|
+
modifiers: ['destructured'],
|
|
70
|
+
format: null,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
selector: 'typeLike',
|
|
74
|
+
format: ['PascalCase'],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
selector: 'typeParameter',
|
|
78
|
+
format: ['PascalCase', 'UPPER_CASE'],
|
|
79
|
+
},
|
|
80
|
+
// Allow these in non-camel-case when quoted.
|
|
81
|
+
{
|
|
82
|
+
selector: [
|
|
83
|
+
'classProperty',
|
|
84
|
+
'objectLiteralProperty',
|
|
85
|
+
'typeProperty',
|
|
86
|
+
'classMethod',
|
|
87
|
+
'objectLiteralMethod',
|
|
88
|
+
'typeMethod',
|
|
89
|
+
'accessor',
|
|
90
|
+
'enumMember',
|
|
91
|
+
],
|
|
92
|
+
format: null,
|
|
93
|
+
modifiers: ['requiresQuotes'],
|
|
35
94
|
},
|
|
36
95
|
],
|
|
37
96
|
'@typescript-eslint/no-array-constructor': 2,
|
|
@@ -88,7 +147,7 @@ module.exports = {
|
|
|
88
147
|
'undefined',
|
|
89
148
|
],
|
|
90
149
|
'id-match': 2,
|
|
91
|
-
|
|
150
|
+
'import/order': 2,
|
|
92
151
|
'jsdoc/check-alignment': 2,
|
|
93
152
|
// "jsdoc/check-indentation": "error",
|
|
94
153
|
'jsdoc/newline-after-description': 2,
|
|
@@ -176,7 +235,6 @@ module.exports = {
|
|
|
176
235
|
'no-unsafe-finally': 2,
|
|
177
236
|
'no-unsafe-negation': 2,
|
|
178
237
|
'no-unused-labels': 2,
|
|
179
|
-
'no-unused-vars': 0, // replaced by `unused-imports/no-unused-vars`
|
|
180
238
|
'no-useless-catch': 2,
|
|
181
239
|
'no-useless-escape': 2,
|
|
182
240
|
'no-unneeded-ternary': 2,
|
|
@@ -215,6 +273,7 @@ module.exports = {
|
|
|
215
273
|
allowDeclarations: true, // allows `namespace NodeJS {}` augmentations
|
|
216
274
|
},
|
|
217
275
|
],
|
|
276
|
+
'no-unused-vars': 0, // replaced by `unused-imports/no-unused-vars`
|
|
218
277
|
'@typescript-eslint/no-unused-vars': [
|
|
219
278
|
0, // replaced by `unused-imports/no-unused-vars`
|
|
220
279
|
{
|
package/cfg/eslint.config.js
CHANGED
|
@@ -28,6 +28,10 @@ module.exports = {
|
|
|
28
28
|
// 'plugin:jest/recommended', // add manually if needed!
|
|
29
29
|
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/configs/recommended.js
|
|
30
30
|
'plugin:unicorn/recommended',
|
|
31
|
+
// https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
|
|
32
|
+
'plugin:import/recommended',
|
|
33
|
+
// https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js
|
|
34
|
+
'plugin:import/typescript',
|
|
31
35
|
'./eslint-rules.js',
|
|
32
36
|
'prettier', // must be last! it only turns off eslint rules that conflict with prettier
|
|
33
37
|
],
|
|
@@ -42,6 +46,7 @@ module.exports = {
|
|
|
42
46
|
'jsdoc',
|
|
43
47
|
'import',
|
|
44
48
|
'@typescript-eslint',
|
|
49
|
+
// https://github.com/sweepline/eslint-plugin-unused-imports
|
|
45
50
|
'unused-imports',
|
|
46
51
|
// 'jest', // add manually if needed!
|
|
47
52
|
'unicorn',
|
package/cfg/jest.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
Default config for `lint-staged`.
|
|
3
3
|
Extendable.
|
|
4
|
-
Supports default configs for `prettier`, `stylelint`, `
|
|
4
|
+
Supports default configs for `prettier`, `stylelint`, `eslint`, if they are not found in target project.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const micromatch = require('micromatch')
|
|
@@ -18,40 +18,31 @@ const cfgDir = __dirname
|
|
|
18
18
|
const prettierConfigPath =
|
|
19
19
|
[`prettier.config.js`].find(fs.existsSync) || `${cfgDir}/prettier.config.js`
|
|
20
20
|
|
|
21
|
-
const tslintConfigPath = [`tslint.json`].find(fs.existsSync) || `${cfgDir}/tslint.config.js`
|
|
22
|
-
|
|
23
21
|
const stylelintConfigPath =
|
|
24
22
|
[`stylelint.config.js`].find(fs.existsSync) || `${cfgDir}/stylelint.config.js`
|
|
25
23
|
|
|
26
24
|
// this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
|
|
27
25
|
// const tsconfigPathRoot = ['tsconfig.base.json'].find(p => fs.existsSync(p)) || 'tsconfig.json'
|
|
28
|
-
const tsconfigPathRoot = 'tsconfig.json'
|
|
26
|
+
// const tsconfigPathRoot = 'tsconfig.json'
|
|
29
27
|
|
|
30
28
|
const eslintConfigPathRoot =
|
|
31
29
|
['.eslintrc.js'].find(p => fs.existsSync(p)) || `${cfgDir}/eslint.config.js`
|
|
32
30
|
|
|
33
31
|
const prettierCmd = `prettier --write --config ${prettierConfigPath}`
|
|
34
|
-
const tslintCmd = `tslint -t stylish --fix --config ${tslintConfigPath}`
|
|
35
32
|
const eslintCmd = `eslint --fix`
|
|
36
33
|
const styleLintCmd = `stylelint --fix --config ${stylelintConfigPath}`
|
|
37
34
|
|
|
38
35
|
const linters = {
|
|
39
|
-
// *.ts files: eslint,
|
|
40
|
-
// There are 2 tslint tasks, one without `-p` and the second is with `-p` - it is a speed optimization
|
|
36
|
+
// *.{ts,tsx,vue} files: eslint, prettier
|
|
41
37
|
'./src/**/*.{ts,tsx,vue}': match => {
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
`${eslintCmd} --config ${eslintConfigPathRoot} ${filesList}`,
|
|
48
|
-
filesListTSLint && `${tslintCmd} ${filesListTSLint}`,
|
|
49
|
-
filesListTSLint && `${tslintCmd} -p ${tsconfigPathRoot} ${filesListTSLint}`,
|
|
50
|
-
`${prettierCmd} ${filesList}`,
|
|
51
|
-
].filter(Boolean)
|
|
38
|
+
const filesList = micromatch.not(match, lintExclude).join(' ')
|
|
39
|
+
if (!filesList) return []
|
|
40
|
+
return [`${eslintCmd} --config ${eslintConfigPathRoot}`, prettierCmd].map(
|
|
41
|
+
s => `${s} ${filesList}`,
|
|
42
|
+
)
|
|
52
43
|
},
|
|
53
44
|
|
|
54
|
-
// For all other files we run only Prettier (because e.g
|
|
45
|
+
// For all other files we run only Prettier (because e.g eslint screws *.scss files)
|
|
55
46
|
[`./{${prettierDirs}}/**/*.{${prettierExtensionsExclusive}}`]: match => {
|
|
56
47
|
const filesList = micromatch.not(match, lintExclude).join(' ')
|
|
57
48
|
if (!filesList) return []
|
|
@@ -93,14 +84,12 @@ if (fs.existsSync(`./scripts`)) {
|
|
|
93
84
|
`${cfgDir}/eslint.config.js`
|
|
94
85
|
|
|
95
86
|
Object.assign(linters, {
|
|
96
|
-
// eslint,
|
|
87
|
+
// eslint, Prettier
|
|
97
88
|
'./scripts/**/*.{ts,tsx}': match => {
|
|
98
89
|
const filesList = micromatch.not(match, lintExclude).join(' ')
|
|
99
90
|
if (!filesList) return []
|
|
100
91
|
return [
|
|
101
92
|
`${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json`,
|
|
102
|
-
tslintCmd,
|
|
103
|
-
`${tslintCmd} -p ./scripts/tsconfig.json`,
|
|
104
93
|
prettierCmd,
|
|
105
94
|
].map(s => `${s} ${filesList}`)
|
|
106
95
|
},
|
|
@@ -114,14 +103,12 @@ if (fs.existsSync(`./e2e`)) {
|
|
|
114
103
|
`${cfgDir}/eslint.config.js`
|
|
115
104
|
|
|
116
105
|
Object.assign(linters, {
|
|
117
|
-
// eslint,
|
|
106
|
+
// eslint, Prettier
|
|
118
107
|
'./e2e/**/*.{ts,tsx}': match => {
|
|
119
108
|
const filesList = micromatch.not(match, lintExclude).join(' ')
|
|
120
109
|
if (!filesList) return []
|
|
121
110
|
return [
|
|
122
111
|
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json`,
|
|
123
|
-
tslintCmd,
|
|
124
|
-
`${tslintCmd} -p ./e2e/tsconfig.json`,
|
|
125
112
|
prettierCmd,
|
|
126
113
|
].map(s => `${s} ${filesList}`)
|
|
127
114
|
},
|
package/dist/bin/bt.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
6
|
const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
|
|
7
7
|
const jest_util_1 = require("../util/jest.util");
|
|
8
8
|
const tsc_util_1 = require("../util/tsc.util");
|
package/dist/bin/build.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
6
|
const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
|
|
7
7
|
const tsc_util_1 = require("../util/tsc.util");
|
|
8
8
|
(0, script_1.runScript)(async () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
5
6
|
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
|
-
const fs = require("fs");
|
|
7
7
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
8
8
|
const git_util_1 = require("../util/git.util");
|
|
9
9
|
(0, script_1.runScript)(async () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
6
6
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
7
7
|
(0, script_1.runScript)(async () => {
|
|
8
8
|
// const cwd = process.cwd()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildProdESMCJSCommand = void 0;
|
|
4
|
-
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
6
6
|
// You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
|
|
7
7
|
const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
|
|
8
8
|
const TSCONF_ESM_PATH = `./tsconfig.esm.prod.json`;
|
|
@@ -4,16 +4,20 @@ exports.eslintAllCommand = void 0;
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const yargs = require("yargs");
|
|
6
6
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
7
|
-
const
|
|
7
|
+
const lint_util_1 = require("../util/lint.util");
|
|
8
8
|
/**
|
|
9
9
|
* Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
|
|
10
10
|
*/
|
|
11
11
|
async function eslintAllCommand() {
|
|
12
|
-
const { ext } = yargs.options({
|
|
12
|
+
const { ext, fix } = yargs.options({
|
|
13
13
|
ext: {
|
|
14
14
|
type: 'string',
|
|
15
15
|
default: 'ts,tsx,vue',
|
|
16
16
|
},
|
|
17
|
+
fix: {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: true,
|
|
20
|
+
},
|
|
17
21
|
}).argv;
|
|
18
22
|
const extensions = ext.split(',');
|
|
19
23
|
const eslintConfigPathRoot = ['./.eslintrc.js'].find(p => fs.existsSync(p)) || `${paths_cnst_1.cfgDir}/eslint.config.js`;
|
|
@@ -22,14 +26,14 @@ async function eslintAllCommand() {
|
|
|
22
26
|
const eslintConfigPathE2e = ['./e2e/.eslintrc.js', './.eslintrc.js'].find(p => fs.existsSync(p)) ||
|
|
23
27
|
`${paths_cnst_1.cfgDir}/eslint.config.js`;
|
|
24
28
|
// const tsconfigPath = getTSConfigPath()
|
|
25
|
-
const tsconfigPathScripts = (0,
|
|
29
|
+
const tsconfigPathScripts = (0, lint_util_1.getTSConfigPathScripts)();
|
|
26
30
|
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
27
31
|
// /src
|
|
28
32
|
// await runESLint(`./src`, eslintConfigPathRoot, tsconfigPath, extensions)
|
|
29
|
-
await (0,
|
|
33
|
+
await (0, lint_util_1.runESLint)(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
|
|
30
34
|
// /scripts
|
|
31
|
-
await (0,
|
|
35
|
+
await (0, lint_util_1.runESLint)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
|
|
32
36
|
// /e2e
|
|
33
|
-
await (0,
|
|
37
|
+
await (0, lint_util_1.runESLint)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
|
|
34
38
|
}
|
|
35
39
|
exports.eslintAllCommand = eslintAllCommand;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* We run tslint BEFORE Prettier, because tslint can delete e.g unused imports.
|
|
5
|
-
*
|
|
6
|
-
* We run TSLint separately for /src and /scripts dir, because they might have a different tsconfig.json file.
|
|
2
|
+
* We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
|
|
7
3
|
*/
|
|
8
4
|
export declare function lintAllCommand(): Promise<void>;
|
|
@@ -6,13 +6,8 @@ const git_util_1 = require("../util/git.util");
|
|
|
6
6
|
const prettier_util_1 = require("../util/prettier.util");
|
|
7
7
|
const stylelint_util_1 = require("../util/stylelint.util");
|
|
8
8
|
const eslint_all_command_1 = require("./eslint-all.command");
|
|
9
|
-
const tslint_all_command_1 = require("./tslint-all.command");
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* We run tslint BEFORE Prettier, because tslint can delete e.g unused imports.
|
|
14
|
-
*
|
|
15
|
-
* We run TSLint separately for /src and /scripts dir, because they might have a different tsconfig.json file.
|
|
10
|
+
* We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
|
|
16
11
|
*/
|
|
17
12
|
async function lintAllCommand() {
|
|
18
13
|
const { commitOnChanges, failOnChanges } = yargs.options({
|
|
@@ -28,7 +23,6 @@ async function lintAllCommand() {
|
|
|
28
23
|
const hadChangesBefore = await (0, git_util_1.gitHasUncommittedChanges)();
|
|
29
24
|
// Currently we position ESLint before TSLint, but let's monitor if it's ok
|
|
30
25
|
await (0, eslint_all_command_1.eslintAllCommand)();
|
|
31
|
-
await (0, tslint_all_command_1.tslintAllCommand)();
|
|
32
26
|
await (0, stylelint_util_1.stylelintAll)();
|
|
33
27
|
await (0, prettier_util_1.runPrettier)();
|
|
34
28
|
if (commitOnChanges || failOnChanges) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tscScriptsCommand = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
6
7
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
7
|
-
const fs = require("fs");
|
|
8
8
|
const tsc_util_1 = require("../util/tsc.util");
|
|
9
9
|
async function tscScriptsCommand() {
|
|
10
10
|
if (!fs.existsSync('./scripts')) {
|
package/dist/jestOffline.util.js
CHANGED
|
@@ -12,8 +12,8 @@ function jestOffline() {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
console.log('jest offline mode');
|
|
15
|
-
const
|
|
16
|
-
const mitm =
|
|
15
|
+
const createMitm = require('mitm');
|
|
16
|
+
const mitm = createMitm();
|
|
17
17
|
mitm.on('connect', (socket, opts) => {
|
|
18
18
|
const { host } = opts;
|
|
19
19
|
if (!LOCAL_HOSTS.includes(host)) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mockAllKindsOfThings = void 0;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
5
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/naming-convention */
|
|
6
6
|
const mockAllKindsOfThings = () => {
|
|
7
7
|
const errorWithCode = new Error('Error with code');
|
|
8
8
|
Object.assign(errorWithCode, {
|
package/dist/util/git.util.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gitCurrentRepoName = exports.gitCurrentBranchName = exports.gitCurrentCommitTimestamp = exports.gitCurrentCommitSha = exports.gitPush = exports.gitPull = exports.gitIsAhead = exports.gitCommitAll = exports.gitHasUncommittedChanges = exports.commitMessageToTitleMessage = exports.getLastGitCommitMsg = void 0;
|
|
4
|
+
const path = require("path");
|
|
4
5
|
const exec_util_1 = require("@naturalcycles/nodejs-lib/dist/exec/exec.util");
|
|
5
6
|
const execa = require("execa");
|
|
6
|
-
const path = require("path");
|
|
7
7
|
async function getLastGitCommitMsg() {
|
|
8
8
|
// git log -1 --pretty=%B
|
|
9
9
|
const cmd = 'git';
|
package/dist/util/jest.util.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runJest = exports.isRunningAllTests = exports.getJestManualConfigPath = exports.getJestIntegrationConfigPath = exports.getJestConfigPath = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
6
7
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
7
|
-
const fs = require("fs");
|
|
8
8
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
9
9
|
const test_util_1 = require("./test.util");
|
|
10
10
|
function getJestConfigPath() {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare function runTSLint(dir: string, excludePaths: string[] | undefined, tslintConfigPath: string, tsconfigPath?: string): Promise<void>;
|
|
2
|
-
export declare function getTSLintConfigPath(): string;
|
|
3
1
|
export declare function getTSConfigPath(): string;
|
|
4
2
|
export declare function getTSConfigPathScripts(): string;
|
|
5
|
-
export declare function runESLint(dir: string, eslintConfigPath: string, tsconfigPath: string | undefined, extensions?: string[]): Promise<void>;
|
|
3
|
+
export declare function runESLint(dir: string, eslintConfigPath: string, tsconfigPath: string | undefined, extensions?: string[], fix?: boolean): Promise<void>;
|
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runESLint = exports.getTSConfigPathScripts = exports.getTSConfigPath =
|
|
4
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
-
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
3
|
+
exports.runESLint = exports.getTSConfigPathScripts = exports.getTSConfigPath = void 0;
|
|
6
4
|
const fs = require("fs");
|
|
5
|
+
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
7
6
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
8
|
-
async function runTSLint(dir, excludePaths = [], tslintConfigPath, tsconfigPath) {
|
|
9
|
-
if (!fs.existsSync(dir))
|
|
10
|
-
return; // faster like this
|
|
11
|
-
const args = [
|
|
12
|
-
`--config`,
|
|
13
|
-
tslintConfigPath,
|
|
14
|
-
`${dir}/**/*.{ts,tsx}`,
|
|
15
|
-
...(0, js_lib_1._flatten)(excludePaths.map(p => [`-e`, p])),
|
|
16
|
-
...(tsconfigPath ? [`-p`, tsconfigPath] : []),
|
|
17
|
-
`-t`,
|
|
18
|
-
`stylish`,
|
|
19
|
-
`--fix`,
|
|
20
|
-
];
|
|
21
|
-
await (0, exec_1.execWithArgs)('tslint', args);
|
|
22
|
-
}
|
|
23
|
-
exports.runTSLint = runTSLint;
|
|
24
|
-
function getTSLintConfigPath() {
|
|
25
|
-
const localTSLintConfig = `./tslint.json`;
|
|
26
|
-
const sharedTSLintConfig = `${paths_cnst_1.cfgDir}/tslint.config.js`;
|
|
27
|
-
return fs.existsSync(localTSLintConfig) ? localTSLintConfig : sharedTSLintConfig;
|
|
28
|
-
}
|
|
29
|
-
exports.getTSLintConfigPath = getTSLintConfigPath;
|
|
30
7
|
function getTSConfigPath() {
|
|
31
8
|
// this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
|
|
32
9
|
// return [`./tsconfig.base.json`].find(p => fs.existsSync(p)) || `./tsconfig.json`
|
|
@@ -37,7 +14,7 @@ function getTSConfigPathScripts() {
|
|
|
37
14
|
return [`./scripts/tsconfig.json`].find(p => fs.existsSync(p)) || `${paths_cnst_1.scriptsDir}/tsconfig.json`;
|
|
38
15
|
}
|
|
39
16
|
exports.getTSConfigPathScripts = getTSConfigPathScripts;
|
|
40
|
-
async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue']) {
|
|
17
|
+
async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
41
18
|
if (!fs.existsSync(dir))
|
|
42
19
|
return; // faster to bail-out like this
|
|
43
20
|
const args = [
|
|
@@ -46,8 +23,8 @@ async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts'
|
|
|
46
23
|
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
47
24
|
...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
|
|
48
25
|
`--no-error-on-unmatched-pattern`,
|
|
49
|
-
`--fix
|
|
50
|
-
];
|
|
26
|
+
fix ? `--fix` : '',
|
|
27
|
+
].filter(Boolean);
|
|
51
28
|
await (0, exec_1.execWithArgs)('eslint', args);
|
|
52
29
|
}
|
|
53
30
|
exports.runESLint = runESLint;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runPrettier = void 0;
|
|
4
|
-
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
6
6
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
7
7
|
const { prettierDirs, prettierExtensionsAll, lintExclude } = require('../../cfg/_cnst');
|
|
8
8
|
const prettierPaths = [
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stylelintAll = exports.stylelintPaths = void 0;
|
|
4
|
-
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
5
4
|
const fs = require("fs");
|
|
5
|
+
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
6
|
+
const yargs = require("yargs");
|
|
6
7
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
7
8
|
const { prettierDirs, stylelintExtensions, lintExclude } = require('../../cfg/_cnst');
|
|
8
9
|
exports.stylelintPaths = [
|
|
@@ -12,8 +13,20 @@ exports.stylelintPaths = [
|
|
|
12
13
|
...lintExclude.map((s) => `!${s}`),
|
|
13
14
|
];
|
|
14
15
|
async function stylelintAll() {
|
|
16
|
+
const { fix } = yargs.options({
|
|
17
|
+
fix: {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: true,
|
|
20
|
+
},
|
|
21
|
+
}).argv;
|
|
15
22
|
const config = [`./stylelint.config.js`, `${paths_cnst_1.cfgDir}/stylelint.config.js`].find(f => fs.existsSync(f));
|
|
16
|
-
const args = [
|
|
23
|
+
const args = [
|
|
24
|
+
fix ? `--fix` : '',
|
|
25
|
+
`--allow-empty-input`,
|
|
26
|
+
`--config`,
|
|
27
|
+
config,
|
|
28
|
+
...exports.stylelintPaths,
|
|
29
|
+
].filter(Boolean);
|
|
17
30
|
await (0, exec_1.execWithArgs)('stylelint', args);
|
|
18
31
|
}
|
|
19
32
|
exports.stylelintAll = stylelintAll;
|
package/dist/util/tsc.util.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureProjectTsconfigScripts = exports.tsc = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
6
7
|
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
7
8
|
const fs_1 = require("@naturalcycles/nodejs-lib/dist/fs");
|
|
8
|
-
const fs = require("fs");
|
|
9
9
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
10
10
|
async function tsc() {
|
|
11
11
|
const started = Date.now();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.7.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"tsn-debug": "tsn testScript.ts",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"commitlint-def": "tsn ./src/bin/commitlint-def.ts",
|
|
23
23
|
"prettier-all": "tsn ./src/bin/prettier-all.ts",
|
|
24
24
|
"stylelint-all": "tsn ./src/bin/stylelint-all.ts",
|
|
25
|
-
"tslint-all": "tsn ./src/bin/tslint-all.ts",
|
|
26
25
|
"lint-all": "tsn ./src/bin/lint-all.ts",
|
|
27
26
|
"lint-circleci": "tsn ./src/bin/lint-circleci.ts",
|
|
28
27
|
"eslint-all": "tsn ./src/bin/eslint-all.ts",
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"stylelint-scss": "^3.19.0",
|
|
64
63
|
"timekeeper": "^2.2.0",
|
|
65
64
|
"ts-jest": "^27.0.0",
|
|
66
|
-
"tslint": "^6.0.0",
|
|
67
65
|
"typescript": "^4.0.2",
|
|
68
66
|
"yargs": "^17.0.0"
|
|
69
67
|
},
|
|
@@ -101,7 +99,6 @@
|
|
|
101
99
|
"test-manual": "dist/bin/test-manual.js",
|
|
102
100
|
"tsc-prod": "dist/bin/tsc-prod.js",
|
|
103
101
|
"tsc-scripts": "dist/bin/tsc-scripts.js",
|
|
104
|
-
"tslint-all": "dist/bin/tslint-all.js",
|
|
105
102
|
"update-from-dev-lib": "dist/bin/update-from-dev-lib.js"
|
|
106
103
|
},
|
|
107
104
|
"engines": {
|
package/readme.md
CHANGED
|
@@ -22,9 +22,9 @@ This unlocks all commands listed below, e.g:
|
|
|
22
22
|
yarn test
|
|
23
23
|
yarn lint-all
|
|
24
24
|
|
|
25
|
-
By default, it uses default configs for Prettier,
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
By default, it uses default configs for Prettier, ESLint, Stylelint, that are included in this
|
|
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.
|
|
28
28
|
|
|
29
29
|
## Conventions
|
|
30
30
|
|
|
@@ -127,18 +127,24 @@ variable to disable it.
|
|
|
127
127
|
|
|
128
128
|
#### Lint commands
|
|
129
129
|
|
|
130
|
-
- `lint-all`: runs
|
|
130
|
+
- `lint-all`: runs ESLint, Stylelint, Prettier, in the right order.
|
|
131
131
|
|
|
132
132
|
- `--commitOnChanges` will commit lint-modified changes and push them
|
|
133
133
|
- `--failOnChanges` will exit with status 1 in the end (will fail the command)
|
|
134
134
|
|
|
135
|
-
- `tslint-all`: runs `tslint` on needed paths
|
|
136
135
|
- `eslint-all`: runs `eslint` on needed paths
|
|
137
136
|
- `stylelint-all`: runs `stylelint` on needed paths
|
|
138
137
|
- `prettier-all`: runs just Prettier on needed paths
|
|
139
138
|
- `lint-circleci`: fails if `.circleci/config.yml` is invalid
|
|
140
139
|
([CircleCI CLI](https://circleci.com/docs/2.0/local-cli/) must be installed before)
|
|
141
140
|
|
|
141
|
+
Pass `--no-fix` (or `--fix=false`) to disable the default `--fix` flag on linters. Useful to debug a
|
|
142
|
+
linter, or when linter behaves badly and corrupts your files (just happened to me with
|
|
143
|
+
`eslint-plugin-vue`).
|
|
144
|
+
|
|
145
|
+
Pass `--ext` (e.g `--ext ts,html`) to override the list of ESLint extensions (default is
|
|
146
|
+
`ts,tsx,vue` right now).
|
|
147
|
+
|
|
142
148
|
#### Other commands
|
|
143
149
|
|
|
144
150
|
- `init-from-dev-lib`: copy config files from `dev-lib/cfg/init` to the project
|
|
@@ -167,7 +173,6 @@ These files are meant to be extended in target project, so act as _recommended d
|
|
|
167
173
|
- `husky.config.js`
|
|
168
174
|
- `lint-staged.config.js`
|
|
169
175
|
- `prettier.config.js`
|
|
170
|
-
- `tslint.json`
|
|
171
176
|
- `eslint.config.json`
|
|
172
177
|
- `jest.config.js`
|
|
173
178
|
|
package/cfg/init/tslint.json
DELETED
package/cfg/tslint.config.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// formatting rules still have value that IDEs will infer their setting from them
|
|
2
|
-
module.exports = {
|
|
3
|
-
rules: {
|
|
4
|
-
'class-name': true,
|
|
5
|
-
// 'interface-name': [false, 'never-prefix'],
|
|
6
|
-
// 'no-console': [false, 'debug', 'info', 'time', 'timeEnd', 'trace'],
|
|
7
|
-
// 'no-duplicate-imports': false,
|
|
8
|
-
'no-floating-promises': true,
|
|
9
|
-
// 'no-implicit-dependencies': [false, 'dev', ['@app']],
|
|
10
|
-
'no-invalid-this': [true, 'check-function-in-method'],
|
|
11
|
-
// 'no-null-keyword': false,
|
|
12
|
-
// 'no-require-imports': false,
|
|
13
|
-
// 'no-shadowed-variable': false,
|
|
14
|
-
// 'no-string-literal': false,
|
|
15
|
-
'no-unused-variable': [true, { 'ignore-pattern': '^_' }], // todo: check it
|
|
16
|
-
'ordered-imports': true, // todo
|
|
17
|
-
'promise-function-async': [
|
|
18
|
-
true,
|
|
19
|
-
'check-function-declaration',
|
|
20
|
-
'check-function-expression',
|
|
21
|
-
'check-method-declaration',
|
|
22
|
-
],
|
|
23
|
-
typedef: [true, 'property-declaration'], // todo
|
|
24
|
-
// 'unified-signatures': false,
|
|
25
|
-
'variable-name': [
|
|
26
|
-
true,
|
|
27
|
-
'ban-keywords',
|
|
28
|
-
'check-format',
|
|
29
|
-
'allow-pascal-case',
|
|
30
|
-
'allow-leading-underscore',
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
linterOptions: {
|
|
34
|
-
exclude: ['src/**/__exclude/**/*'],
|
|
35
|
-
},
|
|
36
|
-
}
|
package/dist/bin/tslint-all.d.ts
DELETED
package/dist/bin/tslint-all.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
|
-
const tslint_all_command_1 = require("../cmd/tslint-all.command");
|
|
6
|
-
(0, script_1.runScript)(tslint_all_command_1.tslintAllCommand);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tslintAllCommand = void 0;
|
|
4
|
-
const tslint_util_1 = require("../util/tslint.util");
|
|
5
|
-
const { lintExclude } = require('../../cfg/_cnst');
|
|
6
|
-
/**
|
|
7
|
-
* Runs `tslint` command for all predefined paths (e.g /src, etc).
|
|
8
|
-
*/
|
|
9
|
-
async function tslintAllCommand() {
|
|
10
|
-
const projectSrcDir = `./src`;
|
|
11
|
-
const projectScriptsDir = `./scripts`;
|
|
12
|
-
const projectE2eDir = `./e2e`;
|
|
13
|
-
const tslintConfigPath = (0, tslint_util_1.getTSLintConfigPath)();
|
|
14
|
-
const tsconfigPath = (0, tslint_util_1.getTSConfigPath)();
|
|
15
|
-
const tsconfigPathScripts = (0, tslint_util_1.getTSConfigPathScripts)();
|
|
16
|
-
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
17
|
-
// /src
|
|
18
|
-
await (0, tslint_util_1.runTSLint)(projectSrcDir, lintExclude, tslintConfigPath);
|
|
19
|
-
await (0, tslint_util_1.runTSLint)(projectSrcDir, lintExclude, tslintConfigPath, tsconfigPath);
|
|
20
|
-
// /scripts
|
|
21
|
-
await (0, tslint_util_1.runTSLint)(projectScriptsDir, lintExclude, tslintConfigPath);
|
|
22
|
-
await (0, tslint_util_1.runTSLint)(projectScriptsDir, lintExclude, tslintConfigPath, tsconfigPathScripts);
|
|
23
|
-
// /e2e
|
|
24
|
-
await (0, tslint_util_1.runTSLint)(projectE2eDir, lintExclude, tslintConfigPath);
|
|
25
|
-
await (0, tslint_util_1.runTSLint)(projectE2eDir, lintExclude, tslintConfigPath, tsconfigPathE2e);
|
|
26
|
-
}
|
|
27
|
-
exports.tslintAllCommand = tslintAllCommand;
|