Skip to content
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

element-newline rule throws error #113

Open
visz01 opened this issue Nov 30, 2022 · 2 comments
Open

element-newline rule throws error #113

visz01 opened this issue Nov 30, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@visz01
Copy link

visz01 commented Nov 30, 2022

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

silent-signin-oidc.html.
element-newline-error
zip

@yeonjuan
Copy link
Owner

yeonjuan commented Dec 2, 2022

@visz01 Thanks for the report :)
But I couldn't reproduce it... you seem to use "Window OS." so I tested CRLF also.

@yeonjuan yeonjuan added the bug Something isn't working label Dec 2, 2022
@work933k
Copy link

work933k commented Mar 22, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants