ESLint 5.9.0版本问题

升级新版本eslint,编译项目时会出现以下问题

'window' is not defined                                                    no-undef
'document' is not defined                                                  no-undef
'document' is not defined                                                  no-undef
'window' is not defined                                                    no-undef
'window' is not defined                                                    no-undef
'window' is not defined                                                    no-undef
Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
'window' is not defined                                                    no-undef
Expected the Promise rejection reason to be an Error                       prefer-promise-reject-e
'sessionStorage' is not defined                                            no-undef
Unexpected console statement                                               no-console
Expected 'this' to be used by class method 'onRequestStart'                class-methods-use-this
Unexpected console statement                                               no-console
Expected 'this' to be used by class method 'onRequestFinish'               class-methods-use-this
Unexpected console statement                                               no-console
Expected 'this' to be used by class method 'logError'                      class-methods-use-this
Unexpected console statement                                               no-console
Expected 'this' to be used by class method 'sortArray'                     class-methods-use-this

尝试解决问题:

1.window is not defined问题:查找到如下解决方法:然而并没有什么用。

output: {
...
  globalObject: 'this',
}

在.eslintrc文件中填入下面变量,true表示可编辑,false表示不可编辑,将需要全局使用的变量放入globals中。

{
    "rule""{
        ...
    },
    "globals": {
        "window": false,
        "location": false,
        "localStorage": false,
        "document": false
    }
}

2.最终发现需要根据eslint修改,或者对eslint规则进行修改:eslint规则地址 :http://eslint.cn/docs/user-guide/configuring

在搜索框中输入 no-undef 等关键词,查看规则,以及屏蔽规则等;

你可能感兴趣的:(个人笔记,eslint)