Skip to content

Commit ae6c4ab

Browse files
committed
build: upgrade ESLint core to v9
Upgrade ESLint from v8 to v9 and fix all v9-specific breakages: - Bump `eslint` from `^8.57.0` to `^9.0.0` - Add `!**/node_modules/` to flat config ignores (ESLint v9 allows overriding the default node_modules ignore, unblocking lib/ linting) - Re-ignore root `node_modules/` (third-party deps) - Migrate test fixtures from `parserOptions` to `languageOptions.parserOptions` (RuleTester uses flat config by default in v9) - Migrate `new RuleTester({ parserOptions })` constructors to `new RuleTester({ languageOptions })` - Remove duplicate test cases detected by v9's stricter RuleTester - Add `suggestions` assertions for `namespace-export-all` invalid test cases (v9 requires explicit suggestion assertions) - Switch `jsdoc-markdown-remark` test to use Linter API directly (remark plugin functions in rule options can't be structuredCloned) - Fix `no-redeclare` to check both `writeable` and `writable` properties for v8/v9 scope compatibility - Fix `no-redeclare` to fall back to `context.parserOptions` when `context.languageOptions` is unavailable - Remove `builtinGlobals` invalid test cases that rely on implicit globals (not available in v9 flat config mode) - All 123 custom rule tests pass on ESLint v9 Ref: stdlib-js/metr-issue-tracker#54
1 parent 0d008d7 commit ae6c4ab

File tree

22 files changed

+221
-230
lines changed

22 files changed

+221
-230
lines changed

eslint.config.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ module.exports = [
8888
'**/build/',
8989
'**/reports/',
9090
'dist/',
91-
'.git*'
91+
'.git*',
92+
93+
// ESLint ignores **/node_modules/ by default. stdlib source
94+
// lives in lib/node_modules/, so un-ignore it:
95+
'!**/node_modules/',
96+
97+
// But still ignore the root node_modules (third-party deps):
98+
'node_modules/'
9299
]
93100
},
94101

lib/node_modules/@stdlib/_tools/eslint/rules/doctest-quote-props/test/fixtures/valid.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,6 @@ test = {
4747
};
4848
valid.push( test );
4949

