Skip to content

Commit fe1dbb3

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 c3c02ec commit fe1dbb3

File tree

23 files changed

+280
-246
lines changed

23 files changed

+280
-246
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: 53 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,33 @@ 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;
47+
var config;
48+
49+
linter = new Linter({
50+
'configType': 'eslintrc'
51+
});
52+
linter.defineRule( 'jsdoc-markdown-remark', rule );
53+
config = {
54+
'rules': {
55+
'jsdoc-markdown-remark': [ 'error' ].concat( options || [] )
56+
}
57+
};
58+
return linter.verify( code, config );
59+
}
60+
61+
3562
// TESTS //
3663

3764
tape( 'main export is an object', function test( t ) {
@@ -41,46 +68,41 @@ tape( 'main export is an object', function test( t ) {
4168
});
4269

4370
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 );
71+
var messages;
72+
var tc;
73+
var i;
74+
75+
for ( i = 0; i < valid.length; i++ ) {
76+
tc = valid[ i ];
77+
messages = lintCode( tc.code, tc.options );
78+
t.strictEqual( messages.length, 0, 'valid test case '+i+' has no errors' );
5479
}
5580
t.end();
5681
});
5782

5883
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 );
84+
var messages;
85+
var tc;
86+
var i;
87+
88+
for ( i = 0; i < invalid.length; i++ ) {
89+
tc = invalid[ i ];
90+
messages = lintCode( tc.code, tc.options );
91+
t.ok( messages.length > 0, 'invalid test case '+i+' has errors' );
92+
t.strictEqual( messages.length, tc.errors.length, 'invalid test case '+i+' has expected number of errors' );
6993
}
7094
t.end();
7195
});
7296

7397
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 );
98+
var messages;
99+
var tc;
100+
var i;
101+
102+
for ( i = 0; i < unvalidated.length; i++ ) {
103+
tc = unvalidated[ i ];
104+
messages = lintCode( tc.code, tc.options );
105+
t.strictEqual( messages.length, 0, 'unvalidated test case '+i+' has no errors' );
84106
}
85107
t.end();
86108
});

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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ test = {
110110
'type': 'ExportNamedDeclaration'
111111
}
112112
],
113-
'parserOptions': {
114-
'ecmaVersion': 6,
115-
'sourceType': 'module'
113+
'languageOptions': {
114+
'parserOptions': {
115+
'ecmaVersion': 6,
116+
'sourceType': 'module'
117+
}
116118
}
117119
};
118120
invalid.push( test );
@@ -131,9 +133,11 @@ test = {
131133
'type': 'ExportNamedDeclaration'
132134
}
133135
],
134-
'parserOptions': {
135-
'ecmaVersion': 6,
136-
'sourceType': 'module'
136+
'languageOptions': {
137+
'parserOptions': {
138+
'ecmaVersion': 6,
139+
'sourceType': 'module'
140+
}
137141
}
138142
};
139143
invalid.push( test );

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ test = {
5151
'',
5252
'export { gamma };'
5353
].join( '\n' ),
54-
'parserOptions': {
55-
'ecmaVersion': 6,
56-
'sourceType': 'module'
54+
'languageOptions': {
55+
'parserOptions': {
56+
'ecmaVersion': 6,
57+
'sourceType': 'module'
58+
}
5759
}
5860
};
5961
valid.push( test );
@@ -64,9 +66,11 @@ test = {
6466
'export const beep = 0;',
6567
'export default boop;'
6668
].join( '\n' ),
67-
'parserOptions': {
68-
'ecmaVersion': 6,
69-
'sourceType': 'module'
69+
'languageOptions': {
70+
'parserOptions': {
71+
'ecmaVersion': 6,
72+
'sourceType': 'module'
73+
}
7074
}
7175
};
7276
valid.push( test );

0 commit comments

Comments
 (0)