azat-io / eslint-plugin-perfectionist

☂️ ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://perfectionist.dev
MIT License
2.07k stars 44 forks source link

Bug: program.body is not iterable #391

Open draylegend opened 3 days ago

draylegend commented 3 days ago

I'm using PhpStorm 2024.3, build #PS-243.21565.202, built on November 13, 2024

Describe the bug

TypeError: program.body is not iterable
Occurred while linting /home/dl/my-app/apps/app/src/app/app.component.ts/1_inline-template-app.component.ts-1.component.html:1
Rule: "perfectionist/sort-modules"

TypeError: program.body is not iterable
Occurred while linting /home/dl/my-app/apps/app/src/app/app.component.ts/1_inline-template-app.component.ts-1.component.html:1
Rule: "perfectionist/sort-modules"
at analyzeModule (/home/dl/my-app/node_modules/eslint-plugin-perfectionist/dist/rules/sort-modules.js:180:28)
at Program (/home/dl/my-app/node_modules/eslint-plugin-perfectionist/dist/rules/sort-modules.js:159:9)
at ruleErrorHandler (/home/dl/my-app/node_modules/eslint/lib/linter/linter.js:1084:48)
at /home/dl/my-app/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
  at Object.emit (/home/dl/my-app/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
  at NodeEventGenerator.applySelector
  (/home/dl/my-app/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
  at NodeEventGenerator.applySelectors
  (/home/dl/my-app/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
  at NodeEventGenerator.enterNode
  (/home/dl/my-app/node_modules/eslint/lib/linter/node-event-generator.js:337:14)
  at runRules (/home/dl/my-app/node_modules/eslint/lib/linter/linter.js:1128:40)
  Process finished with exit code -1

Code example

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'app-root',
  imports: [RouterOutlet],
  template: `<router-outlet />`,
})
export class AppComponent {}

Repo

https://github.com/draylegend/perfectionist-bugs

ESLint version

9.15.0

ESLint Plugin Perfectionist version

4.0.3

Additional comments

but perfectionist@3.9.1 does work with eslint@9.14.0

Validations

hugop95 commented 3 days ago

Hi @draylegend, I can't reproduce the problem on my end. Could you please provide a repository or ESlint config + package.json with your problem?

Edit:

Occurred while linting /home/dl/my-app/apps/app/src/app/app.component.ts/1_inline-template-app.component.ts-1.component.html:1

It seems that the issue occurs due to inline template generated by angular-eslint, you may find a workaround by using "excludedFiles": ["*inline-template-*.component*"] (see https://github.com/angular-eslint/angular-eslint/issues/105#issuecomment-767787074), or something similar in your ESLint config, but it's hard for me to pinpoint the exact problem without having a way to reproduce the error.

draylegend commented 2 days ago

@hugop95 thanks for the quick reply. I've added the repo https://github.com/draylegend/perfectionist-bugs

azat-io commented 2 days ago

For some reason I'm still unable to reproduce the problem. I ran pnpm exec eslint . command.

pnpm exec eslint .

/Users/azat/Developer/perfectionist-bugs/apps/app/src/app/app.component.ts
  6:3  error  Expected "changeDetection" to come before "selector"  perfectionist/sort-objects

/Users/azat/Developer/perfectionist-bugs/apps/app/src/app/app.config.server.ts
  1:34  error  Expected "ApplicationConfig" to come before "mergeApplicationConfig"  perfectionist/sort-named-imports
  4:1   error  Missed spacing between "@angular/ssr" and "./app.config" imports      perfectionist/sort-imports

/Users/azat/Developer/perfectionist-bugs/apps/app/src/app/app.config.ts
  8:1  error  Expected "@angular/platform-browser" (external) to come before "./app.routes" (sibling)  perfectionist/sort-imports

/Users/azat/Developer/perfectionist-bugs/apps/app/src/main.server.ts
  2:1  error  Missed spacing between "@angular/platform-browser" and "./app/app.component" imports  perfectionist/sort-imports

/Users/azat/Developer/perfectionist-bugs/apps/app/src/main.ts
  2:1  error  Missed spacing between "@angular/platform-browser" and "./app/app.config" imports  perfectionist/sort-imports
  3:1  error  Expected "./app/app.component" to come before "./app/app.config"                   perfectionist/sort-imports

/Users/azat/Developer/perfectionist-bugs/apps/app/src/server.ts
  35:5  error  Expected "index" to come before "maxAge"  perfectionist/sort-objects

✖ 8 problems (8 errors, 0 warnings)
  8 errors and 0 warnings potentially fixable with the `--fix` option.

The only thing is that I had to remove the @angular-eslint/template rule. ESLint did not see it. Can you tell me if I need to install something to make it work?

azat-io commented 2 days ago

@draylegend Can you tell me how to reproduce the problem in your repository?