Skip to content

Commit 56893dc

Browse files
committed
Update regular expression and run entire code upfront
1 parent 02c0e0c commit 56893dc

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/return-annotations-values/lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var compareValues = require( './compare_values.js' );
3838

3939
var RE_JSDOC = /\/\*\*[\s\S]+?\*\//g;
4040
var RE_NEWLINE = /\r?\n/g;
41-
var RE_ANNOTATION = /(?:var|let|const)? ?([a-zA-Z0-9.]*) ?=?[^\n]*\n\/\/ ?(?:returns|=>|throws) {0,1}([\s\S]*?)(?:\n\n|$)/g;
41+
var RE_ANNOTATION = /(?:var|let|const)? ?([a-zA-Z0-9.]*) ?=?[^\n]*\n\/\/ ?(?:returns|=>|throws) {0,1}([\s\S]*?)(?:\n|$)/g;
4242
var rule;
4343

4444

@@ -106,6 +106,9 @@ function main( context ) {
106106
};
107107
vm.createContext( scope );
108108

109+
// Run entire code in case it relies on hoisting of function declarations:
110+
vm.runInContext( sourceCode, scope );
111+
109112
/**
110113
* Reports the error message.
111114
*

lib/node_modules/@stdlib/_tools/eslint/rules/return-annotations-values/test/fixtures/invalid.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ test = {
7373
};
7474
invalid.push( test );
7575

76+
test = {
77+
'code': [
78+
'var startsWith = require( \'@stdlib/string/starts-with\' );',
79+
'',
80+
'var str = \'Fair is foul, and foul is fair, hover through fog and filthy air\';',
81+
'',
82+
'console.log( startsWith( str, \'Fair\' ) );',
83+
'// => false',
84+
'',
85+
'console.log( startsWith( str, \'fair\' ) );',
86+
'// => false',
87+
'',
88+
'console.log( startsWith( str, \'foul\', 8 ) );',
89+
'// => true',
90+
'',
91+
'console.log( startsWith( str, \'filthy\', -10 ) );',
92+
'// => true',
93+
''
94+
].join( '\n' ),
95+
'errors': [
96+
{
97+
'message': 'Displayed return value is `false`, but function returns `true` instead',
98+
'type': null
99+
}
100+
]
101+
};
102+
invalid.push( test );
103+
76104

77105
// EXPORTS //
78106

lib/node_modules/@stdlib/_tools/eslint/rules/return-annotations-values/test/fixtures/valid.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ test = {
104104
};
105105
valid.push( test );
106106

107+
test = {
108+
'code': [
109+
'var startsWith = require( \'@stdlib/string/starts-with\' );',
110+
'',
111+
'var str = \'Fair is foul, and foul is fair, hover through fog and filthy air\';',
112+
'',
113+
'console.log( startsWith( str, \'Fair\' ) );',
114+
'// => true',
115+
'',
116+
'console.log( startsWith( str, \'fair\' ) );',
117+
'// => false',
118+
'',
119+
'console.log( startsWith( str, \'foul\', 8 ) );',
120+
'// => true',
121+
'',
122+
'console.log( startsWith( str, \'filthy\', -10 ) );',
123+
'// => true',
124+
'',
125+
''
126+
].join( '\n' )
127+
};
128+
valid.push( test );
129+
107130

108131
// EXPORTS //
109132

0 commit comments

Comments
 (0)