File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed
lib/node_modules/@stdlib/_tools/eslint/rules/return-annotations-values Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ var compareValues = require( './compare_values.js' );
3838
3939var RE_JSDOC = / \/ \* \* [ \s \S ] + ?\* \/ / g;
4040var RE_NEWLINE = / \r ? \n / g;
41- var RE_ANNOTATION = / (?: v a r | l e t | c o n s t ) ? ? ( [ a - z A - Z 0 - 9 . ] * ) ? = ? [ ^ \n ] * \n \/ \/ ? (?: r e t u r n s | = > | t h r o w s ) { 0 , 1 } ( [ \s \S ] * ?) (?: \n \n | $ ) / g;
41+ var RE_ANNOTATION = / (?: v a r | l e t | c o n s t ) ? ? ( [ a - z A - Z 0 - 9 . ] * ) ? = ? [ ^ \n ] * \n \/ \/ ? (?: r e t u r n s | = > | t h r o w s ) { 0 , 1 } ( [ \s \S ] * ?) (?: \n | $ ) / g;
4242var 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 *
Original file line number Diff line number Diff line change @@ -73,6 +73,34 @@ test = {
7373} ;
7474invalid . 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
Original file line number Diff line number Diff line change @@ -104,6 +104,29 @@ test = {
104104} ;
105105valid . 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
You can’t perform that action at this time.
0 commit comments