What version of Oxlint are you using?
1.57.0
What command did you run?
oxlint --fix
What does your .oxlintrc.json (or oxlint.config.ts) config file look like?
What happened?
In some cases the autofix for sort-keys can move keys - detaching them from inline comments. I would expect the inline comment to move with the property, or for there to not be an autofix available at all. This does not happen in all cases, but I have not figured out why.
Running on the following code, we get two different behaviors for the two different objects.
// Help + autofix available -> misplaces the inline comment
export const data1 = {
c: "c",
b: "b",
a: "a", // Comment on the a property
};
// Help + autofix not available
export const data2 = {
c: "c",
a: "a", // Comment on the a property
b: "b",
};
Running oxlint --fix we see that the first object gets its keys sorted, but the inline comment is now attached to the wrong property (as it stayed on the same line). The second object does not get autofixed, so it is fine.
$ npx oxlint --fix
× eslint(sort-keys): Object keys should be sorted
╭─[code.ts:9:22]
8 │ // Help + autofix not available
9 │ ╭─▶ export const data2 = {
10 │ │ c: "c",
11 │ │ a: "a", // Comment on the a property
12 │ │ b: "b",
13 │ ╰─▶ };
╰────
Found 0 warnings and 1 error.
Finished in 22ms on 1 file with 94 rules using 12 threads.
$ git diff
diff --git a/code.ts b/code.ts
index 57438fc..d01761d 100644
--- a/code.ts
+++ b/code.ts
@@ -1,8 +1,8 @@
// Help + autofix available -> misplaces the inline comment
export const data1 = {
- c: "c",
+ a: "a",
b: "b",
- a: "a", // Comment on the a property
+ c: "c", // Comment on the a property
};
// Help + autofix not available
$ cat code.ts
// Help + autofix available -> misplaces the inline comment
export const data1 = {
a: "a",
b: "b",
c: "c", // Comment on the a property
};
// Help + autofix not available
export const data2 = {
c: "c",
a: "a", // Comment on the a property
b: "b",
};
Restoring the code back to the original state and running without --fix, we see that the behavior matches with whether the command shows a "help" suggestion for the issue.
$ npx oxlint
× eslint(sort-keys): Object keys should be sorted
╭─[code.ts:2:22]
1 │ // Help + autofix available -> misplaces the inline comment
2 │ ╭─▶ export const data1 = {
3 │ │ c: "c",
4 │ │ b: "b",
5 │ │ a: "a", // Comment on the a property
6 │ ╰─▶ };
7 │
╰────
help: Replace `c: "c",
b: "b",
a: "a"` with `a: "a",
b: "b",
c: "c"`.
× eslint(sort-keys): Object keys should be sorted
╭─[code.ts:9:22]
8 │ // Help + autofix not available
9 │ ╭─▶ export const data2 = {
10 │ │ c: "c",
11 │ │ a: "a", // Comment on the a property
12 │ │ b: "b",
13 │ ╰─▶ };
╰────
Found 0 warnings and 2 errors.
Finished in 29ms on 1 file with 94 rules using 12 threads.
What version of Oxlint are you using?
1.57.0
What command did you run?
oxlint --fixWhat does your
.oxlintrc.json(oroxlint.config.ts) config file look like?{ "rules": { "sort-keys": "error" } }What happened?
In some cases the autofix for sort-keys can move keys - detaching them from inline comments. I would expect the inline comment to move with the property, or for there to not be an autofix available at all. This does not happen in all cases, but I have not figured out why.
Example (link to reproduction):
Running on the following code, we get two different behaviors for the two different objects.
Running
oxlint --fixwe see that the first object gets its keys sorted, but the inline comment is now attached to the wrong property (as it stayed on the same line). The second object does not get autofixed, so it is fine.$ npx oxlint --fix × eslint(sort-keys): Object keys should be sorted ╭─[code.ts:9:22] 8 │ // Help + autofix not available 9 │ ╭─▶ export const data2 = { 10 │ │ c: "c", 11 │ │ a: "a", // Comment on the a property 12 │ │ b: "b", 13 │ ╰─▶ }; ╰──── Found 0 warnings and 1 error. Finished in 22ms on 1 file with 94 rules using 12 threads. $ git diff diff --git a/code.ts b/code.ts index 57438fc..d01761d 100644 --- a/code.ts +++ b/code.ts @@ -1,8 +1,8 @@ // Help + autofix available -> misplaces the inline comment export const data1 = { - c: "c", + a: "a", b: "b", - a: "a", // Comment on the a property + c: "c", // Comment on the a property }; // Help + autofix not available $ cat code.ts // Help + autofix available -> misplaces the inline comment export const data1 = { a: "a", b: "b", c: "c", // Comment on the a property }; // Help + autofix not available export const data2 = { c: "c", a: "a", // Comment on the a property b: "b", };Restoring the code back to the original state and running without
--fix, we see that the behavior matches with whether the command shows a "help" suggestion for the issue.