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
Add --print-config equivalent to Node.js API #5723
Comments
In my opinion, it is possible to automatically determine the target language by exposing a Node API that does the same thing as If customSyntax is set in the obtained configuration, I think it is the target of linting. |
I love this idea! It seems to be very minimally intrusive and simple to implement. |
Implemented in #5734 |
In vscode-stylelint, we continue to get issues with users confused as to why the extension doesn't work for their non-CSS syntaxes (e.g. SCSS, Less) when their Stylelint config is configured correctly. I was thinking of ways to make this easier for users and I thought that maybe, if there was a way to auto-detect if a user wants a certain file type to be linted, we could have the extension lint the file without having to have extra configuration in the extension.
However, there are different ways this could be achieved, each with pros and cons, and there still stands the question of if this is the right approach in the first place. I think some discussion and brainstorming could help figure out how we can make this less of a headache for users. I'm opening this issue in this repository since my gut feeling is that if there is a way to do this, it would belong in some form in the API here since Stylelint owns all the logic for reading, parsing, and determining effective configuration.
Excludes don't work for this — just because a user didn't exclude a file doesn't mean that they intend for that file to be linted. Since Stylelint is run on the CLI with the paths that it should lint, that's the only context where we know specifically what files the user wants to be linted. I think we should have a way to know this information in the API.
Maybe check overrides?
For example, let's say we ask Stylelint, "hey, do you have overrides set up for 'test.scss'?" If the resolved config for that particular file is:
the response would be yes, and then we'd know downstream that we should lint that file. One way this could look:
Caveats
This would only work if the user is using overrides. If, instead, their configuration is:
this would result in a no, even though the user's intent here is that SCSS should be listed.
Includes, similar to tsc?
Another approach could be having an
include
option, similar to some tools like tsc:This would indicate that Stylelint should only lint files matching those globs. This also would have the additional benefit that you could have Stylelint lint the files you want it to without having to provide it the globs directly on the CLI:
npx stylelint .
would only lint the files the user has configured in their project.This would also mean that we now have the precise context to know if a user wants a file to be linted. We could ask Stylelint, downstream, if it has a particular file included in the "project":
While at first glance, this seems similar to what we do in the extension with
validate: ['css', 'scss']
, it is fundamentally different in that the user is now able to put into their config the exact files that they want Stylelint to apply to. Therefore, if the user is usinginclude
, we can know for absolute certain if a user wants to lint a specific file. There is no gap as there is with checking overrides.Caveats
This would be another property added to the configuration. However, at least it wouldn't break any existing behaviour, as it would only come into effect when used.
These are just the solutions I came up with off the top of my head. I'd love to hear your thoughts. I definitely feel that there are ways we can make the user experience better here. Unlike ESLint, there are far more preprocessors and contexts in which CSS is used, even in other languages, so we have many more cases where users are going to have all sorts of configurations for all sorts of files.
The text was updated successfully, but these errors were encountered: