-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new rules for side effect only imports
- Loading branch information
1 parent
c0e6a41
commit 79965a3
Showing
13 changed files
with
123 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path="../../types/matchers.d.ts" /> | ||
import sideEffect | ||
from "../../../src/sort_rules/compare_imports/sideEffect"; | ||
|
||
describe("sort_rules/compare_imports/sideEffect", function() { | ||
const imports = [ | ||
`import a from "alpha";`, | ||
`import "beta";`, | ||
`import c from "charlie";`, | ||
`import "delta";` | ||
]; | ||
|
||
const expectedOutput = [ | ||
`import "beta";`, | ||
`import "delta";`, | ||
`import a from "alpha";`, | ||
`import c from "charlie";` | ||
]; | ||
|
||
it("should get sorted correctly", function() { | ||
expect(imports).toBeImportSorted(expectedOutput, sideEffect); | ||
}); | ||
}); |
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 @@ | ||
import Import from "../../../src/import_management/Import"; | ||
import separator from "../../../src/sort_rules/separate_by/unequalSideEffectUse"; | ||
import expectSeparator from "../../helpers/expectSeparator"; | ||
|
||
describe("sort_rules/separate_by/unequalsSideEffectUse", function() { | ||
const sideEffect = {isSideEffectOnly: true} as Import; | ||
const noSideEffect = {isSideEffectOnly: false} as Import; | ||
|
||
it("should set the separator correctly", function() { | ||
expectSeparator(separator).between(sideEffect).and(noSideEffect); | ||
expectSeparator(separator).between(noSideEffect).and(sideEffect); | ||
expectSeparator(separator).not.between(sideEffect).and(sideEffect); | ||
expectSeparator(separator).not.between(noSideEffect).and(noSideEffect); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ImportCompareFunction from "../ImportCompareFunction"; | ||
|
||
/** | ||
* Compares two imports whether they are for side effects only or not. | ||
* Imports with only side effects are considered lesser (higher position). | ||
* | ||
* <b>Example:</b> | ||
* ```ts | ||
* // unsorted | ||
* import a from "alpha"; | ||
* import "beta"; | ||
* import c from "charlie"; | ||
* | ||
* // sorted | ||
* import "beta"; | ||
* import a from "alpha"; | ||
* import c from "charlie"; | ||
* ``` | ||
* | ||
* @param a Import A | ||
* @param b Import B | ||
*/ | ||
const sideEffect: ImportCompareFunction = function(a, b) { | ||
const aDefault = a.isSideEffectOnly ? 0 : 1; | ||
const bDefault = b.isSideEffectOnly ? 0 : 1; | ||
return aDefault - bDefault; | ||
} | ||
|
||
export default sideEffect; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import SeparateByFunction from "../SeparateByFunction"; | ||
|
||
/** | ||
* Place a separator between two imports if one of them is importing only for | ||
* side effects. | ||
* | ||
* <b>Example:</b> | ||
* ```ts | ||
* // unseparated | ||
* import a from "alpha"; | ||
* import b from "bravo"; | ||
* import "charlie"; | ||
* import "delta"; | ||
* import e from "echo"; | ||
* | ||
* // separated | ||
* import a from "alpha"; | ||
* import b from "bravo"; | ||
* | ||
* import "charlie"; | ||
* import "delta"; | ||
* | ||
* import e from "echo"; | ||
* ``` | ||
* @see Import#isSideEffectOnly | ||
* @param l Leading Import | ||
* @param f Following Import | ||
*/ | ||
const unequalSideEffectUse: SeparateByFunction = function(l, f) { | ||
return l.isSideEffectOnly !== f.isSideEffectOnly; | ||
} | ||
|
||
export default unequalSideEffectUse; |