Skip to content

Commit 485bf9b

Browse files
committed
bench: migrate custom ESLint rules to modern APIs
Replace deprecated ESLint rule APIs with their modern equivalents to prepare for the ESLint v9 migration (see [1][2]): - `context.getSourceCode()` → `context.sourceCode` (100 files) - `context.getScope()` → `sourceCode.getScope(node)` (4 files) The `context.getSourceCode()` method was deprecated in ESLint v8.40.0 in favor of the `context.sourceCode` property. The `context.getScope()` method was deprecated in ESLint v8.38.0 in favor of `sourceCode.getScope(node)`, which takes an explicit node argument rather than relying on implicit traversal state. For `no-builtin-big-int`, the scope acquisition was moved from the `create` function (which previously captured the global scope once) into the `CallExpression` visitor, and `isImportedBigInt` was updated to walk up the scope chain to find `BigInt` declarations in outer scopes. Also fixes pre-existing lint violations in touched files: - Move `copyLocationInfo`, `locationInfo`, `checkComment`, `extractPackagePath`, `getAlias`, and `sortExpressions` from nested functions to module scope - Replace `.toUpperCase()`, `.toLowerCase()`, `.trim()` with stdlib equivalents - Fix variable declaration ordering No other deprecated APIs (`context.getAncestors`, `context.getDeclaredVariables`, `context.markVariableAsUsed`, deprecated comment/token access patterns) were found in the codebase. All rules with `context.options` already have proper `meta.schema`. [1]: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/ [2]: https://eslint.org/docs/latest/use/migrate-to-9.0.0 Ref: stdlib-js/metr-issue-tracker#54 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 51981c7 commit 485bf9b

File tree

103 files changed

