How to avoid no-param-reassign when setting a property on a DOM object

前端 未结 11 745
无人共我
无人共我 2020-12-23 15:41

I have a method which\'s main purpose is to set a property on a DOM object

function (el) {
  el.expando = {};
}

I use AirBnB\'s code style

11条回答
  •  一个人的身影
    2020-12-23 16:30

    As @Mathletics suggests, you can disable the rule entirely by adding this to your .eslintrc.json file:

    "rules": {
      "no-param-reassign": 0
    }
    

    Or you could disable the rule specifically for param properties

    "rules": {
      "no-param-reassign": [2, { "props": false }]
    }
    

    Alternatively, you could disable the rule for that function

    /* eslint-disable no-param-reassign */
    function (el) {
      el.expando = {};
    }
    /* eslint-enable no-param-reassign */
    

    Or for that line only

    function (el) {
      el.expando = {}; // eslint-disable-line no-param-reassign
    }
    

    You might also check out this blog post on disabling ESLint rules specifically to accommodate AirBnB's style guide.

提交回复
热议问题