This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for new ordered-imports groups option.
- Loading branch information
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env node | ||
|
||
// comment outside of imports | ||
import {afoo, foo} from 'foo'; | ||
import x = require('y'); | ||
|
||
import {app_b} from 'app/bar'; | ||
import {app_f} from 'app/foo'; | ||
|
||
// comment pkg/bar | ||
import {a} from '@pkg/bar'; | ||
import {x} from '@pkg/foo'; | ||
|
||
import './baa'; | ||
import './baz'; // required | ||
|
||
import {bar} from '../bar'; | ||
import {xbar} from '../xbar'; | ||
|
||
export class Test {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
// comment outside of imports | ||
import {app_f} from 'app/foo'; | ||
import {x} from '@pkg/foo'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: default, ^app, ^@pkg, current dir, parent_dir.] | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] | ||
|
||
import {app_b} from 'app/bar'; | ||
// comment pkg/bar | ||
import {a} from '@pkg/bar'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] | ||
|
||
import {xbar} from '../xbar'; | ||
|
||
import {bar} from '../bar'; | ||
|
||
import {foo, afoo} from 'foo'; | ||
~~~~~~~~~ [Named imports must be alphabetized.] | ||
|
||
import './baz'; // required | ||
import './baa'; | ||
~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] | ||
|
||
import x = require('y'); | ||
|
||
export class Test {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"rules": { | ||
"ordered-imports": [ | ||
true, | ||
{ | ||
"import-sources-order": "case-insensitive", | ||
"named-imports-order": "case-insensitive", | ||
"grouped-imports": true, | ||
"groups": [ | ||
{ "match": "^app", "order": 20 }, | ||
{ "match": "^@pkg", "order": 30 }, | ||
{ "name": "parent_dir", "match": "^[.][.]", "order": 50 }, | ||
{ "name": "current dir", "match": "^[.]", "order": 40 }, | ||
{ "match": null, "order": 10 } | ||
] | ||
} | ||
] | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/rules/ordered-imports/groups-shared-order/test.ts.fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env node | ||
|
||
import {y} from 'app_a/bar'; | ||
import {x} from 'app_a/foo'; | ||
import {f} from 'app_b/foo'; | ||
|
||
import {b} from '@pkg/bar'; | ||
import {a} from '@pkg/foo'; | ||
|
||
import {o} from 'other/bar'; | ||
|
||
export class Test {} |
17 changes: 17 additions & 0 deletions
17
test/rules/ordered-imports/groups-shared-order/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env node | ||
|
||
import {f} from 'app_b/foo'; | ||
import {x} from 'app_a/foo'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] | ||
import {y} from 'app_a/bar'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] | ||
|
||
|
||
import {a} from '@pkg/foo'; | ||
|
||
import {b} from '@pkg/bar'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app_b, ^app_a, ^@pkg.] | ||
|
||
import {o} from 'other/bar'; | ||
|
||
export class Test {} |
17 changes: 17 additions & 0 deletions
17
test/rules/ordered-imports/groups-shared-order/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"rules": { | ||
"ordered-imports": [ | ||
true, | ||
{ | ||
"import-sources-order": "case-insensitive", | ||
"named-imports-order": "case-insensitive", | ||
"grouped-imports": true, | ||
"groups": [ | ||
{ "match": "^app_b", "order": 10 }, | ||
{ "match": "^app_a", "order": 10 }, | ||
{ "match": "^@pkg", "order": 20 } | ||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
import {app_b} from 'app/bar'; | ||
import {app_f} from 'app/foo'; | ||
|
||
import {a} from '@pkg/bar'; | ||
import {x} from '@pkg/foo'; | ||
|
||
import {foo} from 'foo'; | ||
import {xbar} from '../xbar'; | ||
import {b} from './ybar'; | ||
|
||
export class Test {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env node | ||
|
||
import {app_f} from 'app/foo'; | ||
|
||
import {x} from '@pkg/foo'; | ||
|
||
import {app_b} from 'app/bar'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: ^app, ^@pkg.] | ||
|
||
import {a} from '@pkg/bar'; | ||
|
||
import {xbar} from '../xbar'; | ||
|
||
import {foo} from 'foo'; | ||
import {b} from './ybar'; | ||
|
||
export class Test {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"rules": { | ||
"ordered-imports": [ | ||
true, | ||
{ | ||
"import-sources-order": "case-insensitive", | ||
"named-imports-order": "case-insensitive", | ||
"grouped-imports": true, | ||
"groups": [{ "match": "^app", "order": 20 }, { "match": "^@pkg", "order": 30 }] | ||
} | ||
] | ||
} | ||
} |