@cookshack/eslint-config 4.0.0 → 5.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.
- package/AGENTS.md +12 -0
- package/dist/index.cjs +6 -5
- package/dist/index.js +6 -5
- package/index.js +1 -0
- package/package.json +1 -1
- package/plugins/init-before-use.js +6 -6
- package/test/rules/no-shadow.js +42 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
- `dist/` is gitignored and must be rebuilt after source changes: `npm run prepare` (runs husky + rollup)
|
|
4
|
+
- Self-lint: `npm run check` (uses this config to lint itself)
|
|
5
|
+
- Tests: `npm test` (mocha, `test/**/*.js`)
|
|
6
|
+
- Pre-commit hook runs `npm run check && npm test`
|
|
7
|
+
- Custom ESLint rules live in `plugins/` and are wired into the config via `index.js`
|
|
8
|
+
- Each plugin has a corresponding test file in `test/rules/` with the same name
|
|
9
|
+
- Tests use ESLint's `Linter` API directly; many test the print buffer output via `getPrintBuffer()`
|
|
10
|
+
- `plugins/narrowest-scope.js` has extensive analysis docs in `A1.md` through `A7.md`
|
|
11
|
+
- Rollup bundles `index.js` and `formatter.js` into `dist/` as both ESM (`.js`) and CJS (`.cjs`); `globals` is external
|
|
12
|
+
- Package is ESM (`"type": "module"`) but ships dual format via the `exports` field
|
package/dist/index.cjs
CHANGED
|
@@ -482,10 +482,10 @@ var alwaysLetPlugin = { meta: { type: 'problem',
|
|
|
482
482
|
schema: [] },
|
|
483
483
|
create: create$4 };
|
|
484
484
|
|
|
485
|
-
let ostIdCounter,
|
|
485
|
+
let ostIdCounter, $lastOst;
|
|
486
486
|
|
|
487
487
|
ostIdCounter = 0;
|
|
488
|
-
|
|
488
|
+
$lastOst = 0;
|
|
489
489
|
|
|
490
490
|
function trace$1
|
|
491
491
|
(...args) {
|
|
@@ -506,11 +506,11 @@ function createInitBeforeUse
|
|
|
506
506
|
buildScopeTree(scopeManager.scopes[0], '1', scopeToNode, astToTree);
|
|
507
507
|
|
|
508
508
|
ostIdCounter = 0;
|
|
509
|
-
|
|
509
|
+
$lastOst = processAst(context.sourceCode.ast, null, astToTree, astToOst, '', new Set());
|
|
510
510
|
|
|
511
|
-
ostAnnotate(
|
|
511
|
+
ostAnnotate($lastOst, astToOst, context);
|
|
512
512
|
|
|
513
|
-
ostCheck(
|
|
513
|
+
ostCheck($lastOst, context);
|
|
514
514
|
} }
|
|
515
515
|
}
|
|
516
516
|
|
|
@@ -1101,6 +1101,7 @@ exports.rules = { 'array-bracket-newline': [ 'error', 'never' ],
|
|
|
1101
1101
|
'no-negated-condition': 'error',
|
|
1102
1102
|
'no-redeclare': 'error',
|
|
1103
1103
|
'no-sequences': 'error',
|
|
1104
|
+
'no-shadow': [ 'error', { builtinGlobals: true } ],
|
|
1104
1105
|
'no-sparse-arrays': 'error',
|
|
1105
1106
|
'no-tabs': 'error',
|
|
1106
1107
|
'no-trailing-spaces': 'error',
|
package/dist/index.js
CHANGED
|
@@ -478,10 +478,10 @@ var alwaysLetPlugin = { meta: { type: 'problem',
|
|
|
478
478
|
schema: [] },
|
|
479
479
|
create: create$4 };
|
|
480
480
|
|
|
481
|
-
let ostIdCounter,
|
|
481
|
+
let ostIdCounter, $lastOst;
|
|
482
482
|
|
|
483
483
|
ostIdCounter = 0;
|
|
484
|
-
|
|
484
|
+
$lastOst = 0;
|
|
485
485
|
|
|
486
486
|
function trace$1
|
|
487
487
|
(...args) {
|
|
@@ -502,11 +502,11 @@ function createInitBeforeUse
|
|
|
502
502
|
buildScopeTree(scopeManager.scopes[0], '1', scopeToNode, astToTree);
|
|
503
503
|
|
|
504
504
|
ostIdCounter = 0;
|
|
505
|
-
|
|
505
|
+
$lastOst = processAst(context.sourceCode.ast, null, astToTree, astToOst, '', new Set());
|
|
506
506
|
|
|
507
|
-
ostAnnotate(
|
|
507
|
+
ostAnnotate($lastOst, astToOst, context);
|
|
508
508
|
|
|
509
|
-
ostCheck(
|
|
509
|
+
ostCheck($lastOst, context);
|
|
510
510
|
} }
|
|
511
511
|
}
|
|
512
512
|
|
|
@@ -1097,6 +1097,7 @@ rules = { 'array-bracket-newline': [ 'error', 'never' ],
|
|
|
1097
1097
|
'no-negated-condition': 'error',
|
|
1098
1098
|
'no-redeclare': 'error',
|
|
1099
1099
|
'no-sequences': 'error',
|
|
1100
|
+
'no-shadow': [ 'error', { builtinGlobals: true } ],
|
|
1100
1101
|
'no-sparse-arrays': 'error',
|
|
1101
1102
|
'no-tabs': 'error',
|
|
1102
1103
|
'no-trailing-spaces': 'error',
|
package/index.js
CHANGED
|
@@ -67,6 +67,7 @@ rules = { 'array-bracket-newline': [ 'error', 'never' ],
|
|
|
67
67
|
'no-negated-condition': 'error',
|
|
68
68
|
'no-redeclare': 'error',
|
|
69
69
|
'no-sequences': 'error',
|
|
70
|
+
'no-shadow': [ 'error', { builtinGlobals: true } ],
|
|
70
71
|
'no-sparse-arrays': 'error',
|
|
71
72
|
'no-tabs': 'error',
|
|
72
73
|
'no-trailing-spaces': 'error',
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { buildScopeTree } from './narrowest-scope.js'
|
|
2
2
|
|
|
3
|
-
let ostIdCounter, errorCount,
|
|
3
|
+
let ostIdCounter, errorCount, $lastOst
|
|
4
4
|
|
|
5
5
|
ostIdCounter = 0
|
|
6
6
|
errorCount = 0
|
|
7
|
-
|
|
7
|
+
$lastOst = 0
|
|
8
8
|
|
|
9
9
|
function trace
|
|
10
10
|
(...args) {
|
|
@@ -15,7 +15,7 @@ function trace
|
|
|
15
15
|
export
|
|
16
16
|
function lastOst
|
|
17
17
|
() {
|
|
18
|
-
return
|
|
18
|
+
return $lastOst
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function createInitBeforeUse
|
|
@@ -35,11 +35,11 @@ function createInitBeforeUse
|
|
|
35
35
|
buildScopeTree(scopeManager.scopes[0], '1', scopeToNode, astToTree)
|
|
36
36
|
|
|
37
37
|
ostIdCounter = 0
|
|
38
|
-
|
|
38
|
+
$lastOst = processAst(context.sourceCode.ast, null, astToTree, astToOst, '', new Set())
|
|
39
39
|
|
|
40
|
-
ostAnnotate(
|
|
40
|
+
ostAnnotate($lastOst, astToOst, context)
|
|
41
41
|
|
|
42
|
-
ostCheck(
|
|
42
|
+
ostCheck($lastOst, context)
|
|
43
43
|
|
|
44
44
|
trace('ERRORS: ' + errorCount)
|
|
45
45
|
} }
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint'
|
|
2
|
+
import { Linter } from 'eslint'
|
|
3
|
+
|
|
4
|
+
let ruleTester, validCases, invalidCases, rule
|
|
5
|
+
|
|
6
|
+
rule = new Linter({ configType: 'eslintrc' }).getRules().get('no-shadow')
|
|
7
|
+
ruleTester = new RuleTester()
|
|
8
|
+
validCases = []
|
|
9
|
+
invalidCases = []
|
|
10
|
+
|
|
11
|
+
function pass
|
|
12
|
+
(code) {
|
|
13
|
+
validCases.push({ code, options: [ { builtinGlobals: true } ] })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fail
|
|
17
|
+
(messageId, code) {
|
|
18
|
+
invalidCases.push({ code,
|
|
19
|
+
options: [ { builtinGlobals: true } ],
|
|
20
|
+
errors: [ { messageId } ] })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
pass('var a = 3; function b() { var c = 10; }')
|
|
24
|
+
pass('let x = 1; { let y = 2; }')
|
|
25
|
+
pass('function a() { let x = 1 } function b() { let x = 2 }')
|
|
26
|
+
pass('var a = 1; if (x) { var a = 2; }')
|
|
27
|
+
|
|
28
|
+
fail('noShadow', 'var a = 3; function b() { var a = 10; }')
|
|
29
|
+
fail('noShadow', 'let x = 1; { let x = 2; }')
|
|
30
|
+
fail('noShadow', 'let a = 1; function foo(a) { return a }')
|
|
31
|
+
fail('noShadow', 'function f(x) { function g() { let x = 2; } }')
|
|
32
|
+
fail('noShadow', 'const a = 1; function foo() { const a = 2; }')
|
|
33
|
+
fail('noShadow', 'let a = 1; if (x) { let a = 2; }')
|
|
34
|
+
|
|
35
|
+
fail('noShadowGlobal', 'function foo() { let Object = 1; }')
|
|
36
|
+
fail('noShadowGlobal', 'function foo() { let Array = []; }')
|
|
37
|
+
|
|
38
|
+
globalThis.describe('no-shadow',
|
|
39
|
+
() => ruleTester.run('no-shadow',
|
|
40
|
+
rule,
|
|
41
|
+
{ valid: validCases,
|
|
42
|
+
invalid: invalidCases }))
|