Skip to content

Commit

Permalink
add new test cases from eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
KubaJastrz committed May 16, 2024
1 parent 315be77 commit 2cd7066
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions crates/oxc_linter/src/rules/eslint/object_shorthand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,14 @@ fn test() {
];

let fail = vec![
(
"var x = {
f: /* comment */ function() {
}
}",
None,
),
(
"var x = {
f /* comment */: function() {
}
}",
None,
),
("var x = {a: /* comment */ a}", None),
("var x = {a /* comment */: a}", None),
("var x = {a: (a /* comment */)}", None),
("var x = {'a': /* comment */ a}", None),
("var x = {'a' /* comment */: a}", None),
("var x = {'a': (a /* comment */)}", None),
("var x = {f: /* comment */ function() {}}", None),
("var x = {f /* comment */: function() {}}", None),
("var x = {a: a, b}", Some(json!(["consistent"]))),
("var x = {b, c: d, f: g}", Some(json!(["consistent"]))),
("var x = {foo, bar: baz, ...qux}", Some(json!(["consistent"]))),
Expand Down Expand Up @@ -812,6 +806,11 @@ fn test_avoid_explicit_return_arrows() {
];

let fix = vec![
(
"({ x: (arg => { return; }) })",
"({ x(arg) { return; } })",
Some(json!(["always", { "avoidExplicitReturnArrows": true }])),
),
(
"({ x: () => { return; } })",
"({ x() { return; } })",
Expand Down Expand Up @@ -1009,6 +1008,25 @@ fn test_avoid_explicit_return_arrows() {
"({ async a(arg, arg2) { return foo; } })",
Some(json!(["always", { "avoidExplicitReturnArrows": true }])),
),
(
"
const test = {
key: <T>(): void => { },
key: async <T>(): Promise<void> => { },
key: <T>(arg: T): T => { return arg },
key: async <T>(arg: T): Promise<T> => { return arg },
}
",
"
const test = {
key<T>(): void { },
async key<T>(): Promise<void> { },
key<T>(arg: T): T { return arg },
async key<T>(arg: T): Promise<T> { return arg },
}
",
Some(json!(["always", { "avoidExplicitReturnArrows": true }])),
),
(
"
const test = {
Expand Down

0 comments on commit 2cd7066

Please sign in to comment.