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

Issue using plugins with Betterer's eslint #1012

Open
cathey191 opened this issue Apr 5, 2022 · 7 comments · May be fixed by #1179
Open

Issue using plugins with Betterer's eslint #1012

cathey191 opened this issue Apr 5, 2022 · 7 comments · May be fixed by #1179

Comments

@cathey191
Copy link

Describe the bug
Trying to use the eslint plugin rxjs/no-unsafe-takeuntil with Betterer, however getting the error saying it needs the parserServices to be generated.

To Reproduce
Import the package eslint-plugin-rxjs.
"eslint-plugin-rxjs": "^5.0.2",

Add to your .eslintrc.json
{ "root": true, "parser": "@typescript-eslint/parser", "plugins": [ "no-only-tests", "rxjs" ] }

Add to your betterer file
'no-unsafe-takeuntil': () => eslint({ 'rxjs/no-unsafe-takeuntil': ['error', { "allow": ["count", "defaultIfEmpty", "endWith", "every", "finalize", "finally", "isEmpty", "last", "max", "min", "publish", "publishBehavior", "publishLast", "publishReplay", "reduce", "share", "shareReplay", "shareReplayHot", "skipLast", "takeLast", "throwIfEmpty", "toArray", "catchError"] }] })

Expected behavior
Betterer should run the new tests and give a result of how many are failing. In my case Im expecting in the 60s. Instead I receieve this error message mixed in with my other test results in the termal
🔥 no-unsafe-takeuntil: Error while loading rule 'rxjs/no-unsafe-takeuntil': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.

Versions (please complete the following information):

  • Betterer Version [5.1.7]
  • Node Version [e.g. 14.17.3]
@jaohaohsuan
Copy link

Hi @phenomnomnominal
we are trying to use eslint rules from 3rd party plugins, but the eslint function limits us to add configurations to the ESLint instance.

Is it possible to make a new function which allow us to pass the ESLint config?

Cheers,
Henry

@phenomnomnominal
Copy link
Owner

The intention is that the full configuration for the test should live in the projects real .eslintrc configuration file and the eslint test should just turn on and off the rules. Something is going wrong with the mechanism that retrieves the configuration. Since I can't reproduce the issue here it's hard for me to figure out what is going on.

You can of course have your own test in your own codebase that takes the whole ESLint configuration.

@jaohaohsuan
Copy link

Describe the bug Trying to use the eslint plugin rxjs/no-unsafe-takeuntil with Betterer, however getting the error saying it needs the parserServices to be generated.

To Reproduce Import the package eslint-plugin-rxjs. "eslint-plugin-rxjs": "^5.0.2",

Add to your .eslintrc.json { "root": true, "parser": "@typescript-eslint/parser", "plugins": [ "no-only-tests", "rxjs" ] }

Add to your betterer file 'no-unsafe-takeuntil': () => eslint({ 'rxjs/no-unsafe-takeuntil': ['error', { "allow": ["count", "defaultIfEmpty", "endWith", "every", "finalize", "finally", "isEmpty", "last", "max", "min", "publish", "publishBehavior", "publishLast", "publishReplay", "reduce", "share", "shareReplay", "shareReplayHot", "skipLast", "takeLast", "throwIfEmpty", "toArray", "catchError"] }] })

Expected behavior Betterer should run the new tests and give a result of how many are failing. In my case Im expecting in the 60s. Instead I receieve this error message mixed in with my other test results in the termal 🔥 no-unsafe-takeuntil: Error while loading rule 'rxjs/no-unsafe-takeuntil': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.

Versions (please complete the following information):

  • Betterer Version [5.1.7]
  • Node Version [e.g. 14.17.3]

Hi @cathey191
The error message shows that the rxjs/no-unsafe-takeuntil rule is not recognized as the Betterer doesn't load the eslintrc files. Check the source code here.

@phenomnomnominal
Copy link
Owner

Betterer does load the eslintrc files, it is part of this call await cli.calculateConfigForFile(filePath);. The useEslintrc: false just means that it doesn't use it when it constructs the instance.

I have tested this by installing rxjs and eslint-plugin-rxjs in Betterer, adding those to the eslint config, and adding some code that violates the takeuntil rule, and validated that Betterer finds and records the issue correctly.

It seems that calculateConfigForFile is not working as intended in your specific setup for some reason.

@jaohaohsuan
Copy link

@phenomnomnominal Thanks for the explanation. I will take a look again at our project directory structure.

spaceribs added a commit to spaceribs/betterer that referenced this issue Sep 27, 2023
… configuration

This adds an optional parameter to the configuration passed to the ESLint test factory which should
allow overrides to be passed into eslint.

phenomnomnominal#1012
@jbahamon
Copy link

jbahamon commented Oct 2, 2023

I found something that helped in my case. What happened was the following:

  • I had a .ts file with a template in it (i.e. using 'template')
  • I have angular-eslint configured through overrides
  • When betterer/eslint tried to test a rule that required type information on that .ts file, it failed on the template inside the .ts file with a You have used a rule which requires parserServices... error

I think this happens because angular-eslint adds the template files to the list of files to be checked dynamically, but betterer-eslint has only passed the ESLint configuration for the original .ts file, so there's nothing that tells ESLint about what parserOptions should be used for the html file.

I managed to sidestep the issue by moving the templates to their own .html files, but it should not be necessary. I'm not sure about the best course of action for this case, but hope it helps!

@work933k
Copy link

work933k commented Feb 15, 2024

I have the same issue, but then for a component inside a spec file.

@Component({
  template: `<dummy-step><button #dummyNext>next</button></dummy-step>`,
})
class DummyHostComponent {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants