-
-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(no-duplicate-attr-inheritance): ignore multi root #2598
base: master
Are you sure you want to change the base?
Conversation
I think it would make sense to add a new
How does Vue itself behave here? |
When
Vue treats a group of v-if / v-else-if/v-else as a single node. I've added an |
Sorry, my suggestion was not clear enough. I'd say the rule should stop reporting errors for components with multiple root nodes by default. But the old behavior should still be available (for users who want to explicitly define the behavior for multi-root components) via an option. Is |
Then the name and setting the default to |
let hasIf = false | ||
let hasElse = false | ||
|
||
for (const element of elements) { | ||
if (utils.hasDirective(element, 'if')) { | ||
if (hasIf || hasElse) { | ||
return false | ||
} | ||
hasIf = true | ||
} else if (utils.hasDirective(element, 'else-if')) { | ||
if (!hasIf || hasElse) { | ||
return false | ||
} | ||
} else if (utils.hasDirective(element, 'else')) { | ||
if (!hasIf || hasElse) { | ||
return false | ||
} | ||
hasElse = true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
return hasIf && (elements.length === 1 || hasElse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is much more readable (and we don't need to care about arrays with less than 2 entries anyway):
let hasIf = false | |
let hasElse = false | |
for (const element of elements) { | |
if (utils.hasDirective(element, 'if')) { | |
if (hasIf || hasElse) { | |
return false | |
} | |
hasIf = true | |
} else if (utils.hasDirective(element, 'else-if')) { | |
if (!hasIf || hasElse) { | |
return false | |
} | |
} else if (utils.hasDirective(element, 'else')) { | |
if (!hasIf || hasElse) { | |
return false | |
} | |
hasElse = true | |
} else { | |
return false | |
} | |
} | |
return hasIf && (elements.length === 1 || hasElse) | |
if (elements.length < 2) { | |
return false | |
} | |
const firstElement = element[0] | |
const lastElement = elements[elements.length - 1] | |
const inBetweenElements = elements.slice(1, -1) | |
return ( | |
utils.hasDirective(firstElement, 'if') && | |
(utils.hasDirective(lastElement, 'else-if') || | |
utils.hasDirective(lastElement, 'else')) && | |
inBetweenElements.every((element) => utils.hasDirective(element, 'else-if')) | |
) |
|
||
</eslint-code-block> | ||
|
||
### `"checkMultiRootNodes": true` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This heading should be below the options.
} | ||
``` | ||
|
||
- `"checkMultiRootNodes"` ... If `true`, check and warn when there are multiple root nodes. (Default: `false`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add an explanation why the default is false
(and that is fine), and why someone might still want to enable the option?
resolve #2596.
v-if
/v-else
/v-else
nodes. Should we consider treating it as a "single" root?