Skip to content

Commit 1a41181

Browse files
authoredFeb 1, 2025··
feat(linter): implement eslint/prefer-object-spread (#8216)
implement [eslint:prefer-object-spread](https://eslint.org/docs/latest/rules/prefer-object-spread) (ref: #479)
1 parent 5041cb3 commit 1a41181

File tree

3 files changed

+1463
-1
lines changed

3 files changed

+1463
-1
lines changed
 

Diff for: ‎crates/oxc_linter/src/rules.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ mod eslint {
147147
pub mod prefer_exponentiation_operator;
148148
pub mod prefer_numeric_literals;
149149
pub mod prefer_object_has_own;
150+
pub mod prefer_object_spread;
150151
pub mod prefer_promise_reject_errors;
151152
pub mod prefer_rest_params;
152153
pub mod prefer_spread;
@@ -647,10 +648,11 @@ oxc_macros::declare_all_lint_rules! {
647648
eslint::no_void,
648649
eslint::no_with,
649650
eslint::prefer_promise_reject_errors,
650-
eslint::prefer_rest_params,
651651
eslint::prefer_exponentiation_operator,
652652
eslint::prefer_numeric_literals,
653653
eslint::prefer_object_has_own,
654+
eslint::prefer_object_spread,
655+
eslint::prefer_rest_params,
654656
eslint::prefer_spread,
655657
eslint::radix,
656658
eslint::require_await,
+947
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,947 @@
1+
use std::cmp::max;
2+
3+
use oxc_allocator::Box;
4+
use oxc_ast::ast::Expression;
5+
use oxc_ast::ast::ObjectExpression;
6+
use oxc_ast::ast::ObjectPropertyKind;
7+
use oxc_ast::ast::PropertyKind;
8+
use oxc_ast::AstKind;
9+
use oxc_diagnostics::OxcDiagnostic;
10+
use oxc_macros::declare_oxc_lint;
11+
use oxc_span::GetSpan;
12+
use oxc_span::Span;
13+
14+
use crate::{ast_util::is_method_call, context::LintContext, rule::Rule, AstNode};
15+
16+
fn prefer_object_spread_diagnostic(span: Span, for_use_literal: bool) -> OxcDiagnostic {
17+
let help_message = if for_use_literal {
18+
"Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`."
19+
} else {
20+
"Use an object spread instead of `Object.assign` eg: `{ ...foo }`."
21+
};
22+
OxcDiagnostic::warn("Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead")
23+
.with_help(help_message)
24+
.with_label(span)
25+
}
26+
27+
#[derive(Debug, Default, Clone)]
28+
pub struct PreferObjectSpread;
29+
30+
declare_oxc_lint!(
31+
/// ### What it does
32+
/// Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
33+
///
34+
/// ### Why is this bad?
35+
/// When `Object.assign` is called using an object literal as the first argument, this rule requires using the object spread syntax instead. This rule also warns on cases where an `Object.assign` call is made using a single argument that is an object literal, in this case, the `Object.assign` call is not needed.
36+
///
37+
/// ### Examples
38+
///
39+
/// Examples of **incorrect** code for this rule:
40+
/// ```js
41+
/// Object.assign({}, foo);
42+
///
43+
/// Object.assign({}, {foo: 'bar'});
44+
///
45+
/// Object.assign({ foo: 'bar'}, baz);
46+
///
47+
/// Object.assign({}, baz, { foo: 'bar' });
48+
///
49+
/// Object.assign({}, { ...baz });
50+
///
51+
/// // Object.assign with a single argument that is an object literal
52+
/// Object.assign({});
53+
///
54+
/// Object.assign({ foo: bar });
55+
/// ```
56+
///
57+
/// Examples of **correct** code for this rule:
58+
/// ```js
59+
/// ({ ...foo });
60+
///
61+
/// ({ ...baz, foo: 'bar' });
62+
///
63+
/// // Any Object.assign call without an object literal as the first argument
64+
/// Object.assign(foo, { bar: baz });
65+
///
66+
/// Object.assign(foo, bar);
67+
///
68+
/// Object.assign(foo, { bar, baz });
69+
///
70+
/// Object.assign(foo, { ...baz });
71+
/// ```
72+
PreferObjectSpread,
73+
eslint,
74+
style,
75+
fix
76+
);
77+
78+
impl Rule for PreferObjectSpread {
79+
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
80+
let AstKind::CallExpression(call_expr) = node.kind() else {
81+
return;
82+
};
83+
84+
if !is_method_call(call_expr, None, Some(&["assign"]), Some(1), None) {
85+
return;
86+
}
87+
88+
let Some(callee) = call_expr.callee.as_member_expression() else {
89+
return;
90+
};
91+
92+
match callee.object().get_inner_expression() {
93+
Expression::Identifier(ident) => {
94+
if ident.name != "Object" || !ctx.semantic().is_reference_to_global_variable(ident)
95+
{
96+
return;
97+
}
98+
}
99+
Expression::StaticMemberExpression(member_expr) => {
100+
if let Expression::Identifier(ident) = member_expr.object.get_inner_expression() {
101+
if ident.name != "globalThis"
102+
|| !ctx.semantic().is_reference_to_global_variable(ident)
103+
{
104+
return;
105+
}
106+
} else {
107+
return;
108+
}
109+
110+
if member_expr.property.name != "Object" {
111+
return;
112+
}
113+
}
114+
_ => return,
115+
}
116+
117+
let arguments_len = call_expr.arguments.len();
118+
119+
for (idx, arg) in call_expr.arguments.iter().enumerate() {
120+
let Some(Expression::ObjectExpression(obj_expr)) =
121+
arg.as_expression().map(oxc_ast::ast::Expression::get_inner_expression)
122+
else {
123+
if idx == 0 {
124+
return;
125+
}
126+
127+
if arg.is_spread() {
128+
return;
129+
}
130+
131+
continue;
132+
};
133+
134+
if arguments_len > 1 && has_get_or_set_property(obj_expr) {
135+
return;
136+
}
137+
}
138+
139+
ctx.diagnostic_with_fix(
140+
prefer_object_spread_diagnostic(call_expr.span(), arguments_len == 1),
141+
|fixer| {
142+
let fixer = fixer.for_multifix();
143+
let mut rule_fixes = fixer.new_fix_with_capacity(2 + call_expr.arguments.len() * 5);
144+
145+
let needs_paren = !matches!(
146+
ctx.nodes().parent_kind(node.id()),
147+
Some(
148+
AstKind::VariableDeclarator(_)
149+
| AstKind::ArrayExpressionElement(_)
150+
| AstKind::ReturnStatement(_)
151+
| AstKind::Argument(_)
152+
| AstKind::ObjectProperty(_)
153+
| AstKind::AssignmentExpression(_)
154+
)
155+
);
156+
157+
let Some(callee_left_paren_span) = find_char_span(ctx, call_expr, b'(') else {
158+
return fixer.noop();
159+
};
160+
161+
let (left, right) = if needs_paren { ("({", "})") } else { ("{", "}") };
162+
163+
rule_fixes.push(
164+
fixer
165+
.replace(Span::new(call_expr.span.start, callee_left_paren_span.end), left),
166+
);
167+
rule_fixes.push(
168+
fixer.replace(Span::new(call_expr.span.end - 1, call_expr.span.end), right),
169+
);
170+
171+
for arg in &call_expr.arguments {
172+
let Some(expression) = arg.as_expression() else {
173+
return fixer.noop();
174+
};
175+
176+
if let Expression::ObjectExpression(obj_expr) = expression {
177+
let delete_span_of_left = get_delete_span_of_left(obj_expr, ctx);
178+
179+
let delete_span_of_right = Span::new(
180+
max(
181+
get_delete_span_start_of_right(obj_expr, ctx),
182+
delete_span_of_left.end,
183+
),
184+
obj_expr.span.end,
185+
);
186+
187+
rule_fixes.push(fixer.delete_range(delete_span_of_left));
188+
rule_fixes.push(fixer.delete_range(delete_span_of_right));
189+
190+
if obj_expr.properties.is_empty()
191+
|| ctx.source_range(get_last_char_span(expression, 1, ctx).unwrap())
192+
== ","
193+
{
194+
if let Some(maybe_arg_comma_span) = get_char_span_after(expression, ctx)
195+
{
196+
if ctx.source_range(maybe_arg_comma_span) == "," {
197+
rule_fixes.push(fixer.delete_range(maybe_arg_comma_span));
198+
}
199+
}
200+
}
201+
} else {
202+
let span = expression.span();
203+
let replacement = if matches!(
204+
expression,
205+
Expression::ArrowFunctionExpression(_)
206+
| Expression::AssignmentExpression(_)
207+
| Expression::ConditionalExpression(_)
208+
) {
209+
format!("...({})", ctx.source_range(span))
210+
} else {
211+
format!("...{}", ctx.source_range(span))
212+
};
213+
214+
rule_fixes.push(fixer.replace(span, replacement));
215+
}
216+
}
217+
218+
rule_fixes
219+
},
220+
);
221+
}
222+
}
223+
224+
fn has_get_or_set_property(obj_expr: &ObjectExpression) -> bool {
225+
obj_expr.properties.iter().any(|p| {
226+
let ObjectPropertyKind::ObjectProperty(p) = p else {
227+
return false;
228+
};
229+
230+
p.kind == PropertyKind::Get || p.kind == PropertyKind::Set
231+
})
232+
}
233+
234+
/**
235+
* Find the span of the first character matches with target_char in the expression
236+
*/
237+
fn find_char_span(ctx: &LintContext, expr: &dyn GetSpan, target_char: u8) -> Option<Span> {
238+
let span = expr.span();
239+
for idx in memchr::memchr_iter(target_char, ctx.source_range(span).as_bytes()) {
240+
let idx = u32::try_from(idx).unwrap();
241+
242+
let current_span = Span::sized(span.start + idx, 1);
243+
244+
if ctx.comments().iter().any(|comment| comment.span.contains_inclusive(current_span)) {
245+
continue;
246+
}
247+
248+
return Some(current_span);
249+
}
250+
251+
None
252+
}
253+
254+
/**
255+
* Find the span of the first non-whitespace character before the expression.
256+
* (Includes character in the comment)
257+
*/
258+
fn get_char_span_before(start_char_span: Span, ctx: &LintContext) -> Option<Span> {
259+
let skip_count = start_char_span.start;
260+
let mut span_start = skip_count;
261+
for c in ctx.source_text()[..skip_count as usize].chars().rev() {
262+
let c_size = u32::try_from(c.len_utf8()).unwrap();
263+
span_start -= c_size;
264+
265+
if c.is_whitespace() {
266+
continue;
267+
}
268+
269+
let current_span = Span::sized(span_start, c_size);
270+
271+
return Some(current_span);
272+
}
273+
274+
None
275+
}
276+
277+
fn get_last_char_span(expr: &Expression, last_from: u32, ctx: &LintContext) -> Option<Span> {
278+
let expr_span = expr.span();
279+
let mut count: u32 = 0;
280+
let mut span_start = expr_span.end;
281+
for c in ctx.source_range(expr_span).chars().rev() {
282+
let c_size = u32::try_from(c.len_utf8()).unwrap();
283+
span_start -= c_size;
284+
285+
if c.is_whitespace() {
286+
continue;
287+
}
288+
289+
let current_span = Span::sized(span_start, c_size);
290+
291+
if ctx.comments().iter().any(|comment| comment.span.contains_inclusive(current_span)) {
292+
continue;
293+
}
294+
295+
count += 1;
296+
if count > last_from {
297+
return Some(current_span);
298+
}
299+
}
300+
301+
None
302+
}
303+
304+
/**
305+
* Find the span of the first non-whitespace character after the expression.
306+
* And ignore characters in the comment.
307+
*/
308+
fn get_char_span_after(expr: &Expression, ctx: &LintContext) -> Option<Span> {
309+
let skip_count = expr.span().end;
310+
let mut span_end = skip_count;
311+
for c in ctx.source_text()[skip_count as usize..].chars() {
312+
let c_size = u32::try_from(c.len_utf8()).unwrap();
313+
span_end += c_size;
314+
315+
if c.is_whitespace() {
316+
continue;
317+
}
318+
319+
let current_span = Span::new(span_end - c_size, span_end);
320+
321+
if ctx.comments().iter().any(|comment| comment.span.contains_inclusive(current_span)) {
322+
continue;
323+
}
324+
325+
return Some(current_span);
326+
}
327+
328+
None
329+
}
330+
331+
fn get_delete_span_of_left(obj_expr: &Box<'_, ObjectExpression<'_>>, ctx: &LintContext) -> Span {
332+
let mut span_end = obj_expr.span.start;
333+
for (i, c) in ctx.source_range(obj_expr.span).char_indices() {
334+
if i != 0 && !c.is_whitespace() {
335+
break;
336+
}
337+
338+
let c_size = u32::try_from(c.len_utf8()).unwrap();
339+
span_end += c_size;
340+
}
341+
342+
Span::new(obj_expr.span.start, span_end)
343+
}
344+
345+
fn get_delete_span_start_of_right(
346+
obj_expr: &Box<'_, ObjectExpression<'_>>,
347+
ctx: &LintContext,
348+
) -> u32 {
349+
let obj_expr_last_char_span = Span::new(obj_expr.span.end - 1, obj_expr.span.end);
350+
let Some(prev_token_span) = get_char_span_before(obj_expr_last_char_span, ctx) else {
351+
return obj_expr_last_char_span.start;
352+
};
353+
354+
let has_line_comment = if let Some(comment) =
355+
ctx.comments().iter().find(|&c| c.span.contains_inclusive(prev_token_span))
356+
{
357+
comment.is_line()
358+
} else {
359+
false
360+
};
361+
362+
if has_line_comment {
363+
return obj_expr_last_char_span.start;
364+
}
365+
366+
let mut span_start: u32 = obj_expr.span.end;
367+
for (i, c) in ctx.source_range(obj_expr.span).chars().rev().enumerate() {
368+
if i != 0 && !c.is_whitespace() {
369+
break;
370+
}
371+
372+
let c_size = u32::try_from(c.len_utf8()).unwrap();
373+
span_start -= c_size;
374+
}
375+
376+
span_start
377+
}
378+
379+
#[test]
380+
fn test() {
381+
use crate::tester::Tester;
382+
383+
let pass = vec![
384+
"Object.assign()",
385+
"let a = Object.assign(a, b)",
386+
"Object.assign(a, b)",
387+
"let a = Object.assign(b, { c: 1 })",
388+
"const bar = { ...foo }",
389+
"Object.assign(...foo)",
390+
"Object.assign(foo, { bar: baz })",
391+
"Object.assign/** comment😀 */(foo, { 'key😀': '😀😀' })", // with multi byte characters
392+
"Object.assign({}, ...objects)",
393+
"foo({ foo: 'bar' })",
394+
"
395+
const Object = {};
396+
Object.assign({}, foo);
397+
",
398+
// "
399+
// Object = {};
400+
// Object.assign({}, foo);
401+
// ",
402+
"
403+
const Object = {};
404+
Object.assign({ foo: 'bar' });
405+
",
406+
// "
407+
// Object = {};
408+
// Object.assign({ foo: 'bar' });
409+
// ",
410+
"
411+
const Object = require('foo');
412+
Object.assign({ foo: 'bar' });
413+
",
414+
"
415+
import Object from 'foo';
416+
Object.assign({ foo: 'bar' });
417+
",
418+
"
419+
import { Something as Object } from 'foo';
420+
Object.assign({ foo: 'bar' });
421+
",
422+
"
423+
import { Object, Array } from 'globals';
424+
Object.assign({ foo: 'bar' });
425+
",
426+
"
427+
var globalThis = foo;
428+
globalThis.Object.assign({}, foo)
429+
", // { "ecmaVersion": 2020 },
430+
"class C { #assign; foo() { Object.#assign({}, foo); } }", // { "ecmaVersion": 2022 },
431+
"Object.assign({ get a() {} }, {})",
432+
"Object.assign({ set a(val) {} }, {})",
433+
"Object.assign({ get a() {} }, foo)",
434+
"Object.assign({ set a(val) {} }, foo)",
435+
"Object.assign({ foo: 'bar', get a() {}, baz: 'quux' }, quuux)",
436+
"Object.assign({ foo: 'bar', set a(val) {} }, { baz: 'quux' })",
437+
"Object.assign({}, { get a() {} })",
438+
"Object.assign({}, { set a(val) {} })",
439+
"Object.assign({}, { foo: 'bar', get a() {} }, {})",
440+
"Object.assign({ foo }, bar, {}, { baz: 'quux', set a(val) {}, quuux }, {})",
441+
];
442+
443+
let fail = vec![
444+
"Object.assign({}, foo)",
445+
"Object.assign ({}, foo)",
446+
"Object.assign({}, { foo: 'bar' })",
447+
"Object.assign({}, baz, { foo: 'bar' })",
448+
"Object.assign({}, { foo: 'bar', baz: 'foo' })",
449+
"Object.assign/** comment😀 */({}, { '😀': '😀', '😆': '💪' })", // with multi byte characters
450+
"Object.assign({ foo: 'bar' }, baz)",
451+
"Object.assign({ foo: 'bar' }, cats, dogs, trees, birds)",
452+
"Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, baz))",
453+
"Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' })))",
454+
"Object.assign({foo: 'bar', ...bar}, baz)",
455+
"Object.assign({}, { foo, bar, baz })",
456+
"Object.assign({}, { [bar]: 'foo' })",
457+
"Object.assign({ ...bar }, { ...baz })",
458+
r#"
459+
Object.assign({ ...bar }, {
460+
// this is a bar
461+
foo: 'bar',
462+
baz: "cats"
463+
})
464+
"#,
465+
r#"
466+
Object.assign({
467+
boo: "lol",
468+
// I'm a comment
469+
dog: "cat"
470+
}, {
471+
// this is a bar
472+
foo: 'bar',
473+
baz: "cats"
474+
})
475+
"#,
476+
r#"
477+
const test = Object.assign({ ...bar }, {
478+
<!-- html comment
479+
foo: 'bar',
480+
baz: "cats"
481+
--> weird
482+
})
483+
"#, // { "sourceType": "script" },
484+
r#"
485+
const test = Object.assign({ ...bar }, {
486+
foo: 'bar', // inline comment
487+
baz: "cats"
488+
})
489+
"#,
490+
r#"
491+
const test = Object.assign({ ...bar }, {
492+
/**
493+
* foo
494+
*/
495+
foo: 'bar',
496+
baz: "cats"
497+
})
498+
"#,
499+
"Object.assign({})",
500+
"Object.assign({ foo: bar })",
501+
"
502+
const foo = 'bar';
503+
Object.assign({ foo: bar })
504+
",
505+
"
506+
foo = 'bar';
507+
Object.assign({ foo: bar })
508+
",
509+
"let a = Object.assign({})",
510+
"let a = Object.assign({}, a)",
511+
"let a = Object.assign ({}, a)",
512+
"let a = Object.assign({ a: 1 }, b)",
513+
"Object.assign( {}, a, b, )",
514+
"Object.assign({}, a ? b : {}, b => c, a = 2)",
515+
"
516+
const someVar = 'foo';
517+
Object.assign({}, a ? b : {}, b => c, a = 2)
518+
",
519+
"
520+
someVar = 'foo';
521+
Object.assign({}, a ? b : {}, b => c, a = 2)
522+
",
523+
"[1, 2, Object.assign({}, a)]",
524+
"const foo = Object.assign({}, a)",
525+
"function foo() { return Object.assign({}, a) }",
526+
"foo(Object.assign({}, a));",
527+
"const x = { foo: 'bar', baz: Object.assign({}, a) }",
528+
"
529+
import Foo from 'foo';
530+
Object.assign({ foo: Foo });",
531+
"
532+
import Foo from 'foo';
533+
Object.assign({}, Foo);",
534+
"
535+
const Foo = require('foo');
536+
Object.assign({ foo: Foo });",
537+
"
538+
import { Something as somethingelse } from 'foo';
539+
Object.assign({}, somethingelse);
540+
",
541+
"
542+
import { foo } from 'foo';
543+
Object.assign({ foo: Foo });
544+
",
545+
"
546+
const Foo = require('foo');
547+
Object.assign({}, Foo);
548+
",
549+
"
550+
const actions = Object.assign(
551+
{
552+
onChangeInput: this.handleChangeInput,
553+
},
554+
this.props.actions
555+
);
556+
",
557+
"
558+
const actions = Object.assign(
559+
{
560+
onChangeInput: this.handleChangeInput, //
561+
},
562+
this.props.actions
563+
);
564+
",
565+
"
566+
const actions = Object.assign(
567+
{
568+
onChangeInput: this.handleChangeInput //
569+
},
570+
this.props.actions
571+
);
572+
",
573+
"
574+
const actions = Object.assign(
575+
(
576+
{
577+
onChangeInput: this.handleChangeInput
578+
}
579+
),
580+
(
581+
this.props.actions
582+
)
583+
);
584+
",
585+
"eventData = Object.assign({}, eventData, { outsideLocality: `${originLocality} - ${destinationLocality}` })",
586+
"Object.assign({ });",
587+
"Object.assign({\n});",
588+
"globalThis.Object.assign({ });", // { "ecmaVersion": 2020 },
589+
"globalThis.Object.assign({\n});", // { "ecmaVersion": 2020 },
590+
"globalThis.Object.assign({}, foo)",
591+
"globalThis.Object.assign({}, { foo: 'bar' })", // { "ecmaVersion": 6 },
592+
"globalThis.Object.assign({}, baz, { foo: 'bar' })", // { "ecmaVersion": 2017 },
593+
"
594+
function foo () { var globalThis = bar; }
595+
globalThis.Object.assign({ });
596+
", // { "ecmaVersion": 2020 },
597+
"
598+
const Foo = require('foo');
599+
globalThis.Object.assign({ foo: Foo });
600+
", // { "ecmaVersion": 2020 },
601+
"Object.assign({ get a() {}, set b(val) {} })",
602+
"const obj = Object.assign<{}, Record<string, string[]>>({}, getObject());", // { "parser": require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") },
603+
"Object.assign<{}, A>({}, foo);", // { "parser": require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") }
604+
];
605+
606+
let fix = vec![
607+
("Object.assign({}, foo)", "({ ...foo})", None),
608+
("Object.assign ({}, foo)", "({ ...foo})", None),
609+
("Object.assign({}, { foo: 'bar' })", "({ foo: 'bar'})", None),
610+
("Object.assign({}, baz, { foo: 'bar' })", "({ ...baz, foo: 'bar'})", None),
611+
("Object.assign({}, { foo: 'bar', baz: 'foo' })", "({ foo: 'bar', baz: 'foo'})", None),
612+
(r"Object.assign/** comment with multi byte 😀 */({}, { '😀': '😀', '😆': '💪' })", r"({ '😀': '😀', '😆': '💪'})", None),
613+
("Object.assign({ foo: 'bar' }, baz)", "({foo: 'bar', ...baz})", None),
614+
("Object.assign({ foo: 'bar' }, cats, dogs, trees, birds)", "({foo: 'bar', ...cats, ...dogs, ...trees, ...birds})", None),
615+
("Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, baz))", "({foo: 'bar', ...Object.assign({ bar: 'foo' }, baz)})", None),
616+
("Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' })))", "({foo: 'bar', ...Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' }))})", None),
617+
("Object.assign({foo: 'bar', ...bar}, baz)", "({foo: 'bar', ...bar, ...baz})", None),
618+
("Object.assign({}, { foo, bar, baz })", "({ foo, bar, baz})", None),
619+
("Object.assign({}, { [bar]: 'foo' })", "({ [bar]: 'foo'})", None),
620+
("Object.assign({ ...bar }, { ...baz })", "({...bar, ...baz})", None),
621+
(
622+
r#"
623+
Object.assign({ ...bar }, {
624+
// this is a bar
625+
foo: 'bar',
626+
baz: "cats"
627+
})
628+
"#,
629+
r#"
630+
({...bar, // this is a bar
631+
foo: 'bar',
632+
baz: "cats"})
633+
"#,
634+
None
635+
),
636+
(
637+
r#"
638+
Object.assign({
639+
boo: "lol",
640+
// I'm a comment
641+
dog: "cat"
642+
}, {
643+
// this is a bar
644+
foo: 'bar',
645+
baz: "cats"
646+
})
647+
"#,
648+
r#"
649+
({boo: "lol",
650+
// I'm a comment
651+
dog: "cat", // this is a bar
652+
foo: 'bar',
653+
baz: "cats"})
654+
"#,
655+
None
656+
),
657+
(
658+
r#"
659+
const test = Object.assign({ ...bar }, {
660+
/* comment
661+
foo: 'bar',
662+
baz: "cats"
663+
*/ weird
664+
})
665+
"#,
666+
r#"
667+
const test = {...bar, /* comment
668+
foo: 'bar',
669+
baz: "cats"
670+
*/ weird}
671+
"#,
672+
None
673+
),
674+
(
675+
r#"
676+
const test = Object.assign({ ...bar }, {
677+
foo: 'bar', // inline comment
678+
baz: "cats"
679+
})
680+
"#,
681+
r#"
682+
const test = {...bar, foo: 'bar', // inline comment
683+
baz: "cats"}
684+
"#,
685+
None
686+
),
687+
(
688+
r#"
689+
const test = Object.assign({ ...bar }, {
690+
/**
691+
* foo
692+
*/
693+
foo: 'bar',
694+
baz: "cats"
695+
})
696+
"#,
697+
r#"
698+
const test = {...bar, /**
699+
* foo
700+
*/
701+
foo: 'bar',
702+
baz: "cats"}
703+
"#,
704+
None
705+
),
706+
("Object.assign({})", "({})", None),
707+
("Object.assign({ foo: bar })", "({foo: bar})", None),
708+
(
709+
"
710+
const foo = 'bar';
711+
Object.assign({ foo: bar })
712+
",
713+
"
714+
const foo = 'bar';
715+
({foo: bar})
716+
",
717+
None
718+
),
719+
(
720+
"
721+
foo = 'bar';
722+
Object.assign({ foo: bar })
723+
",
724+
"
725+
foo = 'bar';
726+
({foo: bar})
727+
",
728+
None
729+
),
730+
("let a = Object.assign({})", "let a = {}", None),
731+
("let a = Object.assign({}, a)", "let a = { ...a}", None),
732+
("let a = Object.assign ({}, a)", "let a = { ...a}", None),
733+
("let a = Object.assign({ a: 1 }, b)", "let a = {a: 1, ...b}", None),
734+
("Object.assign( {}, a, b, )", "({ ...a, ...b, })", None),
735+
("Object.assign({}, a ? b : {}, b => c, a = 2)", "({ ...(a ? b : {}), ...(b => c), ...(a = 2)})", None),
736+
(
737+
"
738+
const someVar = 'foo';
739+
Object.assign({}, a ? b : {}, b => c, a = 2)
740+
",
741+
"
742+
const someVar = 'foo';
743+
({ ...(a ? b : {}), ...(b => c), ...(a = 2)})
744+
",
745+
None
746+
),
747+
(
748+
"
749+
someVar = 'foo';
750+
Object.assign({}, a ? b : {}, b => c, a = 2)
751+
",
752+
"
753+
someVar = 'foo';
754+
({ ...(a ? b : {}), ...(b => c), ...(a = 2)})
755+
",
756+
None
757+
),
758+
("[1, 2, Object.assign({}, a)]", "[1, 2, { ...a}]", None),
759+
("const foo = Object.assign({}, a)", "const foo = { ...a}", None),
760+
("function foo() { return Object.assign({}, a) }", "function foo() { return { ...a} }", None),
761+
("foo(Object.assign({}, a));", "foo({ ...a});", None),
762+
("const x = { foo: 'bar', baz: Object.assign({}, a) }", "const x = { foo: 'bar', baz: { ...a} }", None),
763+
(
764+
"
765+
import Foo from 'foo';
766+
Object.assign({ foo: Foo });
767+
",
768+
"
769+
import Foo from 'foo';
770+
({foo: Foo});
771+
",
772+
None
773+
),
774+
(
775+
"
776+
import Foo from 'foo';
777+
Object.assign({}, Foo);
778+
",
779+
"
780+
import Foo from 'foo';
781+
({ ...Foo});
782+
",
783+
None
784+
),
785+
(
786+
"
787+
const Foo = require('foo');
788+
Object.assign({ foo: Foo });
789+
",
790+
"
791+
const Foo = require('foo');
792+
({foo: Foo});
793+
",
794+
None
795+
),
796+
(
797+
"
798+
import { Something as somethingelse } from 'foo';
799+
Object.assign({}, somethingelse);
800+
",
801+
"
802+
import { Something as somethingelse } from 'foo';
803+
({ ...somethingelse});
804+
",
805+
None
806+
),
807+
(
808+
"
809+
import { foo } from 'foo';
810+
Object.assign({ foo: Foo });
811+
",
812+
"
813+
import { foo } from 'foo';
814+
({foo: Foo});
815+
",
816+
None
817+
),
818+
(
819+
"
820+
const Foo = require('foo');
821+
Object.assign({}, Foo);
822+
",
823+
"
824+
const Foo = require('foo');
825+
({ ...Foo});
826+
",
827+
None
828+
),
829+
(
830+
"
831+
const actions = Object.assign(
832+
{
833+
onChangeInput: this.handleChangeInput,
834+
},
835+
this.props.actions
836+
);
837+
",
838+
"
839+
const actions = {
840+
onChangeInput: this.handleChangeInput,
841+
...this.props.actions
842+
};
843+
",
844+
None
845+
),
846+
(
847+
"
848+
const actions = Object.assign(
849+
{
850+
onChangeInput: this.handleChangeInput, //
851+
}, // comment 2
852+
this.props.actions
853+
);
854+
",
855+
"
856+
const actions = {
857+
onChangeInput: this.handleChangeInput, //
858+
// comment 2
859+
...this.props.actions
860+
};
861+
",
862+
None
863+
),
864+
(
865+
"
866+
const actions = Object.assign(
867+
{
868+
onChangeInput: this.handleChangeInput //
869+
},
870+
this.props.actions
871+
);
872+
",
873+
"
874+
const actions = {
875+
onChangeInput: this.handleChangeInput //
876+
,
877+
...this.props.actions
878+
};
879+
",
880+
None
881+
),
882+
(
883+
"
884+
const actions = Object.assign(
885+
(
886+
{
887+
onChangeInput: this.handleChangeInput
888+
}
889+
),
890+
(
891+
this.props.actions
892+
)
893+
);
894+
",
895+
"
896+
const actions = {
897+
...(
898+
{
899+
onChangeInput: this.handleChangeInput
900+
}
901+
),
902+
...(
903+
this.props.actions
904+
)
905+
};
906+
",
907+
None
908+
),
909+
(
910+
"eventData = Object.assign({}, eventData, { outsideLocality: `${originLocality} - ${destinationLocality}` })",
911+
"eventData = { ...eventData, outsideLocality: `${originLocality} - ${destinationLocality}`}",
912+
None
913+
),
914+
("Object.assign({ });", "({});", None),
915+
("Object.assign({\n});", "({});", None),
916+
("globalThis.Object.assign({ });", "({});", None),
917+
("globalThis.Object.assign({\n});", "({});", None),
918+
(
919+
"
920+
function foo () { var globalThis = bar; }
921+
globalThis.Object.assign({ });
922+
",
923+
"
924+
function foo () { var globalThis = bar; }
925+
({});
926+
",
927+
None
928+
),
929+
(
930+
"
931+
const Foo = require('foo');
932+
globalThis.Object.assign({ foo: Foo });
933+
",
934+
"
935+
const Foo = require('foo');
936+
({foo: Foo});
937+
",
938+
None
939+
),
940+
("Object.assign({ get a() {}, set b(val) {} })", "({get a() {}, set b(val) {}})", None),
941+
("const obj = Object.assign<{}, Record<string, string[]>>({}, getObject());", "const obj = { ...getObject()};", None),
942+
("Object.assign<{}, A>({}, foo);", "({ ...foo});", None)
943+
];
944+
Tester::new(PreferObjectSpread::NAME, PreferObjectSpread::PLUGIN, pass, fail)
945+
.expect_fix(fix)
946+
.test_and_snapshot();
947+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,513 @@
1+
---
2+
source: crates/oxc_linter/src/tester.rs
3+
assertion_line: 356
4+
snapshot_kind: text
5+
---
6+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
7+
╭─[prefer_object_spread.tsx:1:1]
8+
1Object.assign({}, foo)
9+
· ──────────────────────
10+
╰────
11+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
12+
13+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
14+
╭─[prefer_object_spread.tsx:1:1]
15+
1Object.assign ({}, foo)
16+
· ────────────────────────
17+
╰────
18+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
19+
20+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
21+
╭─[prefer_object_spread.tsx:1:1]
22+
1Object.assign({}, { foo: 'bar' })
23+
· ─────────────────────────────────
24+
╰────
25+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
26+
27+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
28+
╭─[prefer_object_spread.tsx:1:1]
29+
1Object.assign({}, baz, { foo: 'bar' })
30+
· ──────────────────────────────────────
31+
╰────
32+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
33+
34+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
35+
╭─[prefer_object_spread.tsx:1:1]
36+
1Object.assign({}, { foo: 'bar', baz: 'foo' })
37+
· ─────────────────────────────────────────────
38+
╰────
39+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
40+
41+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
42+
╭─[prefer_object_spread.tsx:1:1]
43+
1Object.assign/** comment😀 */({}, { '😀': '😀', '😆': '💪' })
44+
· ─────────────────────────────────────────────────────────────
45+
╰────
46+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
47+
48+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
49+
╭─[prefer_object_spread.tsx:1:1]
50+
1Object.assign({ foo: 'bar' }, baz)
51+
· ──────────────────────────────────
52+
╰────
53+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
54+
55+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
56+
╭─[prefer_object_spread.tsx:1:1]
57+
1Object.assign({ foo: 'bar' }, cats, dogs, trees, birds)
58+
· ───────────────────────────────────────────────────────
59+
╰────
60+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
61+
62+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
63+
╭─[prefer_object_spread.tsx:1:1]
64+
1Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, baz))
65+
· ─────────────────────────────────────────────────────────────────
66+
╰────
67+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
68+
69+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
70+
╭─[prefer_object_spread.tsx:1:31]
71+
1Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, baz))
72+
· ──────────────────────────────────
73+
╰────
74+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
75+
76+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
77+
╭─[prefer_object_spread.tsx:1:1]
78+
1Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' })))
79+
· ──────────────────────────────────────────────────────────────────────────────────────────────────────────
80+
╰────
81+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
82+
83+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
84+
╭─[prefer_object_spread.tsx:1:31]
85+
1Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' })))
86+
· ───────────────────────────────────────────────────────────────────────────
87+
╰────
88+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
89+
90+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
91+
╭─[prefer_object_spread.tsx:1:61]
92+
1Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }, Object.assign({}, { superNested: 'butwhy' })))
93+
· ────────────────────────────────────────────
94+
╰────
95+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
96+
97+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
98+
╭─[prefer_object_spread.tsx:1:1]
99+
1Object.assign({foo: 'bar', ...bar}, baz)
100+
· ────────────────────────────────────────
101+
╰────
102+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
103+
104+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
105+
╭─[prefer_object_spread.tsx:1:1]
106+
1Object.assign({}, { foo, bar, baz })
107+
· ────────────────────────────────────
108+
╰────
109+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
110+
111+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
112+
╭─[prefer_object_spread.tsx:1:1]
113+
1Object.assign({}, { [bar]: 'foo' })
114+
· ───────────────────────────────────
115+
╰────
116+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
117+
118+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
119+
╭─[prefer_object_spread.tsx:1:1]
120+
1Object.assign({ ...bar }, { ...baz })
121+
· ─────────────────────────────────────
122+
╰────
123+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
124+
125+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
126+
╭─[prefer_object_spread.tsx:2:9]
127+
1
128+
2 │ ╭─▶ Object.assign({ ...bar }, {
129+
3 │ │ // this is a bar
130+
4 │ │ foo: 'bar',
131+
5 │ │ baz: "cats"
132+
6 │ ╰─▶ })
133+
7
134+
╰────
135+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
136+
137+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
138+
╭─[prefer_object_spread.tsx:2:9]
139+
1
140+
2 │ ╭─▶ Object.assign({
141+
3 │ │ boo: "lol",
142+
4 │ │ // I'm a comment
143+
5 │ │ dog: "cat"
144+
6 │ │ }, {
145+
7 │ │ // this is a bar
146+
8 │ │ foo: 'bar',
147+
9 │ │ baz: "cats"
148+
10 │ ╰─▶ })
149+
11
150+
╰────
151+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
152+
153+
× Unexpected token
154+
╭─[prefer_object_spread.tsx:3:13]
155+
2const test = Object.assign({ ...bar }, {
156+
3 │ <!-- html comment
157+
· ─
158+
4 │ foo: 'bar',
159+
╰────
160+
161+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
162+
╭─[prefer_object_spread.tsx:2:22]
163+
1 │
164+
2 │ ╭─▶ const test = Object.assign({ ...bar }, {
165+
3 │ │ foo: 'bar', // inline comment
166+
4 │ │ baz: "cats"
167+
5 │ ╰─▶ })
168+
6 │
169+
╰────
170+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
171+
172+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
173+
╭─[prefer_object_spread.tsx:2:22]
174+
1 │
175+
2 │ ╭─▶ const test = Object.assign({ ...bar }, {
176+
3 │ │ /**
177+
4 │ │ * foo
178+
5 │ │ */
179+
6 │ │ foo: 'bar',
180+
7 │ │ baz: "cats"
181+
8 │ ╰─▶ })
182+
9 │
183+
╰────
184+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
185+
186+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
187+
╭─[prefer_object_spread.tsx:1:1]
188+
1 │ Object.assign({})
189+
· ─────────────────
190+
╰────
191+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
192+
193+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
194+
╭─[prefer_object_spread.tsx:1:1]
195+
1 │ Object.assign({ foo: bar })
196+
· ───────────────────────────
197+
╰────
198+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
199+
200+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
201+
╭─[prefer_object_spread.tsx:3:9]
202+
2 │ const foo = 'bar';
203+
3 │ Object.assign({ foo: bar })
204+
· ───────────────────────────
205+
4 │
206+
╰────
207+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
208+
209+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
210+
╭─[prefer_object_spread.tsx:3:9]
211+
2 │ foo = 'bar';
212+
3 │ Object.assign({ foo: bar })
213+
· ───────────────────────────
214+
4 │
215+
╰────
216+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
217+
218+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
219+
╭─[prefer_object_spread.tsx:1:9]
220+
1 │ let a = Object.assign({})
221+
· ─────────────────
222+
╰────
223+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
224+
225+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
226+
╭─[prefer_object_spread.tsx:1:9]
227+
1 │ let a = Object.assign({}, a)
228+
· ────────────────────
229+
╰────
230+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
231+
232+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
233+
╭─[prefer_object_spread.tsx:1:9]
234+
1 │ let a = Object.assign ({}, a)
235+
· ───────────────────────
236+
╰────
237+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
238+
239+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
240+
╭─[prefer_object_spread.tsx:1:9]
241+
1 │ let a = Object.assign({ a: 1 }, b)
242+
· ──────────────────────────
243+
╰────
244+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
245+
246+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
247+
╭─[prefer_object_spread.tsx:1:1]
248+
1 │ Object.assign( {}, a, b, )
249+
· ───────────────────────────────────
250+
╰────
251+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
252+
253+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
254+
╭─[prefer_object_spread.tsx:1:1]
255+
1 │ Object.assign({}, a ? b : {}, b => c, a = 2)
256+
· ────────────────────────────────────────────
257+
╰────
258+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
259+
260+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
261+
╭─[prefer_object_spread.tsx:3:9]
262+
2 │ const someVar = 'foo';
263+
3 │ Object.assign({}, a ? b : {}, b => c, a = 2)
264+
· ────────────────────────────────────────────
265+
4 │
266+
╰────
267+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
268+
269+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
270+
╭─[prefer_object_spread.tsx:3:9]
271+
2 │ someVar = 'foo';
272+
3 │ Object.assign({}, a ? b : {}, b => c, a = 2)
273+
· ────────────────────────────────────────────
274+
4 │
275+
╰────
276+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
277+
278+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
279+
╭─[prefer_object_spread.tsx:1:8]
280+
1 │ [1, 2, Object.assign({}, a)]
281+
· ────────────────────
282+
╰────
283+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
284+
285+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
286+
╭─[prefer_object_spread.tsx:1:13]
287+
1 │ const foo = Object.assign({}, a)
288+
· ────────────────────
289+
╰────
290+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
291+
292+
⚠ eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
293+
╭─[prefer_object_spread.tsx:1:25]
294+
1 │ function foo() { return Object.assign({}, a) }
295+
· ────────────────────
296+
╰────
297+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
298+
299+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
300+
╭─[prefer_object_spread.tsx:1:5]
301+
1foo(Object.assign({}, a));
302+
· ────────────────────
303+
╰────
304+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
305+
306+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
307+
╭─[prefer_object_spread.tsx:1:30]
308+
1const x = { foo: 'bar', baz: Object.assign({}, a) }
309+
· ────────────────────
310+
╰────
311+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
312+
313+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
314+
╭─[prefer_object_spread.tsx:3:9]
315+
2import Foo from 'foo';
316+
3Object.assign({ foo: Foo });
317+
· ───────────────────────────
318+
╰────
319+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
320+
321+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
322+
╭─[prefer_object_spread.tsx:3:9]
323+
2import Foo from 'foo';
324+
3Object.assign({}, Foo);
325+
· ──────────────────────
326+
╰────
327+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
328+
329+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
330+
╭─[prefer_object_spread.tsx:3:9]
331+
2const Foo = require('foo');
332+
3Object.assign({ foo: Foo });
333+
· ───────────────────────────
334+
╰────
335+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
336+
337+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
338+
╭─[prefer_object_spread.tsx:3:9]
339+
2import { Something as somethingelse } from 'foo';
340+
3Object.assign({}, somethingelse);
341+
· ────────────────────────────────
342+
4
343+
╰────
344+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
345+
346+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
347+
╭─[prefer_object_spread.tsx:3:9]
348+
2import { foo } from 'foo';
349+
3Object.assign({ foo: Foo });
350+
· ───────────────────────────
351+
4
352+
╰────
353+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
354+
355+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
356+
╭─[prefer_object_spread.tsx:3:9]
357+
2const Foo = require('foo');
358+
3Object.assign({}, Foo);
359+
· ──────────────────────
360+
4
361+
╰────
362+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
363+
364+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
365+
╭─[prefer_object_spread.tsx:2:25]
366+
1
367+
2 │ ╭─▶ const actions = Object.assign(
368+
3 │ │ {
369+
4 │ │ onChangeInput: this.handleChangeInput,
370+
5 │ │ },
371+
6 │ │ this.props.actions
372+
7 │ ╰─▶ );
373+
8
374+
╰────
375+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
376+
377+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
378+
╭─[prefer_object_spread.tsx:2:25]
379+
1
380+
2 │ ╭─▶ const actions = Object.assign(
381+
3 │ │ {
382+
4 │ │ onChangeInput: this.handleChangeInput, //
383+
5 │ │ },
384+
6 │ │ this.props.actions
385+
7 │ ╰─▶ );
386+
8
387+
╰────
388+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
389+
390+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
391+
╭─[prefer_object_spread.tsx:2:25]
392+
1
393+
2 │ ╭─▶ const actions = Object.assign(
394+
3 │ │ {
395+
4 │ │ onChangeInput: this.handleChangeInput //
396+
5 │ │ },
397+
6 │ │ this.props.actions
398+
7 │ ╰─▶ );
399+
8
400+
╰────
401+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
402+
403+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
404+
╭─[prefer_object_spread.tsx:2:25]
405+
1
406+
2 │ ╭─▶ const actions = Object.assign(
407+
3 │ │ (
408+
4 │ │ {
409+
5 │ │ onChangeInput: this.handleChangeInput
410+
6 │ │ }
411+
7 │ │ ),
412+
8 │ │ (
413+
9 │ │ this.props.actions
414+
10 │ │ )
415+
11 │ ╰─▶ );
416+
12
417+
╰────
418+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
419+
420+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
421+
╭─[prefer_object_spread.tsx:1:13]
422+
1eventData = Object.assign({}, eventData, { outsideLocality: `${originLocality} - ${destinationLocality}` })
423+
· ───────────────────────────────────────────────────────────────────────────────────────────────
424+
╰────
425+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
426+
427+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
428+
╭─[prefer_object_spread.tsx:1:1]
429+
1Object.assign({ });
430+
· ──────────────────
431+
╰────
432+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
433+
434+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
435+
╭─[prefer_object_spread.tsx:1:1]
436+
1 │ ╭─▶ Object.assign({
437+
2 │ ╰─▶ });
438+
╰────
439+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
440+
441+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
442+
╭─[prefer_object_spread.tsx:1:1]
443+
1globalThis.Object.assign({ });
444+
· ─────────────────────────────
445+
╰────
446+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
447+
448+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
449+
╭─[prefer_object_spread.tsx:1:1]
450+
1 │ ╭─▶ globalThis.Object.assign({
451+
2 │ ╰─▶ });
452+
╰────
453+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
454+
455+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
456+
╭─[prefer_object_spread.tsx:1:1]
457+
1globalThis.Object.assign({}, foo)
458+
· ─────────────────────────────────
459+
╰────
460+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
461+
462+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
463+
╭─[prefer_object_spread.tsx:1:1]
464+
1globalThis.Object.assign({}, { foo: 'bar' })
465+
· ────────────────────────────────────────────
466+
╰────
467+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
468+
469+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
470+
╭─[prefer_object_spread.tsx:1:1]
471+
1globalThis.Object.assign({}, baz, { foo: 'bar' })
472+
· ─────────────────────────────────────────────────
473+
╰────
474+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
475+
476+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
477+
╭─[prefer_object_spread.tsx:3:9]
478+
2function foo () { var globalThis = bar; }
479+
3globalThis.Object.assign({ });
480+
· ─────────────────────────────
481+
4
482+
╰────
483+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
484+
485+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
486+
╭─[prefer_object_spread.tsx:3:9]
487+
2const Foo = require('foo');
488+
3globalThis.Object.assign({ foo: Foo });
489+
· ──────────────────────────────────────
490+
4
491+
╰────
492+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
493+
494+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
495+
╭─[prefer_object_spread.tsx:1:1]
496+
1Object.assign({ get a() {}, set b(val) {} })
497+
· ────────────────────────────────────────────
498+
╰────
499+
help: Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`.
500+
501+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
502+
╭─[prefer_object_spread.tsx:1:13]
503+
1const obj = Object.assign<{}, Record<string, string[]>>({}, getObject());
504+
· ────────────────────────────────────────────────────────────
505+
╰────
506+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.
507+
508+
eslint(prefer-object-spread): Disallow using `Object.assign` with an object literal as the first argument and prefer the use of object spread instead
509+
╭─[prefer_object_spread.tsx:1:1]
510+
1Object.assign<{}, A>({}, foo);
511+
· ─────────────────────────────
512+
╰────
513+
help: Use an object spread instead of `Object.assign` eg: `{ ...foo }`.

0 commit comments

Comments
 (0)
Please sign in to comment.