question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styled Components - Reorder on save

See original GitHub issue

Hey,

I’ve been using this awesome plugin to order styles across our entire organization. It works really well, and everyone is acquainted with the setup.

We are moving from Sass to the very amazing Styled Components. Unfortunately, this config doesn’t reorder the styles written in a template literal.

Here is my .stylelintrc

{
    "defaultSeverity": "warning",
    "extends": [
        "stylelint-config-recommended",
        "stylelint-config-styled-components",
        "stylelint-order",
        "stylelint-config-rational-order"
    ],
    "plugins": [
        "stylelint-prettier",
        "stylelint-order",
        "stylelint-config-rational-order/plugin"
    ],
    "syntax": "scss",
    "processors": ["stylelint-processor-styled-components"],
    "rules": {
        "order/properties-order": [],
        "plugin/rational-order": true,
        "at-rule-empty-line-before": [
            "always",
            {
                "except": ["first-nested"],
                "ignoreAtRules": ["import"]
            }
        ],
        "block-closing-brace-newline-after": "always",
        "block-opening-brace-space-before": "always",
        "prettier/prettier": true,
        "property-no-vendor-prefix": true,
        "rule-empty-line-before": [
            "always",
            {
                "except": "first-nested"
            }
        ],
        "selector-no-vendor-prefix": true,
        "unit-case": "lower",
        "value-no-vendor-prefix": true
    }
}

Am I missing something?

Cheers!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

14reactions
brandonkalcommented, Aug 19, 2019

@samrith-s Just in case you are still looking for a solution, here is the relevant config that won’t cause vscode-stylelint to throw. Note I am also setting the severity to warning as the css is still valid when out of order.

module.exports = {
  extends: ['stylelint-config-standard', 'stylelint-config-prettier'],
  plugins: ['stylelint-order', 'stylelint-config-rational-order/plugin'],
  rules: {
    // Property Order
    'order/properties-order': [[], { severity: 'warning' }],
    'plugin/rational-order': [
      true,
      {
        'border-in-box-model': false,
        'empty-line-between-groups': false,
        severity: 'warning',
      },
    ],
  },
}
7reactions
brandonkalcommented, Aug 18, 2019

Let me help…

  1. First, you must abandon stylelint-processor-styled-components.
  2. Autofix is new but that won’t work with a processor. The Stylelint team intends to eventually deprecate the processor API now that the (built in) postcss-syntax is the preferred way to go. You can find the discussion on their repo.
  3. Stylelint now has “css-in-js” syntax, so setting the syntax to “scss” is incorrect. In fact, you shouldn’t explicitly set it in your config file… Stylelint will detect the syntax for you.
  4. Autofix is still experimental. It is not something you can safely do on save. If you are using VSCode, the vscode-stylelint extension does not support this due to a list of issues with stylelint core.

So to be safe, prefer to save first and then run stylelint --fix. It will function if you remove syntax config and the processor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tooling - styled-components
npm install --save-dev babel-plugin-styled-components. Then add it to your babel configuration like ... The plugin call order in your .babelrc file matters.
Read more >
How to keep styled-components styles separate in different ...
I'm using higher order components to reuse React/Next.js components but with different styles. However, this works only for vanilla React ...
Read more >
The 3 essentials to get started with styled-components
In order to keep the code well structured, let's create a components/Home ... import styled from "styled-components"; export const Home ...
Read more >
Styled components, the styling library for your React apps you ...
There are a ton of ways to style components in React. This is probably my favorite ... yarn add styled-components // OR npm...
Read more >
DRY-ing up styled-components - CSS-Tricks
I like working with styled-components. They allow you write CSS in your JavaScript, keeping your CSS in very close proximity to your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found