简体   繁体   English

如何配置StandardJS?

[英]How to configure StandardJS?

One of the main features of StandardJS is that it doesn't require configuration. StandardJS的一个主要特性是它不需要配置。

The problem is that I want to configure it. 问题是我想配置它。 I don't want to put: 我不想放:

/* eslint-env mocha */

...in every test file. ...在每个测试文件中。 I want to configure StandardJS to treat everything in the test directory as mocha tests. 我想配置StandardJS来将测试目录中的所有内容视为mocha测试。

I've found in the README that some configuration is possible, eg: 我在README中发现一些配置是可能的,例如:

{
  "standard": {
    "globals": [ "myVar1", "myVar2" ]
  }
}

...but I'm struggling to find more comprehensive documentation about the configuration options. ...但我很难找到有关配置选项的更全面的文档。 Is it possible to configure StandardJS to treat files in different directories differently? 是否可以将StandardJS配置为以不同方式处理不同目录中的文件?

You have a couple of options to try out and see what works for your specific project depending on the recent implementation of StandardJS . 根据最近的StandardJS实现,您有几个选项可以尝试并查看适用于您的特定项目的内容


Define your own globals 定义自己的全局变量

in package.json : package.json中

"standard": {
  "globals": [
    "describe",
    "before",
    "after",
    "beforeEach",
    "afterEach",
    "it",
    "assert"
  ]
}

or in .eslintrc : 或者在.eslintrc中

{
  "globals": {
    "describe": false,
    "before": false,
    "after": false,
    "beforeEach": false,
    "afterEach": false,
    "it": false,
    "assert": false
  }
}

More on ESLint's configuration. 有关ESLint配置的更多信息。


Define an environment 定义一个环境

in package.json : package.json中

"standard": {
  "env": {
    "mocha": true
  }
}

or in .eslintrc : 或者在.eslintrc中

{
  "env": {
    "mocha": true
  }
}

Check out currently available environments 查看当前可用的环境


Run StandardJS as an NPM script with the environment specified 将StandardJS作为指定环境的NPM脚本运行

in package.json : package.json中

{
  "scripts": {
    "lint": "standard --env mocha"
  }
}

Use a plugin 使用插件

after installing the plugin (eg eslint-plugin-mocha ) 安装插件后(例如eslint-plugin-mocha

in package.json : package.json中

"standard": {
  "plugins": [
    "mocha"
  ]
}

or in .eslintrc : 或者在.eslintrc中

{
  "plugins": [
    "mocha"
  ]
}

Create your own, customized rules based on StandardJS 基于StandardJS创建自己的自定义规则

Check out this repository . 看看这个存储库 The quick rundown: 快速破解:

Install with: 安装时间:

npm install --save-dev eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node

Then create a .eslintrc file by extending StandardJS and start to fill with your own rules: 然后通过扩展StandardJS创建一个.eslintrc文件,并开始填写您自己的规则:

{
  "extends": "standard"
}

Since StandardJS uses ESLint under the hood , you can pretty much configure it however you want it using ESLint's documentation . 由于StandardJS在引擎盖下使用了ESLint ,因此您可以使用ESLint的文档来配置它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM