简体   繁体   中英

how to configure styled jsx in Eslint

I'm setting up an environment this way to work with a ReactJs/Next.js project that uses 'styled jsx', but eslint can't fix the css flaws in the middle of the code.

How can I best configure eslint to work with the project I'm working on?

 {
          "parser": "@babel/eslint-parser",
          "extends": [
            "airbnb",
            "plugin:react/recommended"
          ],
          "env": {
            "es6": true,
            "browser": true,
            "node": true,
            "jest": true
          },
          "settings": {
            "import/core-modules": ["styled-jsx", "styled-jsx/css"],
          },
          "plugins": [
            "react",
            "react-hooks"
          ],
          "parserOptions": {
            "sourceType": "module",
            "allowImportExportEverywhere": true
          },
          "rules": {
             // ..rules
          }
        }

Check this out:

https://github.com/vercel/styled-jsx#eslint

If you're using eslint-plugin-import , the css import will generate errors, being that it's a "magic" import (not listed in package.json). To avoid these, simply add the following line to your eslint configuration:

"settings": {"import/core-modules": ["styled-jsx/css"] }

This should remove any errors - but you won't get highlighting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM