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
Always infer syntax for known file formats, even with processors. #5132
Always infer syntax for known file formats, even with processors. #5132
Conversation
lib/getPostcssResult.js
Outdated
} else if (!(options.codeProcessors && options.codeProcessors.length)) { | ||
} else if ( | ||
!(options.codeProcessors && options.codeProcessors.length) || | ||
(options.filePath && /\.(scss|sass|less)$/.test(options.filePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it defeats the purpose of postcss-syntax
, and removes support for many supported extensions, e. g. .js
, .ts
, .html
, .vue
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand. I'm only adding an ||
branch so if a file's syntax was previously inferred, then it should continue being inferred. This infers the syntax for more filetypes. Are you suggesting I add those extensions to this list?
For context, this is a copy-paste of the code as it was before it was accidentally removed in https://github.com/stylelint/stylelint/pull/4729/files#diff-5383a0a864da5a5ad24b4bae8f44c5574601bd4d145999b1ddc211d3900dd68bL89
Thanks for taking a look :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand if you still don't want to merge this but i've spent a couple hours on this
@yaymukund Thank you for taking the time to dig into this. The syntax hullabaloo in stylelint is complex. I'm personally looking forward to the possibility of removing it in favour of explicit-configuration using a overrides
property. #5126 is the first step towards that.
Anyhow, in the meantime, would you mind removing the else if
in favour of simple else
, i.e. autosyntax is always used regardless of if a processor is configured in the configuration object?:
} else {
const autoSyntax = require('postcss-syntax');
// TODO: investigate why lazy import HTML syntax causes
// JS files with the word "html" to throw TypeError
// https://github.com/stylelint/stylelint/issues/4793
const { html, ...rest } = syntaxes;
syntax = autoSyntax({
css: cssSyntax(stylelint),
jsx: syntaxes['css-in-js'],
...rest,
});
}
And seeing if that works in your repository.
(We actually ended up passing -s scss to work around this issue, so it's no longer blocking us.)
Ha, yes, that'll do it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that condition has existed for as long as postcss-safe-parser:
But changing it to else
seems to work for our repo, and the tests here pass, so this should be GTM if all that checks out for you :)
Re: syntax configuration: that makes sense. I would be in favor of an explicit opt-in API, if only so we can more easily reason about what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the change and testing it with your repo!
@hudochenkov what do you think, can we merge this or would you rather hold off while you're looking into what the future of syntaxes could be?
Thanks for the pull request. We're going to take a different direction with Closed by #5297. |
closes #5117
Unfortunately, I but couldn't figure out a minimal reproduction so I couldn't add a test. I suspect it might only break in our case because of some interaction with
processors: ['stylelint-processor-styled-components']
. However, I can confirm:I understand if you still don't want to merge this but i've spent a couple hours on this and don't have time to dive any further. (We actually ended up passing
-s scss
to work around this issue, so it's no longer blocking us.)