Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, e.g.:

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

like image 733
Erik B Avatar asked Jun 13 '18 12:06

Erik B


People also ask

What is StandardJS?

What is Standard JS? It is a Style guide, with linter & automatic code fixer. It is a way to enforce consistent style in your project. It automatically formats code. Standard JS is a tool in the Code Review category of a tech stack.


1 Answers

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 (e.g. 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.

like image 146
user7637745 Avatar answered Nov 16 '22 04:11

user7637745