@@ -46,6 +46,16 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
4646 parserOptions : { ecmaVersion : 6 } ,
4747 options : [ { considerComments : true } ] ,
4848 } ,
49+ {
50+ code : `
51+ const x = () => require('baz') && require('bar')
52+
53+ // Some random single line comment
54+ var bar = 42;
55+ ` ,
56+ parserOptions : { ecmaVersion : 6 } ,
57+ options : [ { considerComments : true , count : 1 , exactCount : true } ] ,
58+ } ,
4959 {
5060 code : `
5161 const x = () => require('baz') && require('bar')
@@ -122,6 +132,21 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
122132 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
123133 options : [ { count : 2 } ] ,
124134 } ,
135+ {
136+ code : `import foo from 'foo';\n\n\nvar bar = 'bar';` ,
137+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
138+ options : [ { count : 2 , exactCount : true } ] ,
139+ } ,
140+ {
141+ code : `import foo from 'foo';\n\nvar bar = 'bar';` ,
142+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
143+ options : [ { count : 1 , exactCount : true } ] ,
144+ } ,
145+ {
146+ code : `import foo from 'foo';\n\n\nvar bar = 'bar';` ,
147+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
148+ options : [ { count : 1 } ] ,
149+ } ,
125150 {
126151 code : `import foo from 'foo';\n\n\n\n\nvar bar = 'bar';` ,
127152 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -141,6 +166,11 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
141166 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
142167 options : [ { count : 4 } ] ,
143168 } ,
169+ {
170+ code : `var foo = require('foo-module');\n\n\n\n\nvar foo = 'bar';` ,
171+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
172+ options : [ { count : 4 , exactCount : true } ] ,
173+ } ,
144174 {
145175 code : `require('foo-module');\n\nvar foo = 'bar';` ,
146176 parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -620,5 +650,83 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
620650 parserOptions : { sourceType : 'module' } ,
621651 parser : parsers . BABEL_OLD ,
622652 } ) ) || [ ] ,
653+ {
654+ code : `import foo from 'foo';\n\nexport default function() {};` ,
655+ output : `import foo from 'foo';\n\n\nexport default function() {};` ,
656+ options : [ { count : 2 , exactCount : true } ] ,
657+ errors : [ {
658+ line : 1 ,
659+ column : 1 ,
660+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
661+ } ] ,
662+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
663+ } ,
664+ {
665+ code : `import foo from 'foo';\n\n\n\nexport default function() {};` ,
666+ output : `import foo from 'foo';\n\n\n\nexport default function() {};` ,
667+ options : [ { count : 2 , exactCount : true } ] ,
668+ errors : [ {
669+ line : 1 ,
670+ column : 1 ,
671+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
672+ } ] ,
673+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
674+ } ,
675+ {
676+ code : `import foo from 'foo';\n\n\n\n\nexport default function() {};` ,
677+ output : `import foo from 'foo';\n\n\n\n\nexport default function() {};` ,
678+ options : [ { count : 2 , exactCount : true } ] ,
679+ errors : [ {
680+ line : 1 ,
681+ column : 1 ,
682+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
683+ } ] ,
684+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
685+ } ,
686+ {
687+ code : `
688+ import foo from 'foo';
689+
690+
691+ // Some random single line comment
692+ var bar = 42;
693+ ` ,
694+ output : `
695+ import foo from 'foo';
696+
697+
698+ // Some random single line comment
699+ var bar = 42;
700+ ` ,
701+ errors : [ {
702+ line : 2 ,
703+ column : 9 ,
704+ message : IMPORT_ERROR_MESSAGE ,
705+ } ] ,
706+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
707+ options : [ { considerComments : true , count : 1 , exactCount : true } ] ,
708+ } ,
709+ {
710+ code : `import foo from 'foo';export default function() {};` ,
711+ output : `import foo from 'foo';\n\nexport default function() {};` ,
712+ options : [ { count : 1 , exactCount : true } ] ,
713+ errors : [ {
714+ line : 1 ,
715+ column : 1 ,
716+ message : IMPORT_ERROR_MESSAGE ,
717+ } ] ,
718+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
719+ } ,
720+ {
721+ code : `const foo = require('foo');\n\n\n\nconst bar = function() {};` ,
722+ output : `const foo = require('foo');\n\n\n\nconst bar = function() {};` ,
723+ options : [ { count : 2 , exactCount : true } ] ,
724+ errors : [ {
725+ line : 1 ,
726+ column : 1 ,
727+ message : 'Expected 2 empty lines after require statement not followed by another require.' ,
728+ } ] ,
729+ parserOptions : { ecmaVersion : 2015 } ,
730+ } ,
623731 ) ,
624732} ) ;
0 commit comments