Skip to content

Commit 8584611

Browse files
committed
build: prevent regex from matching function and class declarations in jsdoc-doctest rule
The RE_ANNOTATION regex was incorrectly matching function and class declarations as variable names when they preceded annotated statements. This caused the rule to extract 'function' instead of 'bool' in examples like the is-function-array case, leading to incorrect validation results. Added negative lookahead (?\!function\s|class\s) to prevent matching lines that start with these keywords, ensuring only actual variable assignments are captured. --- 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 e00e353 commit 8584611

File tree

2 files changed

+47
-1
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-doctest

2 files changed

+47
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var windowShim = require( './window.js' );
4848

4949
var debug = logger( 'jsdoc-doctest' );
5050
var ROOT_DIR = rootDir();
51-
var RE_ANNOTATION = /(?:\n|^)(?:var|let|const)? ?([a-zA-Z0-9._]+) ?=?[^;]*;\n\/\/ ?(returns|([A-Za-z][A-Za-z_0-9]*)? ?=>|throws) {0,1}([\s\S]*?)(\n|$)/g;
51+
var RE_ANNOTATION = /(?:\n|^)(?!function\s|class\s)(?:var|let|const)? ?([a-zA-Z0-9._]+) ?=?[^;]*;\n\/\/ ?(returns|([A-Za-z][A-Za-z_0-9]*)? ?=>|throws) {0,1}([\s\S]*?)(\n|$)/g;
5252
var RE_CONSOLE = /console\.(?:dir|error|log)/;
5353
var RE_MODULE_TAG = /\* @module[^\n]*\n/g;
5454
var NODE_SHEBANG = /#!\/usr\/bin\/env node/;

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable max-lines */
20+
1921
'use strict';
2022

2123
var valid = [];
@@ -1505,6 +1507,50 @@ test = {
15051507
};
15061508
valid.push( test );
15071509

1510+
test = {
1511+
'code': [
1512+
'\'use strict\';',
1513+
'',
1514+
'/**',
1515+
'* Test if a value is an array-like object containing only functions.',
1516+
'*',
1517+
'* @module @stdlib/assert/is-function-array',
1518+
'*',
1519+
'* @example',
1520+
'* var isFunctionArray = require( \'@stdlib/assert/is-function-array\' );',
1521+
'*',
1522+
'* function beep() {}',
1523+
'*',
1524+
'* function boop() {}',
1525+
'*',
1526+
'* var bool = isFunctionArray( [ beep, boop ] );',
1527+
'* // returns true',
1528+
'*',
1529+
'* bool = isFunctionArray( [ {}, beep ] );',
1530+
'* // returns false',
1531+
'*',
1532+
'* bool = isFunctionArray( [] );',
1533+
'* // returns false',
1534+
'*/',
1535+
'',
1536+
'// MODULES //',
1537+
'',
1538+
'var arrayfun = require( \'@stdlib/assert/tools/array-like-function\' );',
1539+
'var isFunction = require( \'@stdlib/assert/is-function\' );',
1540+
'',
1541+
'',
1542+
'// MAIN //',
1543+
'',
1544+
'var isFunctionArray = arrayfun( isFunction );',
1545+
'',
1546+
'',
1547+
'// EXPORTS //',
1548+
'',
1549+
'module.exports = isFunctionArray;'
1550+
].join( '\n' )
1551+
};
1552+
valid.push( test );
1553+
15081554

15091555
// EXPORTS //
15101556

0 commit comments

Comments
 (0)