MCPcopy Create free account
hub / github.com/ampproject/amphtml / processVariables

Function processVariables

build-system/eslint-rules/prefer-destructuring.js:99–134  ·  view source on GitHub ↗

* @param {*} struct * @param {*} base

(struct, base)

Source from the content-addressed store, hash-verified

97 * @param {*} base
98 */
99 function processVariables(struct, base) {
100 const {declarations, names, node, nodes} = struct;
101
102 if (nodes.size === 0) {
103 return;
104 }
105
106 context.report({
107 node,
108 message: 'Combine repeated declarators into a destructure',
109 fix(fixer) {
110 const fixes = [];
111 const ids = [];
112
113 names.forEach((name) => ids.push(name));
114 const replacement = `{${ids.join(', ')}} = ${base}`;
115 fixes.push(fixer.replaceText(node, replacement));
116
117 declarations.forEach((declaration) => {
118 const {declarations} = declaration;
119 const all = declarations.every((decl) => nodes.has(decl));
120 if (!all) {
121 return;
122 }
123
124 fixes.push(fixer.remove(declaration));
125 declarations.forEach((decl) => nodes.delete(decl));
126 });
127
128 nodes.forEach((node) => {
129 fixes.push(fixer.remove(node));
130 });
131 return fixes;
132 },
133 });
134 }
135
136 return {
137 /**

Callers

nothing calls this directly

Calls 1

reportMethod · 0.45

Tested by

no test coverage detected