@@ -133,15 +133,25 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
133
133
options : [ { count : 2 } ] ,
134
134
} ,
135
135
{
136
- code : `import foo from 'foo';\n\n\nvar bar = 'bar';` ,
136
+ code : `import foo from 'foo';\n\n// Some random comment \nvar bar = 'bar';` ,
137
137
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
138
138
options : [ { count : 2 , exactCount : true } ] ,
139
139
} ,
140
140
{
141
- code : `import foo from 'foo';\n\nvar bar = 'bar';` ,
141
+ code : `import foo from 'foo';\n// Some random comment \nvar bar = 'bar';` ,
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\n// Some random comment\nvar bar = 'bar';` ,
147
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
148
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
149
+ } ,
150
+ {
151
+ code : `import foo from 'foo';\n\n// Some random comment\nvar bar = 'bar';` ,
152
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
153
+ options : [ { count : 1 , exactCount : true , considerComments : true } ] ,
154
+ } ,
145
155
{
146
156
code : `import foo from 'foo';\n\n\nvar bar = 'bar';` ,
147
157
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -167,10 +177,15 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
167
177
options : [ { count : 4 } ] ,
168
178
} ,
169
179
{
170
- code : `var foo = require('foo-module');\n\n\n\n\nvar foo = 'bar';` ,
180
+ code : `var foo = require('foo-module');\n\n// Some random comment \n\n\nvar foo = 'bar';` ,
171
181
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
172
182
options : [ { count : 4 , exactCount : true } ] ,
173
183
} ,
184
+ {
185
+ code : `var foo = require('foo-module');\n\n\n\n// Some random comment\nvar foo = 'bar';` ,
186
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
187
+ options : [ { count : 4 , exactCount : true , considerComments : true } ] ,
188
+ } ,
174
189
{
175
190
code : `require('foo-module');\n\nvar foo = 'bar';` ,
176
191
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
@@ -651,8 +666,8 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
651
666
parser : parsers . BABEL_OLD ,
652
667
} ) ) || [ ] ,
653
668
{
654
- code : `import foo from 'foo';\n\nexport default function() {};` ,
655
- output : `import foo from 'foo';\n\n\nexport default function() {};` ,
669
+ code : `import foo from 'foo';\n// some random comment \nexport default function() {};` ,
670
+ output : `import foo from 'foo';\n\n// some random comment \nexport default function() {};` ,
656
671
options : [ { count : 2 , exactCount : true } ] ,
657
672
errors : [ {
658
673
line : 1 ,
@@ -662,8 +677,8 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
662
677
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
663
678
} ,
664
679
{
665
- code : `import foo from 'foo';\n\n\n\nexport default function() {};` ,
666
- output : `import foo from 'foo';\n\n\n\nexport default function() {};` ,
680
+ code : `import foo from 'foo';\n// some random comment \n\n\nexport default function() {};` ,
681
+ output : `import foo from 'foo';\n// some random comment \n\n\nexport default function() {};` ,
667
682
options : [ { count : 2 , exactCount : true } ] ,
668
683
errors : [ {
669
684
line : 1 ,
@@ -673,8 +688,8 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
673
688
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
674
689
} ,
675
690
{
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() {};` ,
691
+ code : `import foo from 'foo';\n// some random comment \n\n\n\nexport default function() {};` ,
692
+ output : `import foo from 'foo';\n// some random comment \n\n\n\nexport default function() {};` ,
678
693
options : [ { count : 2 , exactCount : true } ] ,
679
694
errors : [ {
680
695
line : 1 ,
@@ -683,6 +698,39 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
683
698
} ] ,
684
699
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
685
700
} ,
701
+ {
702
+ code : `import foo from 'foo';\n// some random comment\nexport default function() {};` ,
703
+ output : `import foo from 'foo';\n\n\n// some random comment\nexport default function() {};` ,
704
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
705
+ errors : [ {
706
+ line : 1 ,
707
+ column : 1 ,
708
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
709
+ } ] ,
710
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
711
+ } ,
712
+ {
713
+ code : `import foo from 'foo';\n\n// some random comment\nexport default function() {};` ,
714
+ output : `import foo from 'foo';\n\n\n// some random comment\nexport default function() {};` ,
715
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
716
+ errors : [ {
717
+ line : 1 ,
718
+ column : 1 ,
719
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
720
+ } ] ,
721
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
722
+ } ,
723
+ {
724
+ code : `import foo from 'foo';\n\n\n\n// some random comment\nexport default function() {};` ,
725
+ output : `import foo from 'foo';\n\n\n\n// some random comment\nexport default function() {};` ,
726
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
727
+ errors : [ {
728
+ line : 1 ,
729
+ column : 1 ,
730
+ message : IMPORT_ERROR_MESSAGE_MULTIPLE ( 2 ) ,
731
+ } ] ,
732
+ parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
733
+ } ,
686
734
{
687
735
code : `
688
736
import foo from 'foo';
@@ -718,8 +766,8 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
718
766
parserOptions : { ecmaVersion : 2015 , sourceType : 'module' } ,
719
767
} ,
720
768
{
721
- code : `const foo = require('foo');\n\n\n\nconst bar = function() {};` ,
722
- output : `const foo = require('foo');\n\n\n\nconst bar = function() {};` ,
769
+ code : `const foo = require('foo');\n\n\n\n// some random comment\ nconst bar = function() {};` ,
770
+ output : `const foo = require('foo');\n\n\n\n// some random comment\ nconst bar = function() {};` ,
723
771
options : [ { count : 2 , exactCount : true } ] ,
724
772
errors : [ {
725
773
line : 1 ,
@@ -728,5 +776,26 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
728
776
} ] ,
729
777
parserOptions : { ecmaVersion : 2015 } ,
730
778
} ,
779
+ {
780
+ code : `import foo from 'foo';// some random comment\nexport default function() {};` ,
781
+ output : `import foo from 'foo';\n\n// some random comment\nexport default function() {};` ,
782
+ options : [ { count : 1 , exactCount : true , considerComments : true } ] ,
783
+ errors : [ {
784
+ line : 1 ,
785
+ column : 1 ,
786
+ message : IMPORT_ERROR_MESSAGE ,
787
+ } ] ,
788
+ parserOptions : { ecmaVersion : 2015 , considerComments : true , sourceType : 'module' } ,
789
+ } ,
790
+ {
791
+ code : `const foo = require('foo');\n\n\n// some random comment\nconst bar = function() {};` ,
792
+ options : [ { count : 2 , exactCount : true , considerComments : true } ] ,
793
+ errors : [ {
794
+ line : 1 ,
795
+ column : 1 ,
796
+ message : 'Expected 2 empty lines after require statement not followed by another require.' ,
797
+ } ] ,
798
+ parserOptions : { ecmaVersion : 2015 } ,
799
+ } ,
731
800
) ,
732
801
} ) ;
0 commit comments