-1

I use mocha/chai and my .eslint file is in YAML.

What eslint settings could I apply to most projects, i.e. use as a template ?

0

This example works:

env:
  commonjs: true
  es6: true
  node: true
extends:
  - 'plugin:mocha/recommended'
globals:
  Atomics: readonly
  SharedArrayBuffer: readonly
parserOptions:
  ecmaVersion: 2018
rules:
  prefer-const: error
  eqeqeq: error
  no-var: error
  semi: error
plugins:
  - "mocha"
~           

It has 4 simple rules and allows for the describe and it statements in Mocha while applying the 'prefer-const', 'eqeqeq' (use === over ==), etc. rules.

Also if you modify package.json to have:

  "scripts": {
    "pretest": "eslint .",
    "test": "mocha **/*.spec.js"
  },  

then linting will automatically run before your tests when you issue

npm test

to make it seamless and easy and the tests won't run until the linting parses which effectively means that format is tested and enforced. No more code review arguments on formats! once you agree on the rules in the settings.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.