eslint-config-nodejs-pmb 0.2.5 → 0.2.7

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.
@@ -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
@@ -0,0 +1,9 @@
1
+ /* -*- tab-width: 2 -*- */
2
+ 'use strict';
3
+
4
+ module.exports = (function depsHelper(require) {
5
+ return [
6
+ require('@babel/eslint-parser'),
7
+ require('eslint-config-airbnb-base'),
8
+ ];
9
+ }(String));
package/devDepPatterns.js CHANGED
@@ -1,17 +1,6 @@
1
1
  /* -*- tab-width: 2 -*- */
2
2
  'use strict';
3
3
 
4
- const instaffo = require('@instaffogmbh/eslint-config-nodejs/rules.js');
5
-
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
-
13
- const jsGlob = ('.{' + jsFexts.map(s => s.replace(/^\./, '')).join(',') + '}');
14
-
15
4
  const devDirs = [
16
5
  'build',
17
6
  'test',
@@ -19,7 +8,9 @@ const devDirs = [
19
8
  ];
20
9
 
21
10
 
22
- function gen() {
11
+ function gen(how) {
12
+ const { jsFextsNoDot } = how;
13
+ const jsGlob = ('.{' + Array.from(jsFextsNoDot).join(',') + '}');
23
14
  const cwd = process.cwd();
24
15
  const nmSub = cwd.replace(/^\S+\/node_modules(?=\/)/, '…') + '/';
25
16
  if (devDirs.find(d => nmSub.includes('/' + d + '/'))) { return ['**']; }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "eslint-config-nodejs-pmb",
2
- "version": "0.2.5",
2
+ "version": "0.2.7",
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": "nodejs test/all.js" },
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
- "@instaffogmbh/eslint-config-nodejs": "^1.2.8",
24
- "eslint": "^7.32.0"
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 instaffo = require('@instaffogmbh/eslint-config-nodejs/rules');
5
- const devDepPatterns = require('./devDepPatterns.js');
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: devDepPatterns.generate(),
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'],
@@ -45,8 +74,44 @@ const rules = {
45
74
 
46
75
 
47
76
  const config = {
48
- ...instaffo,
77
+
78
+ env: {
79
+ es6: true,
80
+ node: true,
81
+ },
82
+
83
+ extends: [
84
+ ...[
85
+ ...configDeps.filter(mustStartWith('eslint-config-')),
86
+ ].map(require.resolve),
87
+ 'plugin:node/recommended',
88
+ ],
89
+
90
+ overrides: [
91
+ { files: ['**.js'], parserOptions: { sourceType: 'script' } },
92
+ { files: devDepPatternsList,
93
+ rules: {
94
+ 'node/no-unpublished-import': 'off',
95
+ },
96
+ },
97
+ ],
98
+
99
+ parser: require.resolve('@babel/eslint-parser'),
100
+ parserOptions: {
101
+ allowImportExportEverywhere: true,
102
+ requireConfigFile: false,
103
+ },
104
+
105
+ plugins: [
106
+ ...configDeps.filter(mustStartWith('eslint-plugin-')),
107
+ ],
108
+
49
109
  rules,
110
+
111
+ settings: {
112
+ ...importSettings,
113
+ },
114
+
50
115
  };
51
116
 
52
117
  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);
@@ -0,0 +1,9 @@
1
+ /* -*- tab-width: 2 -*- */
2
+ 'use strict';
3
+
4
+ module.exports = (function depsHelper(require) {
5
+ return [
6
+ require('eslint-plugin-json-light'),
7
+ require('eslint-plugin-node'),
8
+ ];
9
+ }(String));