• This repository has been archived on 14/May/2021
  • Stars
    star
    657
  • Rank 66,050 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lint your styled components with stylelint!

stylelint-processor-styled-components

Lint your styled components with stylelint!

Build Status Coverage Status Join the community on Spectrum Greenkeeper

Video of project in use

Setup

You need:

(npm install --save-dev \
  stylelint \
  stylelint-processor-styled-components \
  stylelint-config-styled-components \
  stylelint-config-recommended)

Now use those in your .stylelintrc and run stylelint with your JavaScript files!

{
  "processors": ["stylelint-processor-styled-components"],
  "extends": [
    "stylelint-config-recommended",
    "stylelint-config-styled-components"
  ]
}

NOTE: The processor works with Flow- and TypeScript-typed files too! (we'll assume TypeScript usage if your files end in .ts or .tsx)

And it also has some options. Their default values are,

{
  "processors": [["stylelint-processor-styled-components", {
    "moduleName": "styled-components",
    "importName": "default",
    "strict": false,
    "ignoreFiles": [],
    "parserPlugins": [
      "jsx",
      ["decorators", { "decoratorsBeforeExport": true }],
      "classProperties",
      "exportExtensions",
      "functionBind",
      "functionSent"
    ]
  }]]
}
  • Combining with moduleName, importName and strict, you can tell the processor what kinds of tagged template literals to lint.
import styled, { css, keyframes } from 'styled-components';

// `importName` from `moduleName`, which means where `styled` comes from
styled(Component)``;
styled('div')``;
styled.div``;

// any other imports from `moduleName` (if `strict` is true, they will not be linted)
css``;
keyframes``;

// special extend calls, which have been deprecated in styled-components v4
Component.extend``;

  • ignoreFiles is passed to micromatch as the second parameter, which means one or more glob patterns for matching.

  • parserPlugins is used to make the processor's parser be able to parse new syntaxes. All available babel parser plugins and related options can be found in Babel's website.

Documentation

Further documentation for this processor lives on the styled-components website!

F.A.Q.

Why does it throw Unexpected token? Even thought the file didn't import styled-components.

You can custom babel plugins by option.parserPlugins now. An API example is our test. But if someone can implement #231, that will be much better.

If your project includes yarn.lock or package-lock.json, an alternative cause can be that babel related dependencies, i.e. @babel/parser and @babel/traverse, are outdated, especially when linting files with new TypeScript syntaxes. You can upgrade them by removing their entries in the lockfile and reinstall dependencies.

Why does it throw unexpected lint errors?

The processor can not always parse interpolations with right things. But you can use interpolation-tagging to help it. If you have ideas to make it more intelligent, feel free to send a PR or share your solution by an new issue.

What's more, if set syntax: css-in-js in stylelint@10, it can extract styles from styled-components without this processor. Even though there are still lots of differences with this processor, we hope this processor's abilities can be migrated to stylelint totally in the future.

I don't want specified tagged template literal to be parsed, i.e. css.

You can set option.strict. More examples are in #258.

License

Licensed under the MIT License, Copyright © 2017 Maximilian Stoiber. See LICENSE.md for more information!

Based on Mapbox' excellent stylelint-processor-markdown, thanks to @davidtheclark!

More Repositories

1

styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
TypeScript
39,930
star
2

polished

A lightweight toolset for writing styles in JavaScript ✨
JavaScript
7,562
star
3

awesome-styled-components

A curated list of awesome styled-components resources 💅
3,283
star
4

xstyled

A utility-first CSS-in-JS framework built for React. 💅👩‍🎤⚡️
MDX
2,254
star
5

jest-styled-components

🔧 💅 Jest utilities for Styled Components
JavaScript
1,577
star
6

vue-styled-components

Visual primitives for the component age. A simple port for Vue of styled-components 💅
JavaScript
1,362
star
7

styled-theming

Create themes for your app using styled-components
JavaScript
1,168
star
8

css-to-react-native

Convert CSS text to a React Native stylesheet object
JavaScript
1,117
star
9

babel-plugin-styled-components

Improve the debugging experience and add server-side rendering support to styled-components
JavaScript
1,063
star
10

vscode-styled-components

Syntax highlighting for styled-components
JavaScript
911
star
11

styled-components-website

The styled-components website and documentation
MDX
607
star
12

webstorm-styled-components

styled-components highlighting support in IntelliJ editors
Kotlin
377
star
13

vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
Vim Script
300
star
14

comparison

Comparing different ways to style components
JavaScript
183
star
15

elm-styled

Styling your Html Elements with typed Css 💅
Elm
180
star
16

babel-plugin-polished

Compile polished helper functions at build time
JavaScript
138
star
17

styled-elements

Styled components for the DOM.
JavaScript
87
star
18

stylelint-config-styled-components

The shareable stylelint config for stylelint-processor-styled-components
JavaScript
71
star
19

spec

Design Requirements and Spec for a Component-oriented CSS Solution
61
star
20

color-schemer

A React app to help you select a color scheme, built with styled-components and polished
JavaScript
55
star
21

styled-components-codemods

Automatic codemods to upgrade your styled-components code to newer versions.
JavaScript
52
star
22

styled-components-experimentation

A place to play with things that shouldn't be in core
JavaScript
31
star
23

s-c.sh

The styled-components URL shortener!
30
star
24

styled-components-native-code-mod

JavaScript
28
star
25

styled-components.github.io

The styled-components homepage
JavaScript
22
star
26

brand

Logo and brand related materials
11
star
27

benchmark

JavaScript
9
star
28

todomvc

The Speedometer 2.0 React TodoMVC example rebuilt with styled-components
JavaScript
6
star
29

babel-plugin-styled-components-ssr

[EXPERIMENTAL]
JavaScript
2
star
30

use-styled-hook

tbd
1
star