Code Monkey home page Code Monkey logo

Comments (13)

mribichich avatar mribichich commented on May 20, 2024 4

I ended up using the stylelint.config.js option to solve the problem, it solves it for the cmd and vscode:

// stylelint.config.js

const argv = require("yargs").argv;

const glob = argv["_"] && argv["_"][0];

const isJsTsxFiles = glob && /.{js,jsx,tsx}/.test(glob);

if (isJsTsxFiles) {
    module.exports = {
        extends: ["stylelint-config-standard", "stylelint-config-styled-components"],
        processors: ["stylelint-processor-styled-components"],
        plugins: ["stylelint-order"],
        rules: {
            "font-family-no-missing-generic-family-keyword": null,
            "order/properties-alphabetical-order": true,
            indentation: 4,
            "declaration-empty-line-before": null,
            "no-eol-whitespace": null
        }
    };
}

module.exports = {
    extends: ["stylelint-config-standard"],
    processors: [],
    plugins: ["stylelint-scss", "stylelint-order"],
    rules: {
        indentation: 4
    }
};

from stylelint-processor-styled-components.

linonetwo avatar linonetwo commented on May 20, 2024 2

The problem is that I didn't run stylelint by myself, I just run it via vscode's plugin, so it will run it against all file I guess.

from stylelint-processor-styled-components.

chinesedfan avatar chinesedfan commented on May 20, 2024 2

Recently, we released v1.8.0(#267) which supports the option ignoreFiles to make the processor skip some files. Maybe it can help.

from stylelint-processor-styled-components.

AntonioRedondo avatar AntonioRedondo commented on May 20, 2024 1

I've also came accross with this problem when linting jsx and scss files at the same time. Linting works as expected when only a kind of file is linted at once but this error arises when types are mixed up.

I think README.md should be updated to reflect that jsx/js files should be linted in a separated go than css/scss/less files. The below line appearing at the moment is confusing:

NOTE: Don't worry about passing in files that don't contain any styled-components code – we take care of that.

from stylelint-processor-styled-components.

JonWallsten avatar JonWallsten commented on May 20, 2024

Same here:

$ stylelint './packages/**/*.tsx'
SyntaxError: Unexpected token, expected , (155:10)
    at Parser.pp$5.raise (/Users/.../node_modules/babylon/lib/index.js:4452:13)
    at Parser.pp.unexpected (/Users/.../node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp.expect (/Users/.../node_modules/babylon/lib/index.js:1749:33)
    at Parser.pp$3.parseParenAndDistinguishExpression (/Users/.../node_modules/babylon/lib/index.js:3812:12)
    at Parser.pp$3.parseExprAtom (/Users/.../node_modules/babylon/lib/index.js:3707:19)
    at Parser.parseExprAtom (/Users/.../node_modules/babylon/lib/index.js:7113:22)
    at Parser.pp$3.parseExprSubscripts (/Users/.../node_modules/babylon/lib/index.js:3492:19)
    at Parser.pp$3.parseMaybeUnary (/Users/.../node_modules/babylon/lib/index.js:3472:19)
    at Parser.pp$3.parseExprOps (/Users/.../node_modules/babylon/lib/index.js:3402:19)
    at Parser.pp$3.parseMaybeConditional (/Users/.../node_modules/babylon/lib/index.js:3379

Unfortunately no source file. So I don't know where to fix this.

from stylelint-processor-styled-components.

mxstbr avatar mxstbr commented on May 20, 2024

@linonetwo Are you running this processor on a .css file? That probably won't work and is nothing we can support I don't think?

@JonWallsten your issue is that you're using TypeScript, but we're using Babylon for parsing which doesn't support Typescript 😢

from stylelint-processor-styled-components.

mxstbr avatar mxstbr commented on May 20, 2024

I'll mark this as wontfix since you shouldn't run this processor when linting .css files, but maybe there's something I'm missing here!

from stylelint-processor-styled-components.

emilgoldsmith avatar emilgoldsmith commented on May 20, 2024

Hmmm... I'm not quite an expert on stylelint, but I just searched a bit, and could it be true that there is no way to specify different stylelint configurations for different file types?

Because yeah, this processor as of right now only supports Javascript files.

@AntonioRedondo if it's true there is currently no way to specify different configs based on a regex, maybe you should open an issue with the Stylelint repo?

And yeah it definitely wouldn't hurt slightly updating the README to reflect that we truly only support Javascript files if that isn't clear enough, feel free to submit a PR with the clarifications you feel are needed :).

from stylelint-processor-styled-components.

ismay avatar ismay commented on May 20, 2024

and could it be true that there is no way to specify different stylelint configurations for different file types?

The way I know of is to use the cli with the config flag:

stylelint "*.css" --config config-for-css.json
stylelint "*.jsx" --config config-for-jsx.json

However I think the node implementation of stylelint just looks for the standard config files.

from stylelint-processor-styled-components.

emilgoldsmith avatar emilgoldsmith commented on May 20, 2024

Yeah that's definitely a possibility.

But I guess that wouldn't work for for example text editor plugins.

You would need a webpack'ish implementation of

test: /\.jsx?/,
loader: [
  stylelint,
  config: { ... }
],
test: /\.css/,
loader: [
  stylelint,
  config: { ... }
]

implemented I guess, which would be a stylelint issue / PR that should be opened there.

from stylelint-processor-styled-components.

ismay avatar ismay commented on May 20, 2024

Yeah. Nothing we can do about it anyway.

from stylelint-processor-styled-components.

ttraenkler avatar ttraenkler commented on May 20, 2024

Is there a way to configure stylelint differently for css and js files in the stylelint section of package json or is the only option to write a different config file and run stylelint twice?

from stylelint-processor-styled-components.

emilgoldsmith avatar emilgoldsmith commented on May 20, 2024

Currently Stylelint (as far as I know) doesn't allow putting in different configs for different files in an easy way, you could either get this to happen by contributing to #163 so we can get that merged, or helping get that implemented for Stylelint itself

from stylelint-processor-styled-components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.