zoukankan      html  css  js  c++  java
  • vs工程配置eslint检测环境

    vs工程打开一个js文件,会提示

    "No ESLint configuration (e.g .eslintrc) found for file ......."

    "Failed to load the ESLint library for the document ......."

    就是需要配置eslint检测环境

    • 首先使用npm 全局安装eslint
    • 在项目目录中执行eslint --init,这时候会让你选择项目的一些参数,比如模块类型(JavaScript modules (import/export) CommonJS (require/exports) ),框架(vue或react),执行完毕后生成.eslintrc.js(报的错不管)
    • 如果选择vue,还需要安装eslint-plugin-vue插件,这时需要本地安装这个插件

      npm i -save-dev eslint-plugin-vue

    • 需要对.eslintrc.js做一些配置,比如之前选择了JavaScript modules,后面又使用module.exports,必须再加上
    "commonjs": true
    比如:
    module.exports = {
    "env": {
    "browser": true,
    "es6": true,
    "commonjs": true
    },
    ........
    }
     
    • 如果需要在控制台打印调试信息,需要加上:
    "no-console":"off"
    比如:
    module.exports = {
    ......
    "rules": {
    "no-console":"off"
    }
    };
    off也可以用0替代
     "off" -> 0 关闭规则
     "warn" -> 1 开启警告规则
    "error" -> 2 开启错误规则
    • 允许使用一些全局变量,比如node里的__dirname
    "env": {
    ......
    "node": true
    },
    • Eslint中no-undef的检查报错

    有时候使用一些全局变量,会报这个错误,

    这个可以在eslint中增加一个global配置,用于标记哪些可以使用的全局对象

    "globals":{
      "document": true,
      "localStorage": true,
      "window": true
    }

     

     

  • 相关阅读:
    Zookeeper 选举机制
    Hadoop Yarn任务调度器
    Hadoop Yarn工作机制 Job提交流程
    Hadoop 切片机制
    Hadoop MapReduce工作流程
    Hadoop HDFS读写数据流程
    数据仓库 拉链表
    高动态范围照片*5
    Java实现的窗口计算器
    拍摄制作星轨拖尾视频 之 前期拍摄
  • 原文地址:https://www.cnblogs.com/cowboybusy/p/10600686.html
Copyright © 2011-2022 走看看