• 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都不会报错了

  • 相关阅读:
    爬虫之JSON
    爬虫bs4案例
    爬虫bs4
    爬虫之Xpath案例
    爬虫之xpath
    监控 Kubernetes 集群应用
    手动部署k8s-prometheus
    ingress之tls和path使用
    ingress安装配置
    kube-dns和coreDNS的使用
  • 原文地址:https://www.cnblogs.com/codexlx/p/14371212.html
Copyright © 2020-2023  润新知