All Projects → exogen → Jest Styled Components Stylelint

exogen / Jest Styled Components Stylelint

Licence: mit
Run stylelint on your styled-components styles at runtime.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jest Styled Components Stylelint

react-component-library-lerna
Build your own React component library managed with lerna, presented with storybook and published in private npm registry.
Stars: ✭ 55 (+120%)
Mutual labels:  stylelint, styled-components, jest
React Ssr Starter
All have been introduced React environment
Stars: ✭ 20 (-20%)
Mutual labels:  stylelint, jest, styled-components
React-Redux-Enterprise
A React-Redux boilerplate for enterprise/large scaled web applications
Stars: ✭ 77 (+208%)
Mutual labels:  styled-components, jest
medly-components
🧩 Medly components provides numerous themable react components, each with multiple varitaions of sizes, colors, position etc.
Stars: ✭ 66 (+164%)
Mutual labels:  styled-components, jest
twitch-stocks
A web platform that allows you to invest in Twitch streamers with imaginary points.
Stars: ✭ 17 (-32%)
Mutual labels:  styled-components, jest
Styled React Boilerplate
Minimal & Modern boilerplate for building apps with React & styled-components
Stars: ✭ 198 (+692%)
Mutual labels:  stylelint, styled-components
Front End Guide
📚 Study guide and introduction to the modern front end stack.
Stars: ✭ 14,073 (+56192%)
Mutual labels:  stylelint, jest
minesweeper
💣Minesweeper game written with React
Stars: ✭ 18 (-28%)
Mutual labels:  styled-components, jest
Mvfsillva
My personal website
Stars: ✭ 13 (-48%)
Mutual labels:  stylelint, styled-components
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (+940%)
Mutual labels:  stylelint, styled-components
jest-runner-stylelint
Stylelint runner for Jest
Stars: ✭ 18 (-28%)
Mutual labels:  stylelint, jest
React Bolt
⚡ The most simple & robust boilerplate for your React projects.
Stars: ✭ 298 (+1092%)
Mutual labels:  jest, styled-components
Express Webpack React Redux Typescript Boilerplate
🎉 A full-stack boilerplate that using express with webpack, react and typescirpt!
Stars: ✭ 156 (+524%)
Mutual labels:  stylelint, jest
Nextjs Ts
Opinionated Next JS project boilerplate with TypeScript and Redux
Stars: ✭ 134 (+436%)
Mutual labels:  stylelint, jest
stylelint-config-styled-components
The shareable stylelint config for stylelint-processor-styled-components
Stars: ✭ 66 (+164%)
Mutual labels:  stylelint, styled-components
Stylelint Processor Styled Components
Lint your styled components with stylelint!
Stars: ✭ 639 (+2456%)
Mutual labels:  stylelint, styled-components
Lerna Yarn Workspaces Monorepo
🐉 A Monorepo with multiple packages and a shared build, test, and release process.
Stars: ✭ 201 (+704%)
Mutual labels:  jest, styled-components
Arc
React starter kit based on Atomic Design
Stars: ✭ 2,780 (+11020%)
Mutual labels:  jest, styled-components
personal-blog
✍️ 个人技术博客
Stars: ✭ 79 (+216%)
Mutual labels:  styled-components, jest
Coderplanets web
the most sexiest community for developers, build with React, Mobx/MST, GraphQL, Styled-Components, Rxjs, Ramda ... and ❤️
Stars: ✭ 314 (+1156%)
Mutual labels:  jest, styled-components

jest-styled-components-stylelint

A helper for running stylelint on your styled-components styles at runtime.

That means it lints the styles after all your dynamic interpolations are resolved! So it doesn’t get tripped up or need annotations, and will more accurately reflect the styles you’re actually shipping.

Screenshot

Usage

In a Jest setup file like setupTestFramework.js:

import configure from 'jest-styled-components-stylelint'

// NOTE: This should be configured before `styled-components` and `stylis` are
// imported anywhere!
configure({ failOnError: true })

Or simply:

require('jest-styled-components-stylelint')()

Then in your tests, just make sure something renders your components:

import TestRenderer from 'react-test-renderer'

test('renders successfully', () => {
  const wrapper = TestRenderer.create(<Button />)
  expect(wrapper.toJSON()).toMatchSnapshot()
})

Any stylelint errors will cause the test to fail – or if failOnError is false, they will simply be logged.

Options

failOnError

Whether there should be an automatic assertion at the end of every test (added via afterEach) that asserts there were no stylelint errors when running the test.

If true, stylelint errors will cause the test to fail. The failure message will include the formatted lint errors.

If false, stylelint errors will be logged to stderr but the test won’t fail.

Default: true

formatterOptions

By default, this package uses its own custom stylelint formatter (seen in the screenshot above). It shows the styles inline so they’re easier to find and fix. You can tune some aspects of the formatter:

  • collapseLines: Whether each line of code with warnings will be printed just once, or multiple times (once for each warning). Defaults to true.

See below if you’d like to change the stylelint formatter completely.

More…

All remaining options are passed along to stylelint’s lint() function.

You can use this to pass a custom formatter (or any of the defaults from stylelint, like string).

Troubleshooting

It’s not doing anything!

If you’re using this with jest-styled-components, make sure to import and configure() this module first, before importing jest-styled-components. Otherwise, the necessary modules aren’t mocked in time.


There are a lot of errors, but my code looks fine.

Are they spacing errors, like declaration-block-semicolon-space-after?

Expected single space after ";" in a single-line declaration block

If so, this is because babel-plugin-styled-components ships with the minify option enabled by default, so your styles come pre-minified.

You can try disabling this in your test environment by modifying your Babel configuration:

plugins: [
  ['styled-components', { ssr: true, minify: process.env.NODE_ENV !== 'test' }]
]

(As a last resort, you could disable the stylelint rules in question.)


I’m including some third-party CSS in my template strings and I don’t care about linting it.

You can try putting normal stylelint comment directives around it, they should work just fine:

/* stylelint-disable */
${someExternalCSS}
/* stylelint-enable */

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].