eslint-config-nodejs-pmb 0.2.4 → 0.2.8
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/.github/workflows/ci.yaml +30 -0
- package/depsHelper.js +9 -0
- package/devDepPatterns.js +12 -13
- package/package.json +15 -5
- package/rules.js +87 -14
- package/test/dump_as_json.mjs +16 -0
- package/test/expectedPeerDependencies.js +9 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
%YAML 1.1
|
|
2
|
+
# ^-- ATTN: [2019-12-31] If you use a later version, Github will fail
|
|
3
|
+
# with a bogus error message "You have an error in your yaml syntax".
|
|
4
|
+
# -*- coding: UTF-8, tab-width: 4 -*-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches:
|
|
10
|
+
- '*'
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
job_npm_test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
node-version:
|
|
18
|
+
- "16.x"
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v2
|
|
22
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
+
uses: actions/setup-node@v1
|
|
24
|
+
with:
|
|
25
|
+
node-version: ${{ matrix.node-version }}
|
|
26
|
+
- run: npm install .
|
|
27
|
+
- run: npm test
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
...
|
package/depsHelper.js
ADDED
package/devDepPatterns.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/* -*- tab-width: 2 -*- */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const devDirs = [
|
|
5
|
+
'build',
|
|
6
|
+
'test',
|
|
7
|
+
'tests',
|
|
8
|
+
];
|
|
5
9
|
|
|
6
|
-
const jsFexts = (function refine() {
|
|
7
|
-
let xt = new Set(instaffo.settings['import/extensions']);
|
|
8
|
-
xt.delete('.json');
|
|
9
|
-
xt = Array.from(xt);
|
|
10
|
-
return xt;
|
|
11
|
-
}());
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
function gen(how) {
|
|
12
|
+
const { jsFextsNoDot } = how;
|
|
13
|
+
const jsGlob = ('.{' + Array.from(jsFextsNoDot).join(',') + '}');
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
const nmSub = cwd.replace(/^\S+\/node_modules(?=\/)/, '…') + '/';
|
|
16
|
+
if (devDirs.find(d => nmSub.includes('/' + d + '/'))) { return ['**']; }
|
|
17
17
|
return [
|
|
18
|
-
'
|
|
19
|
-
'build/**',
|
|
18
|
+
...devDirs.map(d => d + '/**'),
|
|
20
19
|
'**{/,-,.}test{,s,/**}' + jsGlob,
|
|
21
20
|
'**.spec' + jsGlob,
|
|
22
21
|
'**/{,.}eslintrc.js{,on}',
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{ "name": "eslint-config-nodejs-pmb",
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.8",
|
|
3
3
|
"description": "My favorite eslint rules",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
|
|
@@ -16,16 +16,26 @@
|
|
|
16
16
|
|
|
17
17
|
"private": false, "license": "ISC",
|
|
18
18
|
"main": "rules.js",
|
|
19
|
-
"scripts": { "test": "
|
|
19
|
+
"scripts": { "test": "eslint --ext=js,mjs . && echo '+OK eslint succeeded.'" },
|
|
20
20
|
"directories": { "test": "test" },
|
|
21
|
+
"eslintConfig": { "extends": "." },
|
|
21
22
|
|
|
23
|
+
"engines": { "npm": ">=7.0.0", "node": ">=16.0.0" },
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"eslint": "^
|
|
25
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
26
|
+
"eslint-config-airbnb-base": "^15.0.0"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
29
|
+
"absdir": "^1.0.6",
|
|
30
|
+
"eslint-plugin-json-light": "^1.0.3",
|
|
31
|
+
"eslint-plugin-node": "^11.1.0",
|
|
32
|
+
"p-fatal": "^0.1.3",
|
|
33
|
+
"safe-sortedjson": "^1.0.6",
|
|
34
|
+
"usnam-pmb": "^0.2.5"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"eslint": "^8.10.0"
|
|
27
38
|
},
|
|
28
|
-
|
|
29
39
|
|
|
30
40
|
"npm vs. BOM = Unexpected token": "-*- coding: UTF-8 -*-"
|
|
31
41
|
}
|
package/rules.js
CHANGED
|
@@ -1,41 +1,70 @@
|
|
|
1
1
|
/* -*- tab-width: 2 -*- */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const configDeps = [
|
|
5
|
+
...require('./depsHelper.js'),
|
|
6
|
+
...require('./test/expectedPeerDependencies.js'),
|
|
7
|
+
];
|
|
8
|
+
const devDepPatternsGen = require('./devDepPatterns.js');
|
|
6
9
|
|
|
10
|
+
function uniq(a) { return Array.from(new Set(a)).sort(); }
|
|
11
|
+
|
|
12
|
+
const jsFextsNoDot = ['js', 'mjs'];
|
|
13
|
+
const devDepPatternsList = devDepPatternsGen.generate({ jsFextsNoDot });
|
|
7
14
|
const extraneousDepsOpts = {
|
|
8
|
-
devDependencies:
|
|
15
|
+
devDependencies: devDepPatternsList,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const importFextsNoDot = uniq([...jsFextsNoDot, 'json']);
|
|
19
|
+
const importFextsWithDots = importFextsNoDot.map(x => '.' + x);
|
|
20
|
+
const importSettings = {
|
|
21
|
+
'import/extensions': importFextsWithDots,
|
|
22
|
+
'import/resolver': {
|
|
23
|
+
node: { extensions: importFextsWithDots },
|
|
24
|
+
},
|
|
9
25
|
};
|
|
10
26
|
|
|
11
27
|
|
|
28
|
+
function mustStartWith(p) { return function d(s) { return s.startsWith(p); }; }
|
|
29
|
+
|
|
30
|
+
const lineLengthRules = {
|
|
31
|
+
code: 80,
|
|
32
|
+
ignoreRegExpLiterals: true,
|
|
33
|
+
ignoreTrailingComments: true,
|
|
34
|
+
ignoreUrls: true,
|
|
35
|
+
};
|
|
36
|
+
|
|
12
37
|
const rules = {
|
|
13
|
-
...instaffo.rules,
|
|
14
38
|
|
|
15
39
|
// rules docs: https://github.com/eslint/eslint.github.io/tree/master/docs/rules
|
|
16
40
|
|
|
41
|
+
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
|
|
17
42
|
'consistent-return': 'off',
|
|
43
|
+
'default-case': 'off',
|
|
18
44
|
'func-names': ['error', 'as-needed'],
|
|
45
|
+
'function-call-argument-newline': 'off',
|
|
19
46
|
'function-paren-newline': 'off',
|
|
47
|
+
'global-require': 'off', // deprecated, see 'node/global-require' instead.
|
|
48
|
+
'import/no-extraneous-dependencies': ['error', extraneousDepsOpts],
|
|
49
|
+
'key-spacing': 'off', // b/c it doesn't support all the combinations I want
|
|
20
50
|
'lines-around-directive': 'off',
|
|
51
|
+
'max-len': ['error', lineLengthRules],
|
|
21
52
|
'no-console': 'off',
|
|
53
|
+
'no-control-regex': 'off',
|
|
54
|
+
'node/global-require': 'off', // I'd rather exempt just top-level arrays
|
|
55
|
+
'no-div-regex': 'error',
|
|
22
56
|
'no-extra-semi': 'off',
|
|
23
57
|
'no-multiple-empty-lines': 'off',
|
|
24
58
|
'no-multi-spaces': ['off', { ignoreEOLComments: true }],
|
|
59
|
+
'no-useless-escape': 'off', // allow \. in RegExp char group
|
|
25
60
|
'object-curly-newline': 'off',
|
|
61
|
+
'padded-blocks': 'off',
|
|
26
62
|
'prefer-arrow-callback': 'off',
|
|
27
63
|
'prefer-template': 'off',
|
|
64
|
+
'quote-props': 'off',
|
|
28
65
|
'semi': ['error', 'always'],
|
|
66
|
+
'strict': ['error', 'safe'],
|
|
29
67
|
'unicode-bom': 'off',
|
|
30
|
-
'no-control-regex': 'off',
|
|
31
|
-
'no-useless-escape': 'off', // allow \. in RegExp char group
|
|
32
|
-
'no-div-regex': 'error',
|
|
33
|
-
'quote-props': 'off',
|
|
34
|
-
'default-case': 'off',
|
|
35
|
-
'key-spacing': 'off', // b/c it doesn't support all the combinations I want
|
|
36
|
-
'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
|
|
37
|
-
'import/no-extraneous-dependencies': ['error', extraneousDepsOpts],
|
|
38
|
-
'padded-blocks': 'off',
|
|
39
68
|
|
|
40
69
|
// Ugly but unfortunately node v12+ native ESM forces us to:
|
|
41
70
|
'import/extensions': ['error', 'ignorePackages'],
|
|
@@ -44,9 +73,53 @@ const rules = {
|
|
|
44
73
|
};
|
|
45
74
|
|
|
46
75
|
|
|
76
|
+
const overrides = [
|
|
77
|
+
{ files: ['**.js'], parserOptions: { sourceType: 'script' } },
|
|
78
|
+
{ files: ['**.mjs'],
|
|
79
|
+
rules: {
|
|
80
|
+
'node/no-unsupported-features/es-syntax': 'off', // assume esmod-pmb
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{ files: devDepPatternsList,
|
|
84
|
+
rules: {
|
|
85
|
+
'node/no-unpublished-import': 'off',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
|
|
47
91
|
const config = {
|
|
48
|
-
|
|
92
|
+
|
|
93
|
+
env: {
|
|
94
|
+
es6: true,
|
|
95
|
+
node: true,
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
extends: [
|
|
99
|
+
...[
|
|
100
|
+
...configDeps.filter(mustStartWith('eslint-config-')),
|
|
101
|
+
].map(require.resolve),
|
|
102
|
+
'plugin:node/recommended',
|
|
103
|
+
],
|
|
104
|
+
|
|
105
|
+
overrides,
|
|
106
|
+
|
|
107
|
+
parser: require.resolve('@babel/eslint-parser'),
|
|
108
|
+
parserOptions: {
|
|
109
|
+
allowImportExportEverywhere: true,
|
|
110
|
+
requireConfigFile: false,
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
plugins: [
|
|
114
|
+
...configDeps.filter(mustStartWith('eslint-plugin-')),
|
|
115
|
+
],
|
|
116
|
+
|
|
49
117
|
rules,
|
|
118
|
+
|
|
119
|
+
settings: {
|
|
120
|
+
...importSettings,
|
|
121
|
+
},
|
|
122
|
+
|
|
50
123
|
};
|
|
51
124
|
|
|
52
125
|
module.exports = config;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// -*- coding: utf-8, tab-width: 2 -*-
|
|
2
|
+
|
|
3
|
+
import 'p-fatal';
|
|
4
|
+
import 'usnam-pmb';
|
|
5
|
+
|
|
6
|
+
import absdir from 'absdir';
|
|
7
|
+
import jsonify from 'safe-sortedjson';
|
|
8
|
+
|
|
9
|
+
import rules from '../rules.js';
|
|
10
|
+
|
|
11
|
+
const nmPath = absdir(import.meta, '../..')('.') + '/';
|
|
12
|
+
|
|
13
|
+
let json = jsonify(rules);
|
|
14
|
+
json = json.split(nmPath).join('nm://');
|
|
15
|
+
|
|
16
|
+
console.log(json);
|