Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 14, 2021. It is now read-only.

Lint your styled components with stylelint!

License

NotificationsYou must be signed in to change notification settings

styled-components/stylelint-processor-styled-components

Repository files navigation

Lint yourstyled components withstylelint!

Build StatusCoverage StatusJoin the community on SpectrumGreenkeeper

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 withmoduleName,importName andstrict, 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 fromstyled(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 v4Component.extend``;
  • ignoreFiles is passed tomicromatch 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 inBabel's website.

Further documentation for this processor lives onthe styled-components website!

F.A.Q.

Why does it throwUnexpected token? Even thought the file didn't importstyled-components.

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

If your project includesyarn.lock orpackage-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 useinterpolation-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 setsyntax: css-in-js in stylelint@10, it can extract styles fromstyled-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 setoption.strict. More examples are in#258.

License

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

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

About

Lint your styled components with stylelint!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp