0.1.0-preview.5 • Published 2 years ago

@miwebb/eslint-config v0.1.0-preview.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

miWebb shared linting config

To use the config run

yarn add --dev eslint prettier @miwebb/eslint-config
# OR
npm install --save-dev eslint prettier @miwebb/eslint-config

After that, create a new .eslintrc file with the following contents:

{
  "extends": ["@miwebb"]
}

Add a prettier key to your package.json:

{
  // ...
  "prettier": "@miwebb/prettier-config",
  // ...
}

Finally, add some simple linting helpers in your package.json:

{
  // ...
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
    // ... other scripts
  }
}

You can then run yarn lint (or npm run lint) to run and report all linting errors. Some of these errors (such as indentation, etc.) can be automagically fixed for you. Run yarn lint:fix (or npm run lint:fix) to do so.

Formatting will extend @miwebb/prettier-config (to be completed).

Environments

Some of our projects will run in environments that will have globals defined. Our linting config will complain about that unless you tell it otherwise.

First, common environments can be enabled in the .eslintrc under the env key. For example, to assume common browser globals are enabled use:

{
  "extends": ["@miwebb"],
  "env": {
    "browser": true
  }
}

For a complete list of environments, consult the eslint documentation.

Globals

For globals that are not part of environments, such as the wp global in wordpress, you can add custom global variables to the .eslintrc using the "globals" key:

{
  "extends": ["@miwebb"],
  "globals": {
    "wp": "readonly",
    "someOtherGlobal": "writable" // or `true`
  }
}

Globals marked as readonly will raise errors if they are overwritten later, so try to mark globals accordingly. Again, consult the eslint documentation for more information.