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 CSS-in-JS support #3264
Comments
@ai 👍 |
@jeddy3 any thoughts or questions? |
Thanks for creating the issue @ai 👍 This is part of a refactoring of processors that stylelint uses with the goal of reducing the overall optimizing the package size, see: We will for sure work toward adding |
There were two amazing things I ran into while reviewing #3261:
import styled from 'styled-component';
const Button = styled.div`
${/* sc-selector */ Button} {
${/* sc-prop */ something}: papayawhip;
margin-${/* sc-custom 'left' */ rtlSwitch}: 12.5px;
}
` Where Or: import glamorous from 'glamorous';
const Component = glamorous.div({ margin: 0 });
render(
<Div css={{ margin: 0 }}/>
)
export const styles =
// @css
{
margin: 0
} Where all three types of style definitions are extracted by the glamorous processor. I've highlighted the two amazing things above because I wanted to show that, if I'm correct, the existing processors and the new syntaxes offer different features. There is definitely an overlap, but @gucong3000 am I right in saying that So I believe the question are:
The other question at hand is, what should be bundled in stylelint itself? We originally added support for processors because we realised that there was a never-ending list of things that CSS can be extracted out of and trying to keep-up with them all wouldn't be sustainable. We added the We also recently realised stylelint has a weight problem (#3248). I laid out my reasons in #3252 (comment) for why I think we should:
And drop built-in support for markdown fences. We can, instead, improve the documentation around custom syntaxes (and processors if they stick around). We can better emphasise that, as well as the built-in support for the existing syntaxes and So, I believe there are two parts to this issue:
It feels like we should resolve the former before moving onto the latter. |
interpolation tagging was supported in new version of postcss-styled. I created a new package postcss-jsx to suppurt glamorous and styled-components, but it use babel@7.x.x-beta as parser, it is not a safe version. |
There is some information for postcss syntaxes.
|
How about removing markdown support and adding styled support? |
CSS-in-JS got 10% market just for last year. |
Current support for frameworks:
|
Thanks. I've created a separate issue to follow up on deprecating the processor system in favour of using syntaxes.
Users can already use the I think we should ask ourselves what are the pros and cons of bundling syntaxes within stylelint itself? In #3264 (comment), I suggested we keep bundled support for:
And remove bundled support for extracting from markdown. I no longer think that's a good approach as the line that divides what is bundled and what isn't feels arbitrary This in turn makes it difficult to for users to understand how to use stylelint. I can think of two less arbitrary alternatives... stylelint bundles what's necessary to support:
Whatever approach we decided on, the built-in rules will continue to focus on only standard syntax and will attempt to ignore any non-standard constucts. Anyone familiar with the history of stylelint knows that I've historically been in favour of the former. David came around to this thinking too, and there are a lot of good reasons laid out in #2259. However, it looks like prettier adopts the latter i.e. it bundles every parser within its package. I enjoy the ease-of-use that comes with prettier i.e. it works out-of-the-box with most things I throw at it. Offhand, I can think of a few pros and cons to each approach... If we support only standards, then the pace of stylelint's development will slow down to match the pace of change in the standards world i.e. we get stylelint itself off the hamster-wheel that comes with the preprocessor and CSS-in-JS worlds. Users of CSS and HTML standards (i.e. If we bundle everything, then more users are supported out-of-the-box and there are no breaking changes. However, I can foresee a couple of disadvantages:
@stylelint/core I don't think there's an obvious right answer, and there are (dis)advantages to each. What does everyone want to do? |
I think we should be focused on giving the best experience to users, instead of thinking about standards and rational categories. Most of Stylelint users will be junior developers (since junior developers are the biggest part of development community). They will not understand what is standard syntax and what is not standard syntax. It was a key philosophy behind Autoprefixer and it helps a lot. So instead of thinking of syntax types (standard/non-standard), I think it will be much better if we will choose the most popular use cases (Sass, React + CSS Modules, React + CSS-in-JS, Vue.js, CSS) and then give them the moth easy way to use Stylelint. It doesn’t mean, that we must support all these popular languages out-of-box. My suggestions:
Example:
|
Thanks for writing this up @jeddy3 and your reply already @ai 💯 I'm leaning towards the bundle everything option (aka the popular use cases @ai suggested above) primarily due to adding new members to the @stylelint/contributors team I'm hoping the workload can be lightened by spreading over a larger team, "many hands make light work". |
Somebody can say me what is wrong with support |
I would keep everything we have today. Except for markdown, maybe. It's nice to have, but I wouldn't consider it as necessary. Instead of including more syntaxes follow @ai advice:
As contributors, we know all (almost all) use cases. Putting instructions into CLI just a matter of documentation location and user convenience. Also, it'll onboard users, who wouldn't use stylelint, only because they didn't know about some syntax support or didn't know how to make work. Benefits:
In addition, I would add common use cases on a website (CSS-in-JS with template literals, CSS-in-JS with styles as objects, etc...). Our website has tons of information. It's a good thing. But on the other hand for users to achieve the desired result they need to read a lot and solve quite a puzzle. |
3 of the 5 projects largeish projects I use stylelint with use markdown to ensure the documentation is correct. As such if we are going to include Sass, React + CSS Modules, React + CSS-in-JS, Vue.js, CSS then I'm with @evilebottnawi and including |
This is a valid point. It also seems that the general consensus is to take stylelint in this direction. Let's:
I believe that will provide out-of-the-box support for the most common use cases i.e. styles in:
We can, at a later date, address weight and performance concerns by following prettier's approach of rolling-up the syntaxes into separate files. For any future syntax, we can discuss on a per case basis whether to bundle it or provide step-by-step instructions via the command. There is already a PR to bundle |
Bundled support for template literals was added in #3405 Next up is bundled support for JSX. |
JSX was added in #3506 and released in 9.5.0. Thank you, @gucong3000, for making this possible. And thank you, @ai, for bringing this topic up. |
Stylelint need to add |
@WebTravel |
Linking this issue in case it helps anyone identify whey their CSS-in-JS stylelint configuration isnt working. #4018 |
feature request
@gucong3000 announced amazing
postcss-styled
parser for allButton = styled()
CSS-in-JS solutions (styled-components, Emotion.js, etc). Let’s add it to default pack as other parsers (or to the docs).CSS-in-JS become more and more popular. To bring new user and keep “trendy” feeling (it is very important to find new contributors) we should have official CSS-in-JS support.
Right now we can do it by
stylelint-processor-styled-components
. But, as I understand, processor doesn’t work with--fix
. Also, it doesn’t work well with all rules.postcss-styled
could be used easy as any other PostCSS syntaxes likepostcss-scss
.@jeddy3 what do you think?
The text was updated successfully, but these errors were encountered: