@@ -142,6 +142,31 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
142
142
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
143
143
options : [ { count : 1 , exactCount : true } ] ,
144
144
} ,
145
+ {
146
+ code : `import foo from 'foo';\n\n// Some random comment\nvar bar = 'bar';` ,
147
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
148
+ options : [ { count : 2 , exactCount : true } ] ,
149
+ } ,
150
+ {
151
+ code : `import foo from 'foo';\n// Some random comment\nvar bar = 'bar';` ,
152
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
153
+ options : [ { count : 1 , exactCount : true } ] ,
154
+ } ,
155
+ {
156
+ code : `import foo from 'foo';\n\n\n// Some random comment\nvar bar = 'bar';` ,
157
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
158
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
159
+ } ,
160
+ {
161
+ code : `import foo from 'foo';\n\n// Some random comment\nvar bar = 'bar';` ,
162
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
163
+ options : [ { count : 1 , exactCount : true , considerComments : true } ] ,
164
+ } ,
165
+ {
166
+ code : `/**\n * A leading comment\n */\nimport foo from 'foo';\n\n// Some random comment\nexport {foo};` ,
167
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
168
+ options : [ { count : 2 , exactCount : true } ] ,
169
+ } ,
145
170
{
146
171
code : `import foo from 'foo';\n\n\nvar bar = 'bar';` ,
147
172
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -171,6 +196,16 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
171
196
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
172
197
options : [ { count : 4 , exactCount : true } ] ,
173
198
} ,
199
+ {
200
+ code : `var foo = require('foo-module');\n\n// Some random comment\n\n\nvar foo = 'bar';` ,
201
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
202
+ options : [ { count : 4 , exactCount : true } ] ,
203
+ } ,
204
+ {
205
+ code : `var foo = require('foo-module');\n\n\n\n// Some random comment\nvar foo = 'bar';` ,
206
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
207
+ options : [ { count : 4 , exactCount : true , considerComments : true } ] ,
208
+ } ,
174
209
{
175
210
code : `require('foo-module');\n\nvar foo = 'bar';` ,
176
211
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -683,6 +718,72 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
683
718
} ] ,
684
719
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
685
720
} ,
721
+ {
722
+ code : `import foo from 'foo';\n// some random comment\nexport default function() {};` ,
723
+ output : `import foo from 'foo';\n\n// some random comment\nexport default function() {};` ,
724
+ options : [ { count : 2 , exactCount : true } ] ,
725
+ errors : [ {
726
+ line : 1 ,
727
+ column : 1 ,
728
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
729
+ } ] ,
730
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
731
+ } ,
732
+ {
733
+ code : `import foo from 'foo';\n// some random comment\n\n\nexport default function() {};` ,
734
+ output : `import foo from 'foo';\n// some random comment\n\n\nexport default function() {};` ,
735
+ options : [ { count : 2 , exactCount : true } ] ,
736
+ errors : [ {
737
+ line : 1 ,
738
+ column : 1 ,
739
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
740
+ } ] ,
741
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
742
+ } ,
743
+ {
744
+ code : `import foo from 'foo';\n// some random comment\n\n\n\nexport default function() {};` ,
745
+ output : `import foo from 'foo';\n// some random comment\n\n\n\nexport default function() {};` ,
746
+ options : [ { count : 2 , exactCount : true } ] ,
747
+ errors : [ {
748
+ line : 1 ,
749
+ column : 1 ,
750
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
751
+ } ] ,
752
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
753
+ } ,
754
+ {
755
+ code : `import foo from 'foo';\n// some random comment\nexport default function() {};` ,
756
+ output : `import foo from 'foo';\n\n\n// some random comment\nexport default function() {};` ,
757
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
758
+ errors : [ {
759
+ line : 1 ,
760
+ column : 1 ,
761
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
762
+ } ] ,
763
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
764
+ } ,
765
+ {
766
+ code : `import foo from 'foo';\n\n// some random comment\nexport default function() {};` ,
767
+ output : `import foo from 'foo';\n\n\n// some random comment\nexport default function() {};` ,
768
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
769
+ errors : [ {
770
+ line : 1 ,
771
+ column : 1 ,
772
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
773
+ } ] ,
774
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
775
+ } ,
776
+ {
777
+ code : `import foo from 'foo';\n\n\n\n// some random comment\nexport default function() {};` ,
778
+ output : `import foo from 'foo';\n\n\n\n// some random comment\nexport default function() {};` ,
779
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
780
+ errors : [ {
781
+ line : 1 ,
782
+ column : 1 ,
783
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
784
+ } ] ,
785
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
786
+ } ,
686
787
{
687
788
code : `
688
789
import foo from 'foo';
@@ -728,5 +829,37 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
728
829
} ] ,
729
830
parserOptions : { ecmaVersion : 2015 } ,
730
831
} ,
832
+ {
833
+ code : `const foo = require('foo');\n\n\n\n// some random comment\nconst bar = function() {};` ,
834
+ output : `const foo = require('foo');\n\n\n\n// some random comment\nconst bar = function() {};` ,
835
+ options : [ { count : 2 , exactCount : true } ] ,
836
+ errors : [ {
837
+ line : 1 ,
838
+ column : 1 ,
839
+ message : 'Expected 2 empty lines after require statement not followed by another require.' ,
840
+ } ] ,
841
+ parserOptions : { ecmaVersion : 2015 } ,
842
+ } ,
843
+ {
844
+ code : `import foo from 'foo';// some random comment\nexport default function() {};` ,
845
+ output : `import foo from 'foo';\n\n// some random comment\nexport default function() {};` ,
846
+ options : [ { count : 1 , exactCount : true , considerComments : true } ] ,
847
+ errors : [ {
848
+ line : 1 ,
849
+ column : 1 ,
850
+ message : IMPORT_ERROR_MESSAGE ,
851
+ } ] ,
852
+ parserOptions : { ecmaVersion : 2015 , considerComments : true , sourceType : 'module' } ,
853
+ } ,
854
+ {
855
+ code : `const foo = require('foo');\n\n\n// some random comment\nconst bar = function() {};` ,
856
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
857
+ errors : [ {
858
+ line : 1 ,
859
+ column : 1 ,
860
+ message : 'Expected 2 empty lines after require statement not followed by another require.' ,
861
+ } ] ,
862
+ parserOptions : { ecmaVersion : 2015 } ,
863
+ } ,
731
864
) ,
732
865
} ) ;
0 commit comments