zoukankan      html  css  js  c++  java
  • [Javascript] Linting JavaScript with ESLint

    ESLint is a JavaScript linter (static analysis tool) that offers full support for ES6, JSX, and other modern tools via plugins. We walk through setting up ESLint in a project, using the "init" CLI tool, configuring warnings/errors for rules, and adding editor plugins and build integrations. ESLint is built to be "pluggable" with simple, extendable, modular rules and an API for writing and using plugins. ESLint has many rules which are all turned off by default; you can extend the core "recommended" rules which will catch common JavaScript errors, and you can also turn on stylistic rules for code consistency.

    Install:

    npm install eslint --save-dev
    npm install -g eslint

    Run:

    eslint --init   or eslint index.js main.js

    Will create an .eslintrc file for you.

    {
        "rules": {
            "indent": [
                2,
                "tab"
            ],
            "quotes": [
                2,
                "single"
            ],
            "linebreak-style": [
                2,
                "windows"
            ],
            "semi": [
                2,
                "always"
            ]
        },
        "env": {
            "es6": true,
            "node": true,
            "browser": true
        },
        "extends": "eslint:recommended"
    }

    Check http://eslint.org/docs/rules/ for more docs.

    In package.json:

      "scripts": {
        "lint": "eslint **.js"
      },

    Add no-unused-var warning:

    {
        "rules": {
            "indent": [
                2,
                "tab"
            ],
            "quotes": [
                2,
                "single"
            ],
            "linebreak-style": [
                2,
                "windows"
            ],
            "semi": [
                2,
                "always"
            ],
            "no-unused-vars": 1 // no var -> 1: warning, 2: error, 0: ignore
        },
        "env": {
            "es6": true,
            "node": true,
            "browser": true
        },
        "extends": "eslint:recommended"
    }
  • 相关阅读:
    6.etc目录下重要文件和目录详解
    5.linux目录结构介绍
    4.CRT远程连接的使用
    3.了解linux系统以及搭建学习环境
    记录groupby的一次操作
    keras 文本序列的相关api
    networkX.core_number(graph)
    关于无向图的最大团的问题。
    数据分析,numpy pandas常用api记录
    conda install 失败 http404
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4765359.html
Copyright © 2011-2022 走看看