How to configure StandardJS?
Asked Answered
D

1

9

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?

Drucilladrucy answered 13/6, 2018 at 12:1 Comment(2)
github.com/standard/standard/blob/master/options.js hmmmmmmmmmmmmSpeak
This vscode plugin allows the setting to be modified, maybe look for how they do it marketplace.visualstudio.com/…Speak
W
8

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.

Wager answered 14/6, 2018 at 19:43 Comment(4)
I tried to do that, but it doesn't pick up my .eslintrc.json. Are you saying that anything I can configure in a .eslintrc file would work in the standard configuration in package.json?Drucilladrucy
StandardJS definitely recommends you to put your per-project configurations into the project's package.json, so try that first. Other, than that, try creating a .eslintrc (without any extension) OR eslintrc.json (without leading dot) in your project's root directory and check, whether StandardJS picks it up. If not, looks like their current implementation prefers the package.json option.Wager
If none of the above works, check out this repository and try its solution to configure StandardJS. Please, try these options out and get back to me about what solution worked for you.Wager
That's what I did. I simply configured eslint to use the standard configuration, so that I can have different linting rules for my tests. However, that doesn't answer my question.Drucilladrucy

© 2022 - 2024 — McMap. All rights reserved.