ESLint Tool

ESLint 简介

ESLint是由Nicholas C. Zakas编写的一个Javascript的验证工具,

ESLint不仅可以检验Javascript错误,也可以进行代码风格检测。

2013年6月发布第一个版本,最新版本是2015年7月24号发布的ESLint 1.0.0-rc-3

ESLint主要有以下特点:

  (1) 默认规则包含所有JSLint、JSHint中存在的规则,易迁移到ESLint

  (2) ESLint相比于JSLint、JSHint,更加灵活强大,规则可配置性很高

  (3) 包含代码风格检测的规则

  (4) 支持插件扩展、自定义规则

ESLint在OpenStack中的应用项目

1.Horizon

2.Murano

ESLint环境搭建

1.安装NodeJS

  NodeJS是一个基于Chrome JavaScript运行时建立的平台,使用V8引擎,用于方便地搭建响应速度快、易于扩展的网络后台应用。

  下载地址:https://nodejs.org/download/

2.使用NPM安装ESLint

  NPM的全称是Node Package Manager,类似pip,通过NPM安装Nodejs的第三方库。

  执行命令:npm install eslint

3.执行eslint命令检测项目中的Javascript文件

  eslint -f junit -o C:\report.xml C:\

  PS: 输出文件内容格式默认为"stylish".

    还包括: "compact", "checkstyle", "jslint-xml", "junit","tap".

ESLint常用配置方式

1.在文件.eslintrc文件配置,支持 JSON 和 YAML 两种语法。.eslintrc 文件YAML示例:

env:
  # Use jquery global variables
  jquery: true
 # If javascript is running in browser
  browser: true

rules:
  # Specify whether backticks, double or single quotes should be used
  # http://eslint.org/docs/rules/quotes
  quotes:
    - 0
    - ‘single‘

  # Require camel case names
  # http://eslint.org/docs/rules/camelcase
  camelcase:
    - 1
    - properties: "never"

  # This option sets a specific tab width for your code
  # http://eslint.org/docs/rules/indent
  indent:
    - 2 # Mark as errors.
    - 2 # horizon uses 2 space indentation.

globals:
  # allow accessing horizon
  horizon: false
  # allow accessing horizon
  murano: false

    PS:.eslintrc 放在项目根目录,则会应用到整个项目;

      如果子目录中也包含.eslintrc 文件,则子目录会忽略根目录的配置文件,应用该目录中的配置文件。

      这样可以方便地对不同环境的代码应用不同的规则。

2.在package.json中配置,使用JSON语法。

{
  "version": "0.0.0",
  "private": true,
  "name": "muranodashboard",
  "description": "Murano Dashboard",
  "repository": "none",
  "license": "Apache 2.0",
  "devDependencies": {
    "eslint": "^0.23.0"
  },
  "scripts": {
    "lint": "eslint --no-color muranodashboard/static"
  },
  "eslintConfig": {
    "env": {
      "jquery": true
      "browser": true
    }
  }
}

ESLint代码检测示例

时间: 2024-08-29 12:52:28

ESLint Tool的相关文章

[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

[React] Linting React JSX with ESLint (in ES6)

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 eslint --init CLI tool with the JSX and ES6 options, writing a R

完全离线安装VSCode插件--Eslint

最近折腾了一番,总算把Eslint插件在离线的情况下安装好了.之前查了挺多,但是很多方法还是在没有完全离线的情况下进行的.之所以想完全离线安装,主要是因为我们工作的地方是禁止访问外网的,所以像直接执行npm命令来进行一些包的安装,其实对我来说是用不了的. 好了,现在进入正题,说下我的解决方式吧. 1.在无法联网的电脑上先把VSCode安装好. 2.在家里有网的电脑上,在vsCode里面的扩展直接安装eslint插件,然后在该路径(C:\Users\Administrator\.vscode\ex

在Eclipse mars 4.5.2 中安装spring 插件 spring tool suite

最近在学习spring,用到的IDE 有eclipse,也有用到 IDEA. 目前对spring还不是很了解,跟着网上的视频来,先学会了spring,然后再选IDE. 题归正转,下面说说怎么在Eclipse mars 4.5.2 中安装spring 插件 spring tool suite. 打开eclipse,然后在菜单栏中点击Help,选中Eclipse MarketPlace: 然后搜索STS(也就是spring tool suite的缩写),回车: 点击Install即可 由于是在线安装

安装Spring Tool Suite(STS)

JAVA开发工具中,常用工具就是Eclipse,IntelliJ IDEA. 现在使用spring boot&cloud框架进行开发的时候,虽然可以使用上面两个工具,但都未必就真的量身定制,IntelliJ虽说是神器,但太重,而且是收费的,免费的社区版也是一个阉割版.Eclipse当然ok,但要装一些插件. Spring官方出品的基于Ecplise的为spring boot&cloud量身打造的工具Spring Tool Suite是一款免费的非常合适的开发工具. STS的安装也非常简单,

ESLint

参考文档:http://eslint.cn/ ESLint 是在 ECMAScript/JavaScript 代码中识别和报告模式匹配的工具,它的目标是保证代码的一致性和避免错误.在许多方面,它和 JSLint.JSHint 相似,除了少数的例外: ESLint 使用 Espree 解析 JavaScript. ESLint 使用 AST 去分析代码中的模式 ESLint 是完全插件化的.每一个规则都是一个插件并且你可以在运行时添加更多的规则. 以上来自官网.不想再说下去,反正就是一个代码风格检

eslint ":"号

eslint规则默认是没有;号的,如果也没要加;号,那就要在.eslintrc.js里面,加配置: 'semi':['error',always']   强制有;号,没有就报错 参考地址:http://eslint.org/docs/rules/semi 看里面的 options

设置emacs插件flycheck使用jslint eslint

emacs的flycheck插件支持使用 jslint 和eslint (setq flycheck-javascript-eslint-executable "~/.nvm/versions/node/v6.4.0/bin/eslint") (setq flycheck-javascript-jshint-executable "~/.nvm/versions/node/v6.4.0/bin/jshint") (setq flycheck-javascript-j

Spring Boot基础教程1-Spring Tool Suite工具的安装

1.工具下载地址: Eclipse:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neonr Spring Tool Suite:https://spring.io/tools/sts/all 2.使用版本为: Eclipse:eclipse-jee-neon-R-win32-x86_64.zip Spring Tool Suite:springsource-tool-suite-3.8.0.RE