Other
eslint.yaml VS eslint.json

by Lipis

env:
  browser: true
  node: true

plugins:
  - prettier

extends:
  - prettier

parserOptions:
  ecmaVersion: 8
  sourceType: module
  ecmaFeatures:
    jsx: true

rules:
  curly: 2
  dot-notation: 2
  no-const-assign: 2
  no-dupe-class-members: 2
  no-else-return: 2
  no-inner-declarations: 2
  no-lonely-if: 2
  no-magic-numbers: [2, {ignore: [-1, 0, 1]}]
  no-shadow: 2
  no-unneeded-ternary: 2
  no-unused-expressions: 2
  no-unused-vars: [2, {args: none}]
  no-useless-return: 2
  no-var: 2
  one-var: [2, never]
  prefer-arrow-callback: 2
  prefer-const: 2
  prefer-promise-reject-errors: 2
  prettier/prettier: 2
  sort-imports: 2
  sort-keys: [2, asc, {caseSensitive: true, natural: true}]
  sort-vars: 2
  strict: [2, global]

{
  "env": {
    "browser": true,
    "node": true
  },
  "plugins": ["prettier"],
  "extends": ["prettier"],
  "parserOptions": {
    "ecmaVersion": 8,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "curly": 2,
    "dot-notation": 2,
    "no-const-assign": 2,
    "no-dupe-class-members": 2,
    "no-else-return": 2,
    "no-inner-declarations": 2,
    "no-lonely-if": 2,
    "no-magic-numbers": [
      2,
      {
        "ignore": [-1, 0, 1]
      }
    ],
    "no-shadow": 2,
    "no-unneeded-ternary": 2,
    "no-unused-expressions": 2,
    "no-unused-vars": [
      2,
      {
        "args": "none"
      }
    ],
    "no-useless-return": 2,
    "no-var": 2,
    "one-var": [2, "never"],
    "prefer-arrow-callback": 2,
    "prefer-const": 2,
    "prefer-promise-reject-errors": 2,
    "prettier/prettier": 2,
    "sort-imports": 2,
    "sort-keys": [
      2,
      "asc",
      {
        "caseSensitive": true,
        "natural": true
      }
    ],
    "sort-vars": 2,
    "strict": [2, "global"]
  }
}

Plus YAML among other things.. YAML supports comments and there is no need for { } , " and more overhead :)

Lipis

https://arp242.net/weblog/yaml_probably_not_so_great_after_all.html

Florian Keller

https://arp242.net/weblog/json_as_configuration_files-_please_dont

Lipis

😀

Florian Keller

In the JavaScript ecosystem, JSON is the universal standard for configuration files. With ESLint you picked the perfect example because they are using JSON (or JS) by default. You can see that in their examples: https://eslint.org/docs/user-guide/configuring#specifying-parser-options

Therefore using JSON for ESLint configs has the following benefits over using YAML:

  1. Examples from eslint.org can be copied and pasted into your own configuration with ease (no need to rewrite JSON to YAML)

  2. Homogeneous code base and less complexity (ESLint is used for JavaScript linting and JavaScript coders are already familiar with JSON, so no need to learn another data serialization language)

Another possibility would be using JS files to configure ESLint. When running eslint --init, it also generates a .eslintrc.js file. Having a JavaScript file would allow you to add comments (which are not possible with JSON) and to extend other configurations (because you can require them). :)

Benny Neugebauer

Sign in to comment!