@@ -8,6 +8,7 @@ import { getTSParsers, parsers, testVersion } from '../utils';
88const IMPORT_ERROR_MESSAGE = 'Expected 1 empty line after import statement not followed by another import.' ;
99const IMPORT_ERROR_MESSAGE_MULTIPLE = ( count ) => `Expected ${ count } empty lines after import statement not followed by another import.` ;
1010const 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.` ;
1112
1213const ruleTester = new RuleTester ( ) ;
1314
@@ -202,7 +203,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
202203 options : [ { count : 4 , exactCount : true } ] ,
203204 } ,
204205 {
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';` ,
206207 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
207208 options : [ { count : 4 , exactCount : true , considerComments : true } ] ,
208209 } ,
@@ -394,6 +395,19 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
394395 ` ,
395396 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
396397 } ,
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+ } ,
397411 ) ,
398412
399413 invalid : [ ] . concat (
@@ -825,7 +839,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
825839 errors : [ {
826840 line : 1 ,
827841 column : 1 ,
828- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
842+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
829843 } ] ,
830844 parserOptions : { ecmaVersion : 2015 } ,
831845 } ,
@@ -836,7 +850,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
836850 errors : [ {
837851 line : 1 ,
838852 column : 1 ,
839- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
853+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
840854 } ] ,
841855 parserOptions : { ecmaVersion : 2015 } ,
842856 } ,
@@ -852,14 +866,26 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
852866 parserOptions : { ecmaVersion : 2015 , considerComments : true , sourceType : 'module' } ,
853867 } ,
854868 {
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';` ,
857882 errors : [ {
858883 line : 1 ,
859884 column : 1 ,
860- message : 'Expected 2 empty lines after require statement not followed by another require.' ,
885+ message : REQUIRE_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
861886 } ] ,
862887 parserOptions : { ecmaVersion : 2015 } ,
888+ options : [ { considerComments : true , count : 2 } ] ,
863889 } ,
864890 ) ,
865891} ) ;
0 commit comments