indentation with eslint on jsx

纵然是瞬间 提交于 2019-12-24 01:43:17

问题


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?


回答1:


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>
)


来源:https://stackoverflow.com/questions/49632949/indentation-with-eslint-on-jsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!