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

Feature request: Provide a way to control files fixed during onCodeActionsSave (e.g., ignorePatterns) #1814

Open
techfg opened this issue Mar 22, 2024 · 5 comments
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@techfg
Copy link

techfg commented Mar 22, 2024

Would like to see a way to be able to control which files are fixed during onCodeActionsSave. Currently, the only method to differentiate what is done on lint vs fix is eslint.onCodeActionsSave.rules which can be cumbersome to manage, especially with complicated configurations.

Potential Approaches:

  1. Add eslint.onCodeActionsSave.ignorePatterns which could be passed to eslint directly
  2. Add eslint.onCodeActionsSave.ignorePath which could be passed to eslint directly and would allow a different ignore file to be used during fix

Use Case: When linting certain file types (e.g., *.{md,mdx}), fixing a file could conflict with prettier formatting (e.g., remark stringifies the result resulting in characters being escaped while prettier removes the unnecessary escapes). For this reason, we ignore these files during fixing from cli but there is no way to replicate this behavior (at least not that I can see from the available options) when using the extension.

Thank you for your consideration!

@dbaeumer dbaeumer added the feature-request Request for new features or functionality label Mar 25, 2024
@dbaeumer dbaeumer added this to the Backlog milestone Mar 25, 2024
@dbaeumer dbaeumer added the help wanted Issues identified as good community contribution opportunities label Mar 25, 2024
@bashmish
Copy link

I might be running into this too.
I expected that .eslintignore would be respected, but setting up eslint via codeActionsOnSave doesn't seem to work correctly with .eslintignore. I can't find any good way to ignore certain folder or file patterns.

@dbaeumer
Copy link
Member

@bashmish .eslintignore should be full respected. Do you see any errors in the file?

Can you please provide me with a GitHub repository I can clone with a minimal repro setup to demo what you are seeing.

@bashmish
Copy link

bashmish commented Apr 2, 2024

@dbaeumer here it is https://github.com/bashmish/bug-eslint-fixall-ignore

  • vscode-eslint plugin v2.4.4
  • formatting (prettier) on save is disabled in settings, to exclude the potential issue with the formatter (prettier)
  • I included .vscode/settings.json with most important ones to simplify the reproduction
  • I added ignore for test/ folder in .eslintignore

on the screenshot you can see the file inside test contains an error, but I don't want to lint the files in test
on save inside my-test.js the eslint will auto-fix and add a JSDoc to the function, which is also not expected for test folder
npm test will run eslint with just the src folder, which I have to explicitly specify in the CLI arg (try running npx eslint **/*.js without src arg, it will lint test folder too)

basically .eslintignore is not working for me in any of the scenarios, and it looks to be not just an issue with vscode-eslint, but also the the eslint CLI

image

shall I open a separate issue for this? in this repo or in the eslint core?

@dbaeumer
Copy link
Member

dbaeumer commented Apr 2, 2024

@bashmish you are using the new flat config which doesn't honor .eslintignore files. You need to add an ignore section to the flat config. See https://eslint.org/docs/latest/use/configure/configuration-files-new#globally-ignoring-files-with-ignores

@bashmish
Copy link

bashmish commented Apr 2, 2024

@dbaeumer the problem with the latter is that it gets overridden by one of my other configs. I can't easily repro it as I have a closed-sourced company wide config and already spent an hour trying to find out which part of it overrides mine... I tried putting { ignores: ['test/'] } to both start and end of the config, no luck. In the repo https://github.com/bashmish/bug-eslint-fixall-ignore it does work, but doesn't help me.

This is how I ended up here, hoping that some other way to exclude certain file pattern globally can override whatever I have in my eslint config.

With CLI I can just do eslint src and then it's only linting the src folder. With the vscode-eslint I don't know how to achieve the same.
Would be even better if I can explicitly set file patterns I wanna lint similarly to the CLI, instead of trying to ignore all the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

3 participants