Skip to content

Commit 9e2c3b9

Browse files
committed
bench: fix RuleTester and custom-rule tests
Fix 9 pre-existing test failures across custom ESLint rules to ensure all 123 rule tests pass cleanly on ESLint v8: Rule fixes: - `doctest-marker`: replace `acorn-walk` with ESLint `sourceCode` APIs (`getTokenBefore`, `getNodeByRangeIndex`) to avoid deprecated `node.start`/`node.end` property access; add line-proximity check for orphaned annotation detection - `jsdoc-require-throws-tags`: replace `node.start`/`node.end` with `node.range[0]`/`node.range[1]` - `jsdoc-no-space-aligned-asterisks`: fix autofix regex replacement that incorrectly turned trailing whitespace into asterisks (use `$1` back-reference instead of literal `*`) Test fixture fixes: - `no-redeclare`: add `ecmaVersion: 2015` for `sourceType: 'module'` test case - `namespace-index-order`: reorder fixture entries to match alphabetical package path order - `require-last-path-relative`: match error message backtick quoting - `jsdoc-ordered-list-marker-value`: expect 4 errors (not 3) for newer `remark-lint-ordered-list-marker-value` - `jsdoc-doctest-marker`: remove undefined `stdlib/require-globals` from `eslint-disable-line` comments - `doctest-marker`: remove undefined `stdlib/no-builtin-math` from `eslint-disable-line` comments - `jsdoc-no-blockquote-without-marker`: use lazy continuation pattern and update error message for `remark-lint` v2 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 485bf9b commit 9e2c3b9

File tree

11 files changed

+79
-59
lines changed

11 files changed

+79
-59
lines changed

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

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
'use strict';
2020

21-
// MODULES //
22-
23-
var walk = require( 'acorn-walk' );
24-
25-
2621
// VARIABLES //
2722

2823
var RE_ANNOTATION = /^\s*(?:\* ){0,1}(?:\/\/|\/\*)* *(?:e\.g\.,){0,1} (returns|=>|throws)/;
@@ -31,34 +26,71 @@ var rule;
3126

3227
// FUNCTIONS //
3328

29+
/**
30+
* Finds the nearest statement-level ancestor of a given AST node.
31+
*
32+
* @private
33+
* @param {ASTNode} node - AST node
34+
* @returns {ASTNode} statement-level ancestor
35+
*/
36+
function findStatement( node ) {
37+
while ( node ) {
38+
if (
39+
node.type === 'VariableDeclaration' ||
40+
node.type === 'ExpressionStatement' ||
41+
node.type === 'ReturnStatement' ||
42+
node.type === 'ThrowStatement' ||
43+
node.type === 'IfStatement' ||
44+
node.type === 'ForStatement' ||
45+
node.type === 'WhileStatement' ||
46+
node.type === 'TryStatement' ||
47+
node.type === 'FunctionDeclaration' ||
48+
node.type === 'Program'
49+
) {
50+
return node;
51+
}
52+
node = node.parent;
53+
}
54+
return null;
55+
}
56+
3457
/**
3558
* Checks whether a comment is a return annotation and, if so, whether it follows marker style conventions.
3659
*
3760
* @private
61+
* @param {Object} source - source code object
3862
* @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
4163
* @returns {(string|null)} error message or null
4264
*/
43-
function checkComment( comment, ast, offset ) {
65+
function checkComment( source, comment ) {
4466
var matches;
67+
var token;
4568
var node;
46-
var prev;
4769
var type;
4870

4971
matches = comment.value.match( RE_ANNOTATION );
5072
if ( matches ) {
51-
offset += 1 + comment.loc.start.column;
52-
prev = walk.findNodeAt( ast, null, comment.start-offset );
5373
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-
}
74+
75+
// Find the preceding code token:
76+
token = source.getTokenBefore( comment );
77+
if ( !token ) {
78+
return 'Encountered an orphaned return annotation without a preceding node';
79+
}
80+
81+
// Check for orphaned annotation (preceding token is not on the same or previous line):
82+
if ( comment.loc.start.line - token.loc.end.line > 1 ) {
5983
return 'Encountered an orphaned return annotation without a preceding node';
6084
}
61-
node = prev.node;
85+
86+
node = source.getNodeByRangeIndex( token.range[ 0 ] );
87+
if ( !node || node.type === 'Program' ) {
88+
return 'Encountered an orphaned return annotation without a preceding node';
89+
}
90+
node = findStatement( node );
91+
if ( !node || node.type === 'Program' ) {
92+
return null;
93+
}
6294
switch ( type ) {
6395
case 'returns':
6496
if (
@@ -116,32 +148,16 @@ function main( context ) {
116148
function validate( node ) {
117149
var comments;
118150
var current;
119-
var offset;
120-
var prev;
121151
var msg;
122152
var i;
123153

124154
comments = source.getAllComments( node );
125-
if ( comments.length > 0 ) {
126-
current = comments[ 0 ];
127-
msg = checkComment( current, node, 0 );
155+
for ( i = 0; i < comments.length; i++ ) {
156+
current = comments[ i ];
157+
msg = checkComment( source, current );
128158
if ( msg ) {
129159
report( current.loc, msg );
130160
}
131-
for ( i = 1; i < comments.length; i++ ) {
132-
prev = comments[ i-1 ];
133-
current = comments[ i ];
134-
offset = 0;
135-
136-
// Check whether previous comment sits one line before the current one; if so, adjust offset for finding last node:
137-
if ( current.loc.start.line === prev.loc.end.line + 1 ) {
138-
offset = prev.loc.end.column - prev.loc.start.column + 1;
139-
}
140-
msg = checkComment( current, node, offset );
141-
if ( msg ) {
142-
report( current.loc, msg );
143-
}
144-
}
145161
}
146162
}
147163

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ test = {
112112
'code': [
113113
'var functionName = require( \'./../lib\' );',
114114
'',
115-
'console.log( functionName( Math.sqrt ) ); // eslint-disable-line stdlib/no-builtin-math',
115+
'console.log( functionName( Math.sqrt ) );',
116116
'// => \'sqrt\'',
117117
'',
118118
'console.log( functionName( Float64Array ) );',

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-doctest-marker/test/fixtures/invalid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ test = {
122122
'*/',
123123
'function isSharedArrayBuffer( value ) {',
124124
' return (',
125-
' ( hasSharedArrayBuffer && value instanceof SharedArrayBuffer ) || // eslint-disable-line stdlib/require-globals, no-undef',
125+
' ( hasSharedArrayBuffer && value instanceof SharedArrayBuffer ) || // eslint-disable-line no-undef',
126126
' nativeClass( value ) === \'[object SharedArrayBuffer]\'',
127127
' );',
128128
'}'

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-doctest-marker/test/fixtures/valid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test = {
113113
'*/',
114114
'function isSharedArrayBuffer( value ) {',
115115
' return (',
116-
' ( hasSharedArrayBuffer && value instanceof SharedArrayBuffer ) || // eslint-disable-line stdlib/require-globals, no-undef',
116+
' ( hasSharedArrayBuffer && value instanceof SharedArrayBuffer ) || // eslint-disable-line no-undef',
117117
' nativeClass( value ) === \'[object SharedArrayBuffer]\'',
118118
' );',
119119
'}'

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-blockquote-without-marker/test/fixtures/invalid.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ test = {
3535
'* Beep boop.',
3636
'*',
3737
'* > Beep...',
38-
'*',
39-
'* > ...boop.',
38+
'* boop.',
4039
'*/',
4140
'function beep() {',
4241
' console.log( "boop" );',
4342
'}'
4443
].join( '\n' ),
4544
'errors': [
4645
{
47-
'message': 'Missing marker in blockquote',
46+
'message': 'Missing marker in block quote',
4847
'type': null
4948
}
5049
]

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-no-space-aligned-asterisks/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function main( context ) {
100100
* @returns {(Object|null)} fix or null
101101
*/
102102
function fix( fixer ) {
103-
var fixed = replace( comment, RE_LEADING_SPACE, '*' );
103+
var fixed = replace( comment, RE_LEADING_SPACE, '$1' );
104104
fixed = '/*' + fixed + '*/';
105105
return fixer.replaceTextRange( range, fixed );
106106
}

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-ordered-list-marker-value/test/fixtures/invalid.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ test = {
148148
'message': 'Marker should be `1`, was `2`',
149149
'type': null
150150
},
151+
{
152+
'message': 'Marker should be `1`, was `2`',
153+
'type': null
154+
},
151155
{
152156
'message': 'Marker should be `1`, was `2`',
153157
'type': null

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-require-throws-tags/lib/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ function extractFunctionBoundaries( node ) {
8686
elem = body[ i ];
8787
if ( elem.type === 'FunctionDeclaration' ) {
8888
out.push({
89-
'start': elem.start,
90-
'end': elem.end
89+
'start': elem.range[ 0 ],
90+
'end': elem.range[ 1 ]
9191
});
9292
}
9393
}
@@ -140,8 +140,8 @@ function main( context ) {
140140
annotations = extractThrowsAnnotations( node );
141141
functionHash[ node.id.name ] = {
142142
'name': node.id.name,
143-
'start': node.start,
144-
'end': node.end,
143+
'start': node.range[ 0 ],
144+
'end': node.range[ 1 ],
145145
'loc': node.loc,
146146
'throwAnnotations': annotations || [],
147147
'functionBoundaries': extractFunctionBoundaries( node ),
@@ -281,8 +281,8 @@ function main( context ) {
281281
callee = node.argument.callee;
282282
if ( callee && callee.name ) {
283283
obj = {
284-
'start': node.start,
285-
'end': node.end,
284+
'start': node.range[ 0 ],
285+
'end': node.range[ 1 ],
286286
'type': callee.name
287287
};
288288
throwStatements.push( obj );

lib/node_modules/@stdlib/_tools/eslint/rules/namespace-index-order/test/fixtures/valid.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,22 @@ test = {
184184
'setReadOnly( ns, \'complex\', require( \'@stdlib/complex/cmplx\' ) );',
185185
'',
186186
'/**',
187-
'* @name conj',
187+
'* @name Complex64',
188188
'* @memberof ns',
189189
'* @readonly',
190-
'* @type {Function}',
191-
'* @see {@link module:@stdlib/complex/float64/conj}',
190+
'* @constructor',
191+
'* @see {@link module:@stdlib/complex/float32/ctor}',
192192
'*/',
193-
'setReadOnly( ns, \'conj\', require( \'@stdlib/complex/float64/conj\' ) );',
193+
'setReadOnly( ns, \'Complex64\', require( \'@stdlib/complex/float32/ctor\' ) );',
194194
'',
195195
'/**',
196-
'* @name Complex64',
196+
'* @name conj',
197197
'* @memberof ns',
198198
'* @readonly',
199-
'* @constructor',
200-
'* @see {@link module:@stdlib/complex/float32/ctor}',
199+
'* @type {Function}',
200+
'* @see {@link module:@stdlib/complex/float64/conj}',
201201
'*/',
202-
'setReadOnly( ns, \'Complex64\', require( \'@stdlib/complex/float32/ctor\' ) );',
202+
'setReadOnly( ns, \'conj\', require( \'@stdlib/complex/float64/conj\' ) );',
203203
'',
204204
'/**',
205205
'* @name Complex128',

lib/node_modules/@stdlib/_tools/eslint/rules/no-redeclare/test/fixtures/valid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ test = {
7575
'builtinGlobals': true
7676
}],
7777
'parserOptions': {
78+
'ecmaVersion': 2015,
7879
'sourceType': 'module'
7980
}
8081
};

0 commit comments

Comments
 (0)