如果div为空,则Eslint airbnb gets强制执行自我关闭div标签。如何禁用此规则?

时间:2018-10-22 23:40:19

标签: javascript visual-studio-code eslint eslint-config-airbnb eslintrc

如果div元素为空,则Airbnb规则将删除关闭div标签,例如:

<div></div>

被替换为

<div/>

我的.eslintrc文件是这样的:

{
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 9,
    "ecmaFeatures": {
      "impliedStrict": true,
      "jsx": true
    }
  },
  "env": {
    "node": true,
    "es6": true
  },
  "plugins": ["react"],
  "rules": {
    "react/jsx-filename-extension": ["off"],
    "react/prefer-stateless-function": ["off"],
    "arrow-body-style": ["error", "always"],
    "react/self-closing-comp": [
      "error",
      {
        "component": true,
        "html": false
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:0)

“ react / self-closes-comp” 设置为“关闭”。

 {
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 9,
    "ecmaFeatures": {
      "impliedStrict": true,
      "jsx": true
    }
  },
  "env": {
    "node": true,
    "es6": true
  },
  "plugins": ["react"],
  "rules": {
    "react/jsx-filename-extension": ["off"],
    "react/prefer-stateless-function": ["off"],
    "arrow-body-style": ["error", "always"],
    "react/self-closing-comp": "off"
  }
}