简体   繁体   中英

How to configure StandardJS?

One of the main features of StandardJS is that it doesn't require configuration.

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.

I've found in the README that some configuration is possible, eg:

{
  "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?

You have a couple of options to try out and see what works for your specific project depending on the recent implementation of StandardJS .


Define your own globals

in package.json :

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

or in .eslintrc :

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

More on ESLint's configuration.


Define an environment

in package.json :

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

or in .eslintrc :

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

Check out currently available environments


Run StandardJS as an NPM script with the environment specified

in package.json :

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

Use a plugin

after installing the plugin (eg eslint-plugin-mocha )

in package.json :

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

or in .eslintrc :

{
  "plugins": [
    "mocha"
  ]
}

Create your own, customized rules based on 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:

{
  "extends": "standard"
}

Since StandardJS uses ESLint under the hood , you can pretty much configure it however you want it using ESLint's documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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