Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Use? #3

Open
khrome83 opened this issue Oct 19, 2017 · 5 comments
Open

How to Use? #3

khrome83 opened this issue Oct 19, 2017 · 5 comments

Comments

@khrome83
Copy link

khrome83 commented Oct 19, 2017

I have everything setup according to the readme.md

{
  "presets": [
    "es2015",
    "react",
    [
      "next/babel",
      {
        "styled-jsx": {
          "plugins": [
            "styled-jsx-plugin-postcss",
            "styled-jsx-plugin-stylelint"
          ]
        }
      }
    ]
  ]
}

I am not seeing any errors with the plugin being added. I am not seeing any error output when i "break" the css.

I have tried creating non existing classes, adding extra lines, playing with selector definitions, creating fake properties, etc.

Any advice?

Also is there any way to run this via CLI / NPM? I want to lint as part of a CI without running npm run dev

@Darep
Copy link

Darep commented Aug 23, 2018

Seems like you also need to create a .stylelintrc file in your project next to the .babelrc file. After that you should get linting in the console :)

@VinceBT
Copy link

VinceBT commented Feb 8, 2019

@khrome83 I'm also interested in how you could run stylelint via CLI with the plugin enabled, did you eventually find out ?

@khrome83
Copy link
Author

khrome83 commented Feb 8, 2019 via email

@darbymanning
Copy link

Ditto to the above. I have a .stylelintrc file as @Darep mentioned, but it doesn't report any linting issues in within Styled JSX markup. Compared with creating a .css file, where it does report the errors in my IDE as expected.

Does anyone have an example project that can be shared where this is setup and working as expected?

@darbymanning
Copy link

I did some further troubleshooting on this. Managed to get it executing - but found it was hanging during build (for context, I am using Next.js). After some digging, I think it's a problem with the loopWhile function in linter.js (probably never resolves). I stripped this out, leaving the file contents as this:

const stylelint = require('stylelint')
const postcss = require('postcss')
const reporter = require('postcss-reporter')

module.exports = function linter(css, options) {
  postcss()
    .use(stylelint(options))
    .use(reporter())
    .process(css, { from: options.codeFilename }).then()
}

This now reports issues as expected, although I do seem to see the warnings appear twice so something's up there... at least it works. I'm not too sure what the purpose of the loop is...

In terms of getting this to work through the CLI, it's not really possible from what I can tell at the moment, as the actual CSS is provided to this plugin by styled-jsx. There'd need be some other way of extracting that from the JS (I guess reusing whatever method styled-jsx has to resolve them), to then parse. For me personally having this work via the CLI is a must-have, as I need to be able to run linting in CI for my projects.

@giuseppeg any thoughts on all of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants