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 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
object-literal-sort-keys: Add match-declaration-order-only option
- Loading branch information
1 parent
9b7574b
commit 2b4306e
Showing
4 changed files
with
96 additions
and
4 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
71 changes: 71 additions & 0 deletions
71
test/rules/object-literal-sort-keys/match-declaration-order-only/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,71 @@ | ||
interface I { | ||
b; | ||
a; | ||
} | ||
|
||
declare function f(i: I): void; | ||
|
||
const a = 0, b = 0; | ||
|
||
f({ b, a }); | ||
|
||
f({ a, b }); | ||
~ [0 % ('b', 'I')] | ||
|
||
// Resets ordering after spread operator. | ||
|
||
f({ a, ...x, b }); | ||
|
||
f({ a, ...x, a, b }); | ||
~ [0 % ('b', 'I')] | ||
|
||
|
||
// Methods and getters/setters work like any other key. | ||
|
||
f({ b() {}, a() {} }); | ||
|
||
f({ a() {}, b() {} }); | ||
~ [0 % ('b', 'I')] | ||
|
||
f({ | ||
get b() {}, | ||
a, | ||
set b(v) {}, | ||
~ [0 % ('b', 'I')] | ||
}); | ||
|
||
f({ | ||
get b() {}, | ||
set b() {}, | ||
a, | ||
}); | ||
|
||
// Ignores computed properties. Does not ignore string / number keys. | ||
|
||
interface J { | ||
"foo"; | ||
2; | ||
[Symol.iterator]; | ||
} | ||
declare function j(j: J): void; | ||
j({ [Symbol.iterator]: 1, "foo": 1, 2: 1 }); | ||
j({ [Symbol.iterator]: 1, 2: 1, "foo": 1 }); | ||
~~~~~ [0 % ('foo', 'J')] | ||
|
||
// Works with anonymous type too. | ||
type T = { b, a }; | ||
const o: T = { a, b }; | ||
~ [0 % ('b', 'T')] | ||
|
||
const o: { b, a } = { a, b }; | ||
~ [1 % ('b')] | ||
|
||
// Non-alphabetical ordering is fine, even if it can't find a type. | ||
|
||
const o = { | ||
b, | ||
a, | ||
}; | ||
|
||
[0]: The key '%s' is not in the same order as it is in '%s'. | ||
[1]: The key '%s' is not in the same order as it is in its type declaration. |
1 change: 1 addition & 0 deletions
1
test/rules/object-literal-sort-keys/match-declaration-order-only/tsconfig.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 @@ | ||
{} |
5 changes: 5 additions & 0 deletions
5
test/rules/object-literal-sort-keys/match-declaration-order-only/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,5 @@ | ||
{ | ||
"rules": { | ||
"object-literal-sort-keys": [true, "ignore-case", "match-declaration-order-only"] | ||
} | ||
} |