styled-components / stylelint-processor-styled-components

Lint your styled components with stylelint!
https://styled-components.com
MIT License
656 stars 61 forks source link

Stylelint throws on ts/tsx files not using styled-components #259

Closed moimael closed 5 years ago

moimael commented 5 years ago

Environment

## System:
 - OS: Linux 5.0 Fedora 29 (Workstation Edition) 29 (Workstation Edition)
 - CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
 - Memory: 3.78 GB / 15.43 GB
 - Container: Yes
 - Shell: 4.4.23 - /bin/bash
## Binaries:
 - Node: 10.15.3 - /usr/bin/node
 - Yarn: 1.10.1 - /usr/bin/yarn
 - npm: 6.9.0 - /usr/bin/npm
## npmPackages:
 - styled-components: 3.4.2 => 3.4.2 
 - stylelint: 9.10.1 => 9.10.1 
 - stylelint-config-recommended: 2.1.0 => 2.1.0 
 - stylelint-config-styled-components: 0.1.1 => 0.1.1 
 - stylelint-processor-styled-components: 1.5.2 => 1.5.2 

.stylelintrc

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

Reproduction

Stylelint throws errors on Ts/Tsx files that don't use or import styled-components.

stylelint-errors

An example of one of the file that throws (the use-experiment.ts):

import { pathOr } from "ramda"
import { useReduxStore } from "./use-redux"

export const useExperiment = (experimentFlag: string): boolean => {
  const experimentList = <string[]>pathOr([], ["experiment", "list"], useReduxStore().getState())
  return experimentList.includes(experimentFlag)
}

Steps to reproduce

Not sure, just ran stylelint in my project

Expected Behavior

Shouldn't throw for files without styled-components

Actual Behavior

Throws styles errors on Ts/Tsx files only not related to styled-components.

chinesedfan commented 5 years ago

You can custom plugins by option.parserPlugins now. An example is https://github.com/styled-components/stylelint-processor-styled-components/blob/master/test/options.test.js#L211. If disabled the jsx plugin, use-experiment.ts can be parsed successfully.

Of course, if someone can implement #231, that is much better.