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
feat: expose cli entrance #17690
feat: expose cli entrance #17690
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
|
I'm not sure I understand why this would be helpful. The CLI entrance doesn't export anything, so you'd just be running the code without any arguments, which would fail. What is it you're trying to achieve that can't be done via |
Other tools based on eslint can easily hook the cli. // ./bin/my-lint.js
process.argv.push('--fix') // always fix
import('eslint/bin') my-lint .
I have an npm package (a cli tool) based on eslint. If I use |
I don't understand this. If your tool is based on ESLint, then isn't ESLint already installed? Why would they be asked to install it again? |
And note: You'll need to sign the CLA for us to consider this PR. |
This will appear when user do not install |
I see. And what is the reason you don't use the |
Because it's hard to use, and I have to rewrite the same code as // ./bin/my-lint.js
const origin = process.argv
process.argv = origin.filter(i=>!i.startsWith('--eslint')).map(i=>i.replace('--prettier', '')))
await import('prettier/bin')
process.argv = origin.filter(i=>!i.startsWith('--prettier')).map(i=>i.replace('--eslint', '')))
await import('eslint/bin') my-lint . --eslint-f --prettier-w In this example, user don't need to learn new api. And I, who created it, don't need to rewrite the same code as |
I see, thanks for explaining. I guess I'm still having a hard time understanding this use case. If your tool is bundling ESLint as a dependency, then you should be able to run it via |
Hi.
|
This is the part I don't understand. If you have a dependency on In general, I just don't like adding things to the public interface to support an edge case for one implementation. That's why I'm asking so many questions. This was a use case we didn't intend to support, so we need a solid justification for adding it. |
Hi @nzakas. Following your suggection, it can be executed. But the code will be a little bit complex. Comparing with the implementaions about prettier, lint-staged and commitlint, integrating eslint one is the most complicated. Any one of the others is only one line of code. All of them can do it. Why cann't eslint? 🤔 |
See, you now have a script that will work for all CLIs regardless of whether or not the |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:
What changes did you make? (Give an overview)
Expose cli entrance. I have a cli tool want to reuse the eslint's cli entrance by using:
See the similar PR for
lint-staged
.Is there anything you'd like reviewers to focus on?
No.