+1214
-1198
lines changed
  • lib/node_modules/@stdlib/_tools/eslint

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1214
-1198
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/capitalized-comments/lib/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var isCapitalized = require( '@stdlib/assert/is-capitalized' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var uppercase = require( '@stdlib/string/base/uppercase' );
2526
var ltrim = require( '@stdlib/string/left-trim' );
2627
var copy = require( '@stdlib/utils/copy' );
2728
var DEFAULTS = require( './defaults.json' );
@@ -57,7 +58,7 @@ function main( context ) {
5758
if ( hasOwnProp( options, 'whitelist' ) ) {
5859
opts.whitelist = options.whitelist.slice();
5960
}
60-
source = context.getSourceCode();
61+
source = context.sourceCode;
6162
visited = {};
6263

6364
/**
@@ -89,7 +90,7 @@ function main( context ) {
8990

9091
str = source.getText( comment );
9192
idx = str.search( /[a-zA-Z]/ );
92-
ch = str.charAt( idx ).toUpperCase();
93+
ch = uppercase( str.charAt( idx ) );
9394
replacement = str.slice( 0, idx ) + ch + str.slice( idx+1 );
9495
return fixer.replaceText( comment, replacement );
9596
}
@@ -194,7 +195,7 @@ function main( context ) {
194195
var i;
195196

196197
comments = source.getCommentsInside( node );
197-
scope = context.getScope( node );
198+
scope = source.getScope( node );
198199
for ( i = 0; i < comments.length; i++ ) {
199200
comment = comments[ i ];
200201
if ( comment.type !== 'Shebang' && !visited[ comment.range ] ) {

lib/node_modules/@stdlib/_tools/eslint/rules/doctest-annotation-spacing/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var rule;
6666
* @returns {Object} validators
6767
*/
6868
function main( context ) {
69-
var source = context.getSourceCode();
69+
var source = context.sourceCode;
7070

7171
/**
7272
* Reports the error message.

lib/node_modules/@stdlib/_tools/eslint/rules/doctest-marker/lib/main.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,66 @@ var rule;
3131

3232
// FUNCTIONS //
3333

34+
/**
35+
* Checks whether a comment is a return annotation and, if so, whether it follows marker style conventions.
36+
*
37+
* @private
38+
* @param {string} comment - comment to examine
39+
* @param {ASTNode} ast - node to examine
40+
* @param {integer} offset - non-zero if previous line ends with a comment
41+
* @returns {(string|null)} error message or null
42+
*/
43+
function checkComment( comment, ast, offset ) {
44+
var matches;
45+
var node;
46+
var prev;
47+
var type;
48+
49+
matches = comment.value.match( RE_ANNOTATION );
50+
if ( matches ) {
51+
offset += 1 + comment.loc.start.column;
52+
prev = walk.findNodeAt( ast, null, comment.start-offset );
53+
type = matches[ 1 ];
54+
if ( !prev ) {
55+
// Handle case when comment refers to node on the same line:
56+
if ( walk.findNodeAt( ast, null, comment.start-1 ) ) {
57+
return null;
58+
}
59+
return 'Encountered an orphaned return annotation without a preceding node';
60+
}
61+
node = prev.node;
62+
switch ( type ) {
63+
case 'returns':
64+
if (
65+
node.type !== 'VariableDeclaration' &&
66+
( node.type !== 'ExpressionStatement' || node.expression.type !== 'AssignmentExpression' )
67+
) {
68+
return 'Only include `// returns` after variable declarations or assignment expressions (use `=>` after `console.log`)';
69+
}
70+
break;
71+
case '=>':
72+
if (
73+
node.type === 'VariableDeclaration' ||
74+
( node.type === 'ExpressionStatement' && node.expression === 'AssignmentExpression' )
75+
) {
76+
return 'Use `// returns` after variable declarations or assignment expressions instead of `=>`';
77+
}
78+
break;
79+
default:
80+
break;
81+
}
82+
}
83+
return null;
84+
}
85+
3486
/**
3587
* Rule for validating that return annotations follow marker style conventions.
3688
*
3789
* @param {Object} context - ESLint context
3890
* @returns {Object} validators
3991
*/
4092
function main( context ) {
41-
var source = context.getSourceCode();
93+
var source = context.sourceCode;
4294

4395
/**
4496
* Reports the error message.
@@ -93,58 +145,6 @@ function main( context ) {
93145
}
94146
}
95147

96-
/**
97-
* Checks whether a comment is a return annotation and, if so, whether it follows marker style conventions.
98-
*
99-
* @private
100-
* @param {string} comment - comment to examine
101-
* @param {ASTNode} ast - node to examine
102-
* @param {integer} offset - non-zero if previous line ends with a comment
103-
* @returns {(string|null)} error message or null
104-
*/
105-
function checkComment( comment, ast, offset ) {
106-
var matches;
107-
var node;
108-
var prev;
109-
var type;
110-
111-
matches = comment.value.match( RE_ANNOTATION );
112-
if ( matches ) {
113-
offset += 1 + comment.loc.start.column;
114-
prev = walk.findNodeAt( ast, null, comment.start-offset );
115-
type = matches[ 1 ];
116-
if ( !prev ) {
117-
// Handle case when comment refers to node on the same line:
118-
if ( walk.findNodeAt( ast, null, comment.start-1 ) ) {
119-
return null;
120-
}
121-
return 'Encountered an orphaned return annotation without a preceding node';
122-
}
123-
node = prev.node;
124-
switch ( type ) {
125-
case 'returns':
126-
if (
127-
node.type !== 'VariableDeclaration' &&
128-
( node.type !== 'ExpressionStatement' || node.expression.type !== 'AssignmentExpression' )
129-
) {
130-
return 'Only include `// returns` after variable declarations or assignment expressions (use `=>` after `console.log`)';
131-
}
132-
break;
133-
case '=>':
134-
if (
135-
node.type === 'VariableDeclaration' ||
136-
( node.type === 'ExpressionStatement' && node.expression === 'AssignmentExpression' )
137-
) {
138-
return 'Use `// returns` after variable declarations or assignment expressions instead of `=>`';
139-
}
140-
break;
141-
default:
142-
break;
143-
}
144-
}
145-
return null;
146-
}
147-
148148
return {
149149
'Program': validate
150150
};

lib/node_modules/@stdlib/_tools/eslint/rules/doctest-quote-props/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function checkComment( comment ) {
154154
* @returns {Object} validators
155155
*/
156156
function main( context ) {
157-
var source = context.getSourceCode();
157+
var source = context.sourceCode;
158158

159159
/**
160160
* Reports the error message.

lib/node_modules/@stdlib/_tools/eslint/rules/doctest/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function main( context ) {
122122
var scope;
123123
var dir;
124124

125-
source = context.getSourceCode();
125+
source = context.sourceCode;
126126
if ( NODE_SHEBANG.test( source.text ) ) {
127127
// Do not lint executable Node.js script files:
128128
return {};

lib/node_modules/@stdlib/_tools/eslint/rules/empty-line-before-comment/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var rule;
4040
* @returns {Object} validators
4141
*/
4242
function main( context ) {
43-
var source = context.getSourceCode();
43+
var source = context.sourceCode;
4444

4545
/**
4646
* Reports the error message.

lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var rule;
3333
* @returns {Object} validators
3434
*/
3535
function main( context ) {
36-
var source = context.getSourceCode();
36+
var source = context.sourceCode;
3737

3838
/**
3939
* Reports the error message.

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-blockquote-indentation/lib/main.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ var rule;
4343

4444
// FUNCTIONS //
4545

46+
/**
47+
* Creates a location object.
48+
*
49+
* @private
50+
* @param {Object} options - function options
51+
* @returns {Object} location info
52+
*/
53+
function locationInfo( options ) {
54+
return {
55+
'start': {
56+
'line': options.startLine,
57+
'column': options.startColumn
58+
},
59+
'end': {
60+
'line': options.endLine,
61+
'column': options.endColumn
62+
}
63+
};
64+
}
65+
4666
/**
4767
* Rule for enforcing Markdown blockquote indentation in JSDoc descriptions.
4868
*
@@ -63,7 +83,7 @@ function main( context ) {
6383
]
6484
};
6585
lint = remark().use( config ).processSync; // eslint-disable-line node/no-sync
66-
source = context.getSourceCode();
86+
source = context.sourceCode;
6787

6888
return {
6989
'FunctionExpression:exit': validate,
@@ -121,26 +141,6 @@ function main( context ) {
121141
}
122142
}
123143

124-
/**
125-
* Creates a location object.
126-
*
127-
* @private
128-
* @param {Object} options - function options
129-
* @returns {Object} location info
130-
*/
131-
function locationInfo( options ) {
132-
return {
133-
'start': {
134-
'line': options.startLine,
135-
'column': options.startColumn
136-
},
137-
'end': {
138-
'line': options.endLine,
139-
'column': options.endColumn
140-
}
141-
};
142-
}
143-
144144
/**
145145
* Reports an error message.
146146
*

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style/lib/main.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ var rule;
4040

4141
// FUNCTIONS //
4242

43+
/**
44+
* Copies AST node location info.
45+
*
46+
* @private
47+
* @param {Object} loc - AST node location
48+
* @returns {Object} copied location info
49+
*/
50+
function copyLocationInfo( loc ) {
51+
return {
52+
'start': {
53+
'line': loc.start.line,
54+
'column': loc.start.column
55+
},
56+
'end': {
57+
'line': loc.end.line,
58+
'column': loc.end.column
59+
}
60+
};
61+
}
62+
4363
/**
4464
* Rule to enforce that Markdown checkboxes follow a specified style in JSDoc descriptions.
4565
*
@@ -60,7 +80,7 @@ function main( context ) {
6080
]
6181
};
6282
lint = remark().use( config ).processSync; // eslint-disable-line node/no-sync
63-
source = context.getSourceCode();
83+
source = context.sourceCode;
6484

6585
return {
6686
'FunctionExpression:exit': validate,
@@ -115,26 +135,6 @@ function main( context ) {
115135
}
116136
}
117137

118-
/**
119-
* Copies AST node location info.
120-
*
121-
* @private
122-
* @param {Object} loc - AST node location
123-
* @returns {Object} copied location info
124-
*/
125-
function copyLocationInfo( loc ) {
126-
return {
127-
'start': {
128-
'line': loc.start.line,
129-
'column': loc.start.column
130-
},
131-
'end': {
132-
'line': loc.end.line,
133-
'column': loc.end.column
134-
}
135-
};
136-
}
137-
138138
/**
139139
* Reports an error message.
140140
*

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-checkbox-content-indent/lib/main.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ var rule;
3939

4040
// FUNCTIONS //
4141

42+
/**
43+
* Copies AST node location info.
44+
*
45+
* @private
46+
* @param {Object} loc - AST node location
47+
* @returns {Object} copied location info
48+
*/
49+
function copyLocationInfo( loc ) {
50+
return {
51+
'start': {
52+
'line': loc.start.line,
53+
'column': loc.start.column
54+
},
55+
'end': {
56+
'line': loc.end.line,
57+
'column': loc.end.column
58+
}
59+
};
60+
}
61+
4262
/**
4363
* Rule to prevent Markdown checkboxes being followed by too much whitespace in JSDoc descriptions.
4464
*
@@ -57,7 +77,7 @@ function main( context ) {
5777
]
5878
};
5979
lint = remark().use( config ).processSync; // eslint-disable-line node/no-sync
60-
source = context.getSourceCode();
80+
source = context.sourceCode;
6181

6282
return {
6383
'FunctionExpression:exit': validate,
@@ -112,26 +132,6 @@ function main( context ) {
112132
}
113133
}
114134

115-
/**
116-
* Copies AST node location info.
117-
*
118-
* @private
119-
* @param {Object} loc - AST node location
120-
* @returns {Object} copied location info
121-
*/
122-
function copyLocationInfo( loc ) {
123-
return {
124-
'start': {
125-
'line': loc.start.line,
126-
'column': loc.start.column
127-
},
128-
'end': {
129-
'line': loc.end.line,
130-
'column': loc.end.column
131-
}
132-
};
133-
}
134-
135135
/**
136136
* Reports an error message.
137137
*

0 commit comments

Comments
 (0)