Skip to content

Commit 70b575f

Browse files
author
Will Honey
committed
update tests a little, add comments to explain
1 parent 0f50fcd commit 70b575f

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

src/util/import-type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export function isAbsolute(name: string): boolean {
22
return name.indexOf('/') === 0;
33
}
44

5-
const moduleRegExp = /^[^/\\.]/;
5+
// a module is anything that doesn't start with a . or a / or a \
6+
const moduleRegExp = /^[^\/\\.]/;
67
export function isModule(name: string): boolean {
78
return moduleRegExp.test(name);
89
}

test/rules/order-imports-2.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ const rule = require('rules/order-imports');
88
ruleTester.run('order', rule, {
99
valid: [
1010
// Default order using import
11+
// absolute at top
12+
// modules starting with _ or @ are sorted with modules
1113
test({
1214
code: `
13-
import async, {foo1} from 'async';
15+
import abs from '/absolute/module';
16+
17+
import blah from '_lodash';
1418
import module from '@module/core';
1519
import print from '@module/print';
20+
import async, {foo1} from 'async';
1621
import fs from 'fs';
1722
18-
import relParent1 from '../foo';
23+
import relParent1 from '../foo';
1924
import relParent2, {foo2} from '../foo/bar';
2025
2126
import relParent3 from '@shared';
@@ -25,11 +30,11 @@ ruleTester.run('order', rule, {
2530
import index from './';`,
2631
options: [
2732
{
28-
groups: ['module', 'parent', '/@shared/', 'sibling', 'index'],
33+
groups: ['absolute', 'module', 'parent', '/@shared/', 'sibling', 'index'],
2934
alphabetize: { order: 'asc', ignoreCase: true },
30-
newlinesBetween: 'always'
31-
}
32-
]
35+
newlinesBetween: 'always',
36+
},
37+
],
3338
}),
3439
test({
3540
code: `
@@ -46,9 +51,9 @@ ruleTester.run('order', rule, {
4651
{
4752
groups: [['module'], '/@shared/', ['parent', 'sibling', 'index']],
4853
alphabetize: { order: 'asc', ignoreCase: true },
49-
newlinesBetween: 'always'
50-
}
51-
]
54+
newlinesBetween: 'always',
55+
},
56+
],
5257
}),
5358
test({
5459
code: `
@@ -67,9 +72,9 @@ ruleTester.run('order', rule, {
6772
options: [
6873
{
6974
groups: ['module', '/^@shared/', 'parent', 'sibling', 'index'],
70-
newlinesBetween: 'always'
71-
}
72-
]
75+
newlinesBetween: 'always',
76+
},
77+
],
7378
}),
7479
test({
7580
code: `
@@ -90,10 +95,10 @@ ruleTester.run('order', rule, {
9095
{
9196
groups: [['module'], '/@shared/', ['parent', 'sibling', 'index']],
9297
alphabetize: { order: 'asc', ignoreCase: true },
93-
newlinesBetween: 'always-and-inside-groups'
94-
}
95-
]
96-
})
98+
newlinesBetween: 'always-and-inside-groups',
99+
},
100+
],
101+
}),
97102
],
98103
invalid: [
99104
// Option alphabetize: {order: 'desc', ignoreCase: true}
@@ -113,15 +118,15 @@ ruleTester.run('order', rule, {
113118
options: [
114119
{
115120
groups: ['module', 'index'],
116-
alphabetize: { order: 'desc', ignoreCase: true }
117-
}
121+
alphabetize: { order: 'desc', ignoreCase: true },
122+
},
118123
],
119124
errors: [
120125
{
121126
ruleID: 'order',
122-
message: '`Baz` import should occur before import of `bar`'
123-
}
124-
]
125-
})
126-
]
127+
message: '`Baz` import should occur before import of `bar`',
128+
},
129+
],
130+
}),
131+
],
127132
});

0 commit comments

Comments
 (0)