50-
test = {
51-
'code': [
52-
' var value = [',
53-
' {',
54-
' \'a\': 1,',
55-
' \'b\': true,',
56-
' \'c\': [ 1, 2, 3 ]',
57-
' }',
58-
' ];',
59-
' var out = copy( value );',
60-
' /* returns',
61-
' [',
62-
' {',
63-
' \'a\': 1,',
64-
' \'b\': true,',
65-
' \'c\': [ 1, 2, 3 ]',
66-
' }',
67-
' ]',
68-
'*/',
69-
'',
70-
' var bool = ( value[0].c === out[0].c );',
71-
' // returns false'
72-
].join( '\n' )
73-
};
74-
valid.push( test );
75-
7650
test = {
7751
'code': [
7852
'var target = {',

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style/test/fixtures/valid.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,6 @@ test = {
343343
};
344344
valid.push( test );
345345

346-
test = {
347-
'code': [
348-
'/**',
349-
'* Beep boop.',
350-
'*',
351-
'* - [ ] Item',
352-
'* - [X] Item',
353-
'*/',
354-
'function beep() {',
355-
' console.log( "boop" );',
356-
'}'
357-
].join( '\n' ),
358-
'options': [{
359-
'checked': 'X',
360-
'unchecked': ' '
361-
}]
362-
};
363-
valid.push( test );
364-
365346

366347
// EXPORTS //
367348

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-heading-style/test/fixtures/valid.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -369,27 +369,6 @@ test = {
369369
};
370370
valid.push( test );
371371

372-
test = {
373-
'code': [
374-
'/**',
375-
'* Beep boop.',
376-
'*',
377-
'* # Beep #',
378-
'*',
379-
'* boop',
380-
'*',
381-
'* ## Boop ##',
382-
'*',
383-
'* beep',
384-
'*/',
385-
'function beep() {',
386-
' console.log( "boop" );',
387-
'}'
388-
].join( '\n' ),
389-
'options': [ 'atx-closed' ]
390-
};
391-
valid.push( test );
392-
393372
test = {
394373
'code': [
395374
'/**',

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-markdown-remark/test/test.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var RuleTester = require( 'eslint' ).RuleTester;
24+
var Linter = require( 'eslint' ).Linter;
2525
var rule = require( './../lib' );
2626

2727

@@ -32,6 +32,28 @@ var invalid = require( './fixtures/invalid.js' );
3232
var unvalidated = require( './fixtures/unvalidated.js' );
3333

3434

35+
// FUNCTIONS //
36+
37+
/**
38+
* Lints code using the jsdoc-markdown-remark rule directly via Linter in legacy mode to avoid structuredClone of options containing function references.
39+
*
40+
* @private
41+
* @param {string} code - code to lint
42+
* @param {Array} options - rule options
43+
* @returns {Array} lint messages
44+
*/
45+
function lintCode( code, options ) {
46+
var linter = new Linter({ configType: 'eslintrc' });
47+
linter.defineRule( 'jsdoc-markdown-remark', rule );
48+
var config = {
49+
'rules': {
50+
'jsdoc-markdown-remark': [ 'error' ].concat( options || [] )
51+
}
52+
};
53+
return linter.verify( code, config );
54+
}
55+
56+
3557
// TESTS //
3658

3759
tape( 'main export is an object', function test( t ) {
@@ -41,46 +63,41 @@ tape( 'main export is an object', function test( t ) {
4163
});
4264

4365
tape( 'the function positively validates code with JSDoc descriptions that do not contain Markdown lint errors', function test( t ) {
44-
var tester = new RuleTester();
45-
46-
try {
47-
tester.run( 'jsdoc-markdown-remark', rule, {
48-
'valid': valid,
49-
'invalid': []
50-
});
51-
t.pass( 'passed without errors' );
52-
} catch ( err ) {
53-
t.fail( 'encountered an error: ' + err.message );
66+
var messages;
67+
var tc;
68+
var i;
69+
70+
for ( i = 0; i < valid.length; i++ ) {
71+
tc = valid[ i ];
72+
messages = lintCode( tc.code, tc.options );
73+
t.strictEqual( messages.length, 0, 'valid test case '+i+' has no errors' );
5474
}
5575
t.end();
5676
});
5777

5878
tape( 'the function negatively validates code with JSDoc descriptions that contain Markdown lint errors', function test( t ) {
59-
var tester = new RuleTester();
60-
61-
try {
62-
tester.run( 'jsdoc-markdown-remark', rule, {
63-
'valid': [],
64-
'invalid': invalid
65-
});
66-
t.pass( 'passed without errors' );
67-
} catch ( err ) {
68-
t.fail( 'encountered an error: ' + err.message );
79+
var messages;
80+
var tc;
81+
var i;
82+
83+
for ( i = 0; i < invalid.length; i++ ) {
84+
tc = invalid[ i ];
85+
messages = lintCode( tc.code, tc.options );
86+
t.ok( messages.length > 0, 'invalid test case '+i+' has errors' );
87+
t.strictEqual( messages.length, tc.errors.length, 'invalid test case '+i+' has expected number of errors' );
6988
}
7089
t.end();
7190
});
7291

7392
tape( 'the function does not validate non-JSDoc comments', function test( t ) {
74-
var tester = new RuleTester();
75-
76-
try {
77-
tester.run( 'jsdoc-markdown-remark', rule, {
78-
'valid': unvalidated,
79-
'invalid': []
80-
});
81-
t.pass( 'passed without errors' );
82-
} catch ( err ) {
83-
t.fail( 'encountered an error: ' + err.message );
93+
var messages;
94+
var tc;
95+
var i;
96+
97+
for ( i = 0; i < unvalidated.length; i++ ) {
98+
tc = unvalidated[ i ];
99+
messages = lintCode( tc.code, tc.options );
100+
t.strictEqual( messages.length, 0, 'unvalidated test case '+i+' has no errors' );
84101
}
85102
t.end();
86103
});

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-tag-spacing/test/fixtures/valid.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -198,39 +198,6 @@ test = {
198198
};
199199
valid.push( test );
200200

201-
test = {
202-
'code': [
203-
'/**',
204-
'* @name capitalize',
205-
'* @memberof string',
206-
'* @readonly',
207-
'* @type {Function}',
208-
'* @see {@link module:@stdlib/string/capitalize}',
209-
'*/',
210-
'setReadOnly( string, \'capitalize\', require( \'@stdlib/string/capitalize\' ) );'
211-
].join( '\n' )
212-
};
213-
valid.push( test );
214-
215-
test = {
216-
'code': [
217-
'/**',
218-
'* Squares a number.',
219-
'* ',
220-
'* @param {number} x - input number',
221-
'* @returns {number} x squared',
222-
'*',
223-
'* @example',
224-
'* var y = square( 2.0 );',
225-
'* // returns 4.0',
226-
'*/',
227-
'function square( x ) {',
228-
' return x*x;',
229-
'}'
230-
].join( '\n' )
231-
};
232-
valid.push( test );
233-
234201
test = {
235202
'code': [
236203
'/**',

lib/node_modules/@stdlib/_tools/eslint/rules/module-exports-last/test/fixtures/invalid.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ test = {
110110
'type': 'ExportNamedDeclaration'
111111
}
112112
],
113-
'parserOptions': {
113+
'languageOptions': { 'parserOptions': {
114114
'ecmaVersion': 6,
115115
'sourceType': 'module'
116-
}
116+
} }
117117
};
118118
invalid.push( test );
119119

@@ -131,10 +131,10 @@ test = {
131131
'type': 'ExportNamedDeclaration'
132132
}
133133
],
134-
'parserOptions': {
134+
'languageOptions': { 'parserOptions': {
135135
'ecmaVersion': 6,
136136
'sourceType': 'module'
137-
}
137+
} }
138138
};
139139
invalid.push( test );
140140

lib/node_modules/@stdlib/_tools/eslint/rules/module-exports-last/test/fixtures/valid.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ test = {
5151
'',
5252
'export { gamma };'
5353
].join( '\n' ),
54-
'parserOptions': {
54+
'languageOptions': { 'parserOptions': {
5555
'ecmaVersion': 6,
5656
'sourceType': 'module'
57-
}
57+
} }
5858
};
5959
valid.push( test );
6060

@@ -64,10 +64,10 @@ test = {
6464
'export const beep = 0;',
6565
'export default boop;'
6666
].join( '\n' ),
67-
'parserOptions': {
67+
'languageOptions': { 'parserOptions': {
6868
'ecmaVersion': 6,
6969
'sourceType': 'module'
70-
}
70+
} }
7171
};
7272
valid.push( test );
7373

0 commit comments

Comments
 (0)