@@ -854,10 +854,10 @@ ruleTester.run('order', rule, {
854
854
test ( {
855
855
code :
856
856
`/* comment0 */ /* comment1 */ var async = require('async'); /* comment2 */` + `\r\n` +
857
- `/* comment3 */ var fs = require('fs'); /* comment4 */` + `\r\n` ,
857
+ `/* comment3 */ var fs = require('fs'); /* comment4 */` + `\r\n` ,
858
858
output :
859
859
`/* comment3 */ var fs = require('fs'); /* comment4 */` + `\r\n` +
860
- `/* comment0 */ /* comment1 */ var async = require('async'); /* comment2 */` + `\r\n` ,
860
+ `/* comment0 */ /* comment1 */ var async = require('async'); /* comment2 */` + `\r\n` ,
861
861
errors : [ {
862
862
message : '`fs` import should occur before import of `async`' ,
863
863
} ] ,
@@ -1530,7 +1530,8 @@ ruleTester.run('order', rule, {
1530
1530
} ,
1531
1531
] ,
1532
1532
} ) ,
1533
- // Option newlines-between: 'never' cannot fix if there are other statements between imports
1533
+ // Option newlines-between: 'never' with unassigned imports and warnOnUnassignedImports disabled
1534
+ // newline is preserved to match existing behavior
1534
1535
test ( {
1535
1536
code : `
1536
1537
import path from 'path';
@@ -1546,6 +1547,53 @@ ruleTester.run('order', rule, {
1546
1547
import 'something-else';
1547
1548
import _ from 'lodash';
1548
1549
` ,
1550
+ options : [ { 'newlines-between' : 'never' , warnOnUnassignedImports : false } ] ,
1551
+ errors : [
1552
+ {
1553
+ line : 2 ,
1554
+ message : 'There should be no empty line between import groups' ,
1555
+ } ,
1556
+ ] ,
1557
+ } ) ,
1558
+ // Option newlines-between: 'never' with unassigned imports and warnOnUnassignedImports enabled
1559
+ test ( {
1560
+ code : `
1561
+ import path from 'path';
1562
+ import 'loud-rejection';
1563
+
1564
+ import 'something-else';
1565
+ import _ from 'lodash';
1566
+ ` ,
1567
+ output : `
1568
+ import path from 'path';
1569
+ import 'loud-rejection';
1570
+ import 'something-else';
1571
+ import _ from 'lodash';
1572
+ ` ,
1573
+ options : [ { 'newlines-between' : 'never' , warnOnUnassignedImports : true } ] ,
1574
+ errors : [
1575
+ {
1576
+ line : 3 ,
1577
+ message : 'There should be no empty line between import groups' ,
1578
+ } ,
1579
+ ] ,
1580
+ } ) ,
1581
+ // Option newlines-between: 'never' cannot fix if there are other statements between imports
1582
+ test ( {
1583
+ code : `
1584
+ import path from 'path';
1585
+ export const abc = 123;
1586
+
1587
+ import 'something-else';
1588
+ import _ from 'lodash';
1589
+ ` ,
1590
+ output : `
1591
+ import path from 'path';
1592
+ export const abc = 123;
1593
+
1594
+ import 'something-else';
1595
+ import _ from 'lodash';
1596
+ ` ,
1549
1597
options : [ { 'newlines-between' : 'never' } ] ,
1550
1598
errors : [
1551
1599
{
@@ -1764,7 +1812,6 @@ ruleTester.run('order', rule, {
1764
1812
'`./local2` import should occur after import of `global4`' ,
1765
1813
] ,
1766
1814
} ) ,
1767
-
1768
1815
// pathGroup with position 'after'
1769
1816
test ( {
1770
1817
code : `
@@ -2309,6 +2356,53 @@ context('TypeScript', function () {
2309
2356
} ,
2310
2357
parserConfig ,
2311
2358
) ,
2359
+ // warns for out of order unassigned imports (warnOnUnassignedImports enabled)
2360
+ test ( {
2361
+ code : `
2362
+ import './local1';
2363
+ import global from 'global1';
2364
+ import local from './local2';
2365
+ import 'global2';
2366
+ ` ,
2367
+ output : `
2368
+ import './local1';
2369
+ import global from 'global1';
2370
+ import local from './local2';
2371
+ import 'global2';
2372
+ ` ,
2373
+ errors : [
2374
+ {
2375
+ message : '`global1` import should occur before import of `./local1`' ,
2376
+ } ,
2377
+ {
2378
+ message : '`global2` import should occur before import of `./local1`' ,
2379
+ } ,
2380
+ ] ,
2381
+ options : [ { warnOnUnassignedImports : true } ] ,
2382
+ } ) ,
2383
+ // fix cannot move below unassigned import (warnOnUnassignedImports enabled)
2384
+ test ( {
2385
+ code : `
2386
+ import local from './local';
2387
+
2388
+ import 'global1';
2389
+
2390
+ import global2 from 'global2';
2391
+ import global3 from 'global3';
2392
+ ` ,
2393
+ output : `
2394
+ import local from './local';
2395
+
2396
+ import 'global1';
2397
+
2398
+ import global2 from 'global2';
2399
+ import global3 from 'global3';
2400
+ ` ,
2401
+ errors : [ {
2402
+ message : '`./local` import should occur after import of `global3`' ,
2403
+ } ] ,
2404
+ options : [ { warnOnUnassignedImports : true } ] ,
2405
+ } ) ,
2312
2406
] ,
2313
2407
} ) ;
2314
2408
} ) ;
0 commit comments