zoukankan      html  css  js  c++  java
  • ESLint之五种在文件中配置ESLint的方式

     配置ESLint的方式有5种。前面三种是使用npx eslint --init命令生成的配置文件,在选择如何保存配置文件时可以分别选择JavaScript、YAML、JSON三种配置文件格式。三种文件的结构大致都相同。

    1.JavaScript

    module.exports = {
        "env": {
            "browser": true,
            "es2021": true,
            "node": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
            "ecmaVersion": 12,
            "sourceType": "module"
        },
        "rules": {
            "no-console":"off"
        }
    };

     2.YAML

    env:
      browser: true
      es2021: true
      node: true
    extends: 'eslint:recommended'
    parserOptions:
      ecmaVersion: 12
      sourceType: module
    rules: {
      no-console: off
    }

     3.JSON

    {
        "env": {
            "browser": true,
            "es2021": true,
            "node": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
            "ecmaVersion": 12,
            "sourceType": "module"
        },
        "rules": {
            "no-console":"off"
        }
    }

    4.在packages.json配置文件中配置

    {
      "name": "06",
      "version": "1.0.0",
      "main": "index.js",
      "license": "MIT",
      "dependencies": {
        "eslint": "^7.19.0"
      },
      "eslintConfig": {
        "env": {
          "browser": true,
          "es2021": true,
          "node": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
          "ecmaVersion": 12,
          "sourceType": "module"
        },
        "rules": {
          "no-console": "off"
        }
      }
    }

    写在eslintConfig字段中的内容与JSON格式的配置文件相同

    5.针对单个文件的eslint配置

    如在单个js文件中禁用no-console

    /* eslint no-console: "off" */
    console.log(123);
    console.log(123);

    no-console为规则名称,后面是设定的规则。这样后面的no-console都不会报错了

  • 相关阅读:
    混合式应用开发之AngularJS ng-repeat数组有重复值的解决方法
    混合式应用开发之串口通讯(2)
    混合式应用开发之串口通讯(1)
    第一篇博客
    win10出现"本地计算机上的MySQL57服务启动后停止"
    彻底区分html的attribute与dom的property
    Angularv4入门篇1
    node开发后将本地mysql数据导入到服务器mysql
    weex入门
    Color.js 方便修改颜色值
  • 原文地址:https://www.cnblogs.com/codexlx/p/14371212.html
Copyright © 2011-2022 走看看