Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eslint airbnb gets enforces self closing div tag if the div is empy. How can I disable this rule?

Airbnb linting rules are removing the closing div tag if the div element is empty eg:

<div></div>

Is replaced by

<div/>

My .eslintrc file is this:

{
  "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
      }
    ]
  }
}
like image 657
Kaan Yalti Avatar asked Oct 28 '22 02:10

Kaan Yalti


2 Answers

Set "react/self-closing-comp" to "off".

 {
  "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"
  }
}
like image 144
Tarek Essam Avatar answered Nov 12 '22 13:11

Tarek Essam


I know this post is quiet old but for those who need, I have found a solution, which worked for me :

try :

module.exports = {
  extends: [
    'eslint:recommended',
    'plugin:vue/vue3-recommended'

  ],
  rules: {

    'vue/no-unused-vars': 'error',
    'vue/multi-word-component-names': 'off',
    'vue/html-self-closing': 'off',
     indent: 'off'
  }
}

That's how my config file looks like with Vue3, maybe it can help.

like image 37
dasyx Avatar answered Nov 12 '22 12:11

dasyx