简体   繁体   中英

indentation with eslint on jsx

I'm trying to make simple component. But when I click on ctrl + s it does this:

在此处输入图片说明

warning and error is this:

[eslint] Expected closing tag to match indentation of opening. (react/jsx-closing-tag-location) [eslint] Expected indentation of 4 space characters but found 2. (react/jsx-indent)

my .eslintrc :

{
  "extends": "airbnb",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "experimentalObjectRestSpread": true
    }
  },
  "rules": {
    "max-len": ["warn", 120],
    "indent": ["warn", 2],
    "react/jsx-indent": ["warn", 4],
    "react/forbid-prop-types": 0,
    "semi": [2, "never"],
    "no-underscore-dangle": 0,
    "no-console": 0,
    "linebreak-style": 0,
    "comma-dangle": [2, {
      "arrays": "never",
      "objects": "always",
      "imports": "never",
      "exports": "never",
      "functions": "ignore"
    }]
  },
  "globals": {
    "localStorage": true
  },
  "env": {
    "browser": true,
    "node": true
  }
}

What's wrong?

In your gif the never closes with the same indentation. That should do it:

const App = () => (
  <button>
    <span>asd</span>
  </button>
)

In your gif you have either

const App = () => (
   <button>
     <span>asd</span>
     </button>
)

or

const App = () => (
     <button>
       <span>asd</span>
   </button>
)

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