@@ -8,6 +8,7 @@ import { getTSParsers, parsers, testVersion } from '../utils';
8
8
const IMPORT_ERROR_MESSAGE = 'Expected 1 empty line after import statement not followed by another import.' ;
9
9
const IMPORT_ERROR_MESSAGE_MULTIPLE = ( count ) => `Expected ${ count } empty lines after import statement not followed by another import.` ;
10
10
const REQUIRE_ERROR_MESSAGE = 'Expected 1 empty line after require statement not followed by another require.' ;
11
+ const REQUIRE_ERROR_MESSAGE_MULTIPLE = ( count ) => `Expected ${ count } empty lines after require statement not followed by another require.` ;
11
12
12
13
const ruleTester = new RuleTester ( ) ;
13
14
@@ -202,7 +203,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
202
203
options : [ { count : 4 , exactCount : true } ] ,
203
204
} ,
204
205
{
205
- code : `var foo = require('foo-module');\n\n\n\n// Some random comment\nvar foo = 'bar';` ,
206
+ code : `var foo = require('foo-module');\n\n\n\n\n // Some random comment\nvar foo = 'bar';` ,
206
207
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
207
208
options : [ { count : 4 , exactCount : true , considerComments : true } ] ,
208
209
} ,
@@ -394,6 +395,19 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
394
395
` ,
395
396
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
396
397
} ,
398
+ {
399
+ code : `var foo = require('foo-module');\n\n\n// Some random comment\nvar foo = 'bar';` ,
400
+ options : [ { count : 2 , considerComments : true } ] ,
401
+ } ,
402
+ {
403
+ code : `var foo = require('foo-module');\n\n\n/**\n * Test comment\n */\nvar foo = 'bar';` ,
404
+ options : [ { count : 2 , considerComments : true } ] ,
405
+ } ,
406
+ {
407
+ code : `const foo = require('foo');\n\n\n// some random comment\nconst bar = function() {};` ,
408
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
409
+ parserOptions : { ecmaVersion : 2015 } ,
410
+ } ,
397
411
) ,
398
412
399
413
invalid : [ ] . concat (
@@ -825,7 +839,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
825
839
errors : [ {
826
840
line : 1 ,
827
841
column : 1 ,
828
- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
842
+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
829
843
} ] ,
830
844
parserOptions : { ecmaVersion : 2015 } ,
831
845
} ,
@@ -836,7 +850,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
836
850
errors : [ {
837
851
line : 1 ,
838
852
column : 1 ,
839
- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
853
+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
840
854
} ] ,
841
855
parserOptions : { ecmaVersion : 2015 } ,
842
856
} ,
@@ -852,14 +866,26 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
852
866
parserOptions : { ecmaVersion : 2015 , considerComments : true , sourceType : 'module' } ,
853
867
} ,
854
868
{
855
- code : `const foo = require('foo');\n\n\n// some random comment\nconst bar = function() {};` ,
856
- options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
869
+ code : `var foo = require('foo-module');\nvar foo = require('foo-module');\n\n// Some random comment\nvar foo = 'bar';` ,
870
+ output : `var foo = require('foo-module');\nvar foo = require('foo-module');\n\n\n// Some random comment\nvar foo = 'bar';` ,
871
+ errors : [ {
872
+ line : 2 ,
873
+ column : 1 ,
874
+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
875
+ } ] ,
876
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
877
+ options : [ { considerComments : true , count : 2 } ] ,
878
+ } ,
879
+ {
880
+ code : `var foo = require('foo-module');\n\n/**\n * Test comment\n */\nvar foo = 'bar';` ,
881
+ output : `var foo = require('foo-module');\n\n\n/**\n * Test comment\n */\nvar foo = 'bar';` ,
857
882
errors : [ {
858
883
line : 1 ,
859
884
column : 1 ,
860
- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
885
+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
861
886
} ] ,
862
887
parserOptions : { ecmaVersion : 2015 } ,
888
+ options : [ { considerComments : true , count : 2 } ] ,
863
889
} ,
864
890
) ,
865
891
} ) ;
0 commit comments