Skip to content

Commit e14b138

Browse files
committed
Remove array destructuring
1 parent 55152fd commit e14b138

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

lib/rules/jsx-no-literals.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ function normalizeConfig(config, handleElementOverrides) {
142142
normalizedConfig.elementOverrides = fromEntries(
143143
reduce(
144144
iterFrom(entries(config.elementOverrides)),
145-
(acc, [key, value]) => {
145+
(acc, entry) => {
146+
const key = entry[0];
147+
const value = entry[1];
148+
149+
if (!(key && value)) return acc;
146150
if (!reOverridableElement.test(key)) return acc;
151+
147152
acc.push([
148153
key,
149154
Object.assign(normalizeConfig(value, false), {
@@ -241,12 +246,15 @@ module.exports = {
241246
* Gets the name of the given JSX element. Supports nested
242247
* JSXMemeberExpressions. ie `<Namesapce.Component.SubComponent />`
243248
* @param {ASTNode} node
244-
* @returns {(string | undefined)[] | undefined}
249+
* @returns {{ name: string; compoundName: string | undefined } | undefined}
245250
*/
246251
function getJSXElementName(node) {
247252
if (node.openingElement.name.type === 'JSXIdentifier') {
248253
const name = node.openingElement.name.name;
249-
return [renamedImportMap.get(name) || name, undefined];
254+
return {
255+
name: renamedImportMap.get(name) || name,
256+
compoundName: undefined,
257+
}
250258
}
251259

252260
/** @type {string[]} */
@@ -276,7 +284,10 @@ module.exports = {
276284

277285
const nameFragment = nameFragments[nameFragments.length - 1];
278286
if (nameFragment) {
279-
return [nameFragment, nameFragments.join('.')];
287+
return {
288+
name: nameFragment,
289+
compoundName: nameFragments.join('.'),
290+
}
280291
}
281292
}
282293
}
@@ -377,16 +388,15 @@ module.exports = {
377388
const allAncestorElements = getJSXElementAncestors(node);
378389
if (!allAncestorElements.length) return;
379390

380-
for (const ancestor of allAncestorElements) {
381-
const isClosestJSXAncestor = ancestor === allAncestorElements[0];
391+
for (const ancestorElement of allAncestorElements) {
392+
const isClosestJSXAncestor = ancestorElement === allAncestorElements[0];
382393

383-
const elementNames = getJSXElementName(ancestor);
384-
if (elementNames && Array.isArray(elementNames) && elementNames.length === 2) {
385-
const [ancestorName, compoundAncestorName] = elementNames;
386-
if (ancestorName) {
387-
const ancestorConfig = compoundAncestorName
388-
? config.elementOverrides[compoundAncestorName] || config.elementOverrides[ancestorName]
389-
: config.elementOverrides[ancestorName];
394+
const ancestor = getJSXElementName(ancestorElement);
395+
if (ancestor) {
396+
if (ancestor.name) {
397+
const ancestorConfig = ancestor.compoundName
398+
? config.elementOverrides[ancestor.compoundName] || config.elementOverrides[ancestor.name]
399+
: config.elementOverrides[ancestor.name];
390400

391401
if (ancestorConfig) {
392402
if (isClosestJSXAncestor || ancestorConfig.applyToNestedElements) {

0 commit comments

Comments
 (0)