Skip to content

Commit c1c8739

Browse files
committed
build: use existing escapeRegExpString
--- 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent a41fd2d commit c1c8739

File tree

1 file changed

+4
-15
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib

1 file changed

+4
-15
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var contains = require( '@stdlib/assert/contains' );
3535
var replace = require( '@stdlib/string/replace' );
3636
var endsWith = require( '@stdlib/string/ends-with' );
3737
var trim = require( '@stdlib/string/trim' );
38+
var escapeRegExpString = require( '@stdlib/utils/escape-regexp-string' );
3839
var objectKeys = require( '@stdlib/utils/keys' );
3940
var compareValues = require( '@stdlib/_tools/doctest/compare-values' );
4041
var createAnnotationValue = require( '@stdlib/_tools/doctest/create-annotation-value' );
@@ -49,27 +50,15 @@ var debug = logger( 'tsdoc-doctest' );
4950
var RE_TSDOC = /\/\*\*[\s\S]+?\*\//g;
5051
var RE_EXAMPLE = /@example\s*([\s\S]*?)(?=\n\s*@\w|\*\/|$)/g;
5152
var RE_NEWLINE = /\r?\n/g;
52-
var RE_ANNOTATION = /(?:\n|^)(?:var|let|const)? ?([a-zA-Z0-9._]+) ?=[^;]*;\n\/\/ ?(returns|([A-Za-z][A-Za-z_0-9]*)? ?=>|throws) ?([\s\S]*?)(\n|$)/g;
53+
var RE_ANNOTATION = /(?:\n|^)(?:var|let|const)? ?([a-zA-Z0-9._]+) ?=[^;]*;\n\/\/ ?(returns|([A-Za-z][A-Za-z_0-9]*)? ?=>|throws) ?([\s\S]*?)(?=\n|$)/g;
5354
var RE_COMMENT_PREFIX = /^\s*\*\s?/gm;
54-
var RE_SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
5555
var regexCache = {};
5656
var lineCountCache = {};
5757
var rule;
5858

5959

6060
// FUNCTIONS //
6161

62-
/**
63-
* Escapes special regex characters in a string.
64-
*
65-
* @private
66-
* @param {string} str - string to escape
67-
* @returns {string} escaped string
68-
*/
69-
function escapeRegex( str ) {
70-
return replace( str, RE_SPECIAL_CHARS, '\\$&' );
71-
}
72-
7362
/**
7463
* Gets or creates a cached regex for finding return annotations.
7564
*
@@ -83,7 +72,7 @@ function getAnnotationRegex( annotationType, value ) {
8372
var pattern;
8473
var key;
8574

86-
escapedValue = escapeRegex( value );
75+
escapedValue = escapeRegExpString( value );
8776
key = [ annotationType, escapedValue ].join( '::' );
8877

8978
if ( !regexCache[ key ] ) {
@@ -336,7 +325,7 @@ function processExampleCode( code, commentIdx, comments, scope, report, opts, so
336325

337326
// Find annotation part in the match (after "// "):
338327
annotationStart = arr[ 0 ].indexOf( '// ' ) + 3;
339-
annotationEnd = arr[ 0 ].length - arr[ 5 ].length;
328+
annotationEnd = arr[ 0 ].length;
340329
loc.range = [
341330
commentStartIdx + codeIdx + annotationStart,
342331
commentStartIdx + codeIdx + annotationEnd

0 commit comments

Comments
 (0)