forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update orderedImports for standalone groups and source-order any
This change updates the refactored "group" based orderedImports code to handle the cases fixed in the following previous PRs: - palantir#4374: fixed grouping for import-sources-order - palantir#3733: check all imports of same type are grouped As part of this we removed the concept of ImportType as this is now covered by the defined groups for sorting. Moved the check for ensuring groups are not standing alone into the code checkBlocksGroup() code where other group checks are done. Ex: ``` import './baa'; import './baz'; import './caa'; // this should fail ``` Also had to update several other test cases to include the failure notice about import groups needing to be together.
- Loading branch information
Showing
12 changed files
with
75 additions
and
39 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
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
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"rules": { | ||
"ordered-imports": [true, {"import-sources-order": "case-insensitive", "named-imports-order": "case-insensitive", "grouped-imports": true}] | ||
"ordered-imports": [ | ||
true, { | ||
"import-sources-order": "case-insensitive", | ||
"named-imports-order": "case-insensitive", | ||
"grouped-imports": true | ||
}] | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ import { getOr } from 'lodash/fp' | |
import { Request } from 'express' | ||
|
||
import { getStatusCode } from './errors' | ||
|
7 changes: 2 additions & 5 deletions
7
test/rules/ordered-imports/import-sources-any/grouped-imports/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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { getOr } from 'lodash/fp' | ||
|
||
import { Request } from 'express' | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [1] | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: libraries, parent directories, current directory .] | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources with same group order must be grouped together.] | ||
import { getStatusCode } from './errors' | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [grouped-imports] | ||
|
||
[grouped-imports]: Import sources of different groups must be sorted by: libraries, parent directories, current directory. | ||
[1]: Import sources of the same type (package, same folder, different folder) must be grouped together. |
10 changes: 10 additions & 0 deletions
10
test/rules/ordered-imports/standalone-grouped-import/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,10 @@ | ||
#!/usr/bin/env node | ||
|
||
import {a} from 'foo'; | ||
import x = require('y'); | ||
|
||
import './baa'; | ||
import './baz'; | ||
import './caa'; | ||
|
||
export class Test {} |
15 changes: 15 additions & 0 deletions
15
test/rules/ordered-imports/standalone-grouped-import/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,15 @@ | ||
#!/usr/bin/env node | ||
|
||
import {a} from 'foo'; | ||
|
||
import './baa'; | ||
import './baz'; | ||
|
||
import './caa'; | ||
~~~~~~~~~~~~~~~ [Import sources of different groups must be sorted by: libraries, parent directories, current directory .] | ||
~~~~~~~~~~~~~~~ [Import sources with same group order must be grouped together.] | ||
|
||
import x = require('y'); | ||
~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources with same group order must be grouped together.] | ||
|
||
export class Test {} |
10 changes: 10 additions & 0 deletions
10
test/rules/ordered-imports/standalone-grouped-import/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,10 @@ | ||
{ | ||
"rules": { | ||
"ordered-imports": [ | ||
true, { | ||
"import-sources-order": "case-insensitive", | ||
"named-imports-order": "case-insensitive", | ||
"grouped-imports": true | ||
}] | ||
} | ||
} |