MCPcopy
hub / github.com/ampproject/amphtml / create

Function create

build-system/eslint-rules/prefer-spread-props.js:24–60  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

22 },
23
24 create(context) {
25 const sourceCode = context.getSourceCode();
26
27 return {
28 'CallExpression[callee.object.name="Object"][callee.property.name="assign"]':
29 function (node) {
30 const args = node.arguments;
31 if (args.length <= 1) {
32 return;
33 }
34
35 const first = args[0];
36 if (first.type !== 'ObjectExpression') {
37 return;
38 }
39 for (const arg of args) {
40 if (arg.type === 'SpreadElement') {
41 return;
42 }
43 }
44
45 context.report({
46 node,
47 message: 'Prefer using object literals with spread property syntax',
48
49 fix(fixer) {
50 const texts = args.map((arg) => `...${sourceCode.getText(arg)}`);
51 if (first.properties.length === 0) {
52 texts.shift();
53 }
54
55 return fixer.replaceText(node, `({${texts.join(',')}})`);
56 },
57 });
58 },
59 };
60 },
61};

Callers

nothing calls this directly

Calls 1

reportMethod · 0.45

Tested by

no test coverage detected