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

Fix CSS-in-JS problems #4574

Closed
2 of 23 tasks
jeddy3 opened this issue Jan 29, 2020 · 10 comments
Closed
2 of 23 tasks

Fix CSS-in-JS problems #4574

jeddy3 opened this issue Jan 29, 2020 · 10 comments
Labels
help wanted is likely non-trival and help is wanted priority: high is impactful on users status: ready to implement is ready to be worked on by someone type: umbrella a group of related issues

Comments

@jeddy3
Copy link
Member

jeddy3 commented Jan 29, 2020

We have a bunch of CSS-in-JS related problems. I've gathered them here:

Template literal interpolations:

We recently forked the parser we use for CSS-in-JS into the stylelint organisation. We can fix all the above issues by patching and maintaining this fork.

These issues are, along with the glob issues and the one for disable comments, our most pressing ones right now. They all prevent people from using stylelint completely.

If you can help us fix our fork of the parser, please add a comment below!

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone priority: high is impactful on users help wanted is likely non-trival and help is wanted type: umbrella a group of related issues labels Jan 29, 2020
@jeddy3 jeddy3 pinned this issue Jan 29, 2020
@jeddy3
Copy link
Member Author

jeddy3 commented Apr 9, 2020

As of stylelint@13.3.1 we now use our fork of the CSS-in-JS parser, making it easier for us to roll-out any fixes to the parser that address the issues above. If you can help us fix our fork, please dive in!

@abdonrd
Copy link
Member

abdonrd commented May 28, 2020

Probably related: #4800

@rowa-audil
Copy link

Hey stylelint Team, any plans for #4713?

@Nantris
Copy link

Nantris commented Sep 6, 2021

Is there any work ongoing on the forked parser? (https://github.com/stylelint/postcss-css-in-js)

@hudochenkov
Copy link
Member

@slapbox non that we aware of. In the next major version v14 we're going remove it from stylelint.

I started working on another CSS-in-JS syntax, which would be possible to use with stylelint.

@jeddy3
Copy link
Member Author

jeddy3 commented Sep 7, 2021

For context, the issues with the existing syntax are:

Thanks to @hudochenkov, we now have a Document node type in PostCSS@8.

Summary of the plan for 14.0.0:

A lot has already been done for 14.0.0, including a chunk of refactoring. Importantly, the v14 branch has already been migrated to PostCSS@8, and the customSyntax option is ready to use as a CLI flag.

@slapbox If you, or anyone else, would like to help us get 14.0.0 ready for release, please help with the remaining tasks. In particular:

  • adding the customSyntax and overrides properties to the configuration object
  • migrating postcss-html and postcss-markdown to PostCSS@8 (and the new Document node type)

Once @hudochenkov's reference syntax is ready, we can start encouraging the community to work on syntaxes for their CSS-in-JS library of choice.

@heath-freenome
Copy link

heath-freenome commented Dec 13, 2021

@slapbox non that we aware of. In the next major version v14 we're going remove it from stylelint.

I started working on another CSS-in-JS syntax, which would be possible to use with stylelint.

@hudochenkov So I'm migrating to stylelint 14 and all my styles are in .js files (using the Material-ui 4 JSS syntax). Using the customSyntax @stylelint/postcss-css-in-js doesn't seem to pick up any of the rules I have for my styles... will yours
work?

@Lornz-
Copy link

Lornz- commented Dec 31, 2021

@slapbox non that we aware of. In the next major version v14 we're going remove it from stylelint.
I started working on another CSS-in-JS syntax, which would be possible to use with stylelint.

@hudochenkov So I'm migrating to stylelint 14 and all my styles are in .js files (using the Material-ui 4 JSS syntax). Using the customSyntax @stylelint/postcss-css-in-js doesn't seem to pick up any of the rules I have for my styles... will yours work?

Same issue here. I only get it worked from the command line. I use styled-components in one of my projects and the code is not highlighted on error in vscode. It seems like the vscode extension can't see the rules in my config file. I also combine stylelint with prettier by using the stylelint-prettier plugin.

I followed steps as described here with my own setup:

package.json

{
  "scripts": {
    // other scripts omitted for brevity
   "lint:style": "npx stylelint \"**/*.{css,jsx,js}\"",
  },
  "dependencies": {
    // other deps omitted for brevity
    "styled-components": "^5.3.0",
  },
  "devDependencies": {
    // other deps omitted for brevity
    "@stylelint/postcss-css-in-js": "^0.37.2",
    "postcss": "^8.4.5",
    "postcss-syntax": "^0.36.2",
    "stylelint": "^14.2.0",
    "stylelint-a11y": "^1.2.3",
    "stylelint-config-prettier": "^9.0.3",
    "stylelint-config-rational-order": "^0.1.2",
    "stylelint-config-recommended": "^6.0.0",
    "stylelint-config-standard": "^24.0.0",
    "stylelint-config-styled-components": "^0.1.1",
    "stylelint-high-performance-animation": "^1.5.1",
    "stylelint-no-unsupported-browser-features": "^5.0.2",
    "stylelint-order": "^5.0.0",
    "stylelint-prettier": "^2.0.0",
  },
}

.stylelintrc.js

module.exports = {
  plugins: [
    'stylelint-a11y',
    'stylelint-config-rational-order/plugin',
    'stylelint-high-performance-animation',
    'stylelint-no-unsupported-browser-features',
    'stylelint-order',
    'stylelint-prettier',
  ],
  extends: [
    'stylelint-config-standard',
    'stylelint-config-recommended',
    'stylelint-config-rational-order',
    'stylelint-a11y/recommended',
    'stylelint-prettier/recommended',
    'stylelint-config-styled-components',
  ],
  overrides: [
    {
      files: ['**/*.{js,jsx}'],
      customSyntax: '@stylelint/postcss-css-in-js',
    },
  ],

Here's also my vscode settings:

{
  // other settings omitted for brevity
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "eslint.format.enable": true,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.formatDocument": true,
    "source.fixAll": true
  },
}

Did someone find a solution for that? Any help would be appreciated.

@puku0x
Copy link

puku0x commented Jan 4, 2022

@Lornz- I did.

// package.json
"devDependencies": {
  "@babel/core": "7.16.0",  // Do not update babel v7.16.5 or higher (https://github.com/stylelint/postcss-css-in-js/issues/247)
  "@babel/parser": "7.16.0",
  "postcss-jsx": "~0.36.0",  // Do not use stylelint/postcss-css-in-js with decorators (https://github.com/stylelint/postcss-css-in-js/issues/236)
  "postcss-scss": "~4.0.0",
  "postcss-syntax": "~0.36.0",
  "stylelint": "~14.2.0",
  "stylelint-config-prettier": "~9.0.0",
  "stylelint-config-recess-order": "~3.0.0",
  "stylelint-config-recommended": "~6.0.0"
}
// .stylelintrc.json
{
  "extends": [
    "stylelint-config-recommended",
    "stylelint-config-recess-order",
    "stylelint-config-prettier"
  ],
  "ignoreFiles": ["node_modules/**", "dist/**"],
  "overrides": [
    {
      "files": ["**/*.scss"],
      "customSyntax": "postcss-scss"
    },
    {
      "files": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
      "customSyntax": "postcss-jsx"
    }
  ]
}
// .vscode/settings.json
{
  "css.validate": false,
  "scss.validate": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.stylelint": true
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "stylelint.validate": ["css", "scss", "typescript", "typescriptreact"]  // 👈 Use stylelint for validation
}

@jeddy3
Copy link
Member Author

jeddy3 commented Jan 18, 2022

Closing as the syntax option was removed for the 14.0.0 release. (See the migration guide.)

We'll also be deprecating our forked CSS-in-JS package, in favour of leaner custom syntaxes.

Please consider writing a custom syntax specific to your CSS-in-JS library of choice and addressing there any of the bugs above that are applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted is likely non-trival and help is wanted priority: high is impactful on users status: ready to implement is ready to be worked on by someone type: umbrella a group of related issues
Development

No branches or pull requests

8 participants