Skip to content

Commit 6f8214e

Browse files
waynzhFloEdelmann
andauthored
Update lib/rules/no-duplicate-attr-inheritance.js
Co-authored-by: Flo Edelmann <[email protected]>
1 parent 8694e4d commit 6f8214e

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

lib/rules/no-duplicate-attr-inheritance.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,20 @@ const utils = require('../utils')
88

99
/** @param {VElement[]} elements */
1010
function isConditionalGroup(elements) {
11-
let hasIf = false
12-
let hasElse = false
13-
14-
for (const element of elements) {
15-
if (utils.hasDirective(element, 'if')) {
16-
if (hasIf || hasElse) {
17-
return false
18-
}
19-
hasIf = true
20-
} else if (utils.hasDirective(element, 'else-if')) {
21-
if (!hasIf || hasElse) {
22-
return false
23-
}
24-
} else if (utils.hasDirective(element, 'else')) {
25-
if (!hasIf || hasElse) {
26-
return false
27-
}
28-
hasElse = true
29-
} else {
30-
return false
31-
}
11+
if (elements.length < 2) {
12+
return false
3213
}
3314

34-
return hasIf && (elements.length === 1 || hasElse)
15+
const firstElement = element[0]
16+
const lastElement = elements[elements.length - 1]
17+
const inBetweenElements = elements.slice(1, -1)
18+
19+
return (
20+
utils.hasDirective(firstElement, 'if') &&
21+
(utils.hasDirective(lastElement, 'else-if') ||
22+
utils.hasDirective(lastElement, 'else')) &&
23+
inBetweenElements.every((element) => utils.hasDirective(element, 'else-if'))
24+
)
3525
}
3626

3727
/** @param {VElement[]} elements */

0 commit comments

Comments
 (0)