html-eslint
html-eslint copied to clipboard
element-newline rule throws error
The @html-eslint/element-newline
rule throws error for the attached HTML file.
Used package versions: eslint: 8.14.0 @html-eslint/parser: 0.15.0 @html-eslint/eslint-plugin: 0.15.0
@visz01 Thanks for the report :)
But I couldn't reproduce it... you seem to use "Window OS." so I tested CRLF
also.
I just installed the html-eslint plugin and am also greeted with this error. If i change the rule severity to "off", the error does not occur. This is my call-stack:
Linting "shared-material-core-secret"...
> NX Cannot read properties of undefined (reading 'filter')
Occurred while linting /root/secret/libs/shared/material-core-secret/src/lib/form-field-wrapper/form-field-wrapper.component.html:1
Rule: "@html-eslint/element-newline"
TypeError: Cannot read properties of undefined (reading 'filter')
Occurred while linting /root/secret/libs/shared/material-core-secret/src/lib/form-field-wrapper/form-field-wrapper.component.html:1
Rule: "@html-eslint/element-newline"
at checkSiblings (/root/secret/node_modules/@html-eslint/eslint-plugin/lib/rules/element-newline.js:59:10)
at Program (/root/secret/node_modules/@html-eslint/eslint-plugin/lib/rules/element-newline.js:114:9)
at ruleErrorHandler (/root/secret/node_modules/eslint/lib/linter/linter.js:1076:28)
at /root/secret/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/root/secret/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/root/secret/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/root/secret/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/root/secret/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/root/secret/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
This is the code where the error is triggered. Apparently "siblings" is undefined
:
function checkSiblings(siblings) {
siblings
.filter((node) => node.type !== "Text")
.forEach((current, index, arr) => {
I added some logging:
body: undefined
siblings: undefined
added a simple check which works for me:
Program(node) {
if (node.body) {
checkSiblings(node.body);
}
},
These are some (Angular template) html files on which the error occurs:
<article class="osaat-step" [ngClass]="{ 'osaat-step--visible': stepVisible, 'osaat-step--hidden': stepHidden }">
<ng-content></ng-content>
</article>
And also a Storybook file with an inline template:
@Component({
selector: 'athora-nx-whole-number-doc',
template: ` <h3>Formatted numeric input</h3>`,
})
class DocComponent implements OnInit {
...
Probably these files are unable to be parsed and thus cause node.body
to be undefined.
I hope the above information helps. (Y)