Home

Awesome

Silvermine ESLint Rules

NPM Version License Build Status Dependency Status Dev Dependency Status Conventional Commits

What?

Shareable ESLint configuration for all Silvermine projects.

Why?

Because we need it. Whitespace errors are evil. As are the other hundreds of types of errors this protects us from.

Running ESLint

It is recommended to run ESLint via a NPM script in package.json with the command eslint . for projects that use this configuration.

Example:

{
   "scripts": {
      "eslint": "eslint ."
   }
}

Migration to ESLint flag config

ESLint version 8.57 and later enable support for ESLint's flat config. As opposed to using a customized configuration engine, this enables users to configure ESLint using JS objects and results in more flexibility and control over configuration.

Add a file named eslint.config.js to the root of your project and import our configuration like so:

const silvermineNodeConfig = require('@silvermine/eslint-config/node');

module.exports = [
   ...silvermineNodeConfig.complete,
];

Using Configuration Partials

We maintain specific configurations for various project scenarios, such as Node.js, Mocha.js test suites, Vue3, and Vue2.

When using eslint-config-silvermine you have the option of using the default configuration. For example, below is how you would configure a Node.js project with TypeScript:

const config = require('@silvermine/eslint-config'),
      node = require('@silvermine/eslint-config/partials/node');

module.exports = [
   ...config,
   {
      files: [ '**/*.ts' ],
      ...node
   }
];

Below is how you would configure a browser library that uses only vanilla JS:

const config = require('@silvermine/eslint-config'),
      browser = require('@silvermine/eslint-config/partials/browser');

module.exports = [
   ...config,
   {
      files: [ '**/*.js' ],
      ...browser
   }
];

When you need to override different parts of the config given specific project requirements, you can pull in configuration objects from the partials project directory:

const config = require('@silvermine/eslint-config'),
      node = require('@silvermine/eslint-config/partials/node'),
      nodeTests = require('@silvermine/eslint-config/partials/node-tests');

module.exports = [
   ...config,
   {
      files: [ 'tests/**.ts' ],
      ...nodeTests
   }
]

Vue Support

Our default configuration supports Vue 3 by default.

For legacy Vue.js 2.x projects, a Vue 2-specific configuration is available. In this situation your project would be configured like so:

const config = require('@silvermine/eslint-config'),
   eslintPluginVue = require('eslint-plugin-vue'),
   vueConfig = require('@silvermine/eslint-config/partials/vue'),
   vueBaseRules = require('@silvermine/eslint-config/partials/vue/vue-base');

module.exports = [
   ...config,
   ....eslintPluginVue.configs['flat/vue2-strongly-recommended'],
   {
      files: [ 'src/**.vue' ],
      ...vueConfig,
      rules: vueBaseRules
   }
]

VS Code Support

For VS Code users, your installed version of the ESLint extension must be 3.0.5 or later. This version of the extension supports flat config, while earlier versions only provide partial support.

You may need to adjust the project's local .vscode/setting.json and enable the useFlatConfigoption:

{
   "eslint.useFlatConfig": true
}

Notes on Semantic Versioning

See the notes we made in eslint-plugin-silvermine regarding our use of version numbers here. The same decisions made for that repo also apply to this repo, basically for the same reasons.

What version should I use?

When choosing which version of this config to use, consider the following:

Updating ESLint

Updating ESLint in this project requires multiple steps across both this project and @silvermine/eslint-plugin:

  1. Open a PR to update ESLint in @silvermine/eslint-plugin
    • Note: Linting in the @silvermine/eslint-plugin PR will likely fail because @silvermine/eslint-plugin's version of @silvermine/eslint-config is incompatible with the new version of ESLint. That's ok. We will fix it soon in a subsequent step.
  2. After the PR from step 1 is merged, update @silvermine/eslint-plugin in @silvermine/eslint-config using a git+https + git hash URL. The git hash should point to the commit in @silvermine/eslint-plugin where you updated ESLint.
  3. Update ESLint in @silvermine/eslint-config. Open a PR that contains this update and the @silvermine/eslint-plugin update from step 2.
    • Note: All of the linting and tests in this build should pass.
  4. Publish a new version of @silvermine/eslint-config to the NPM registry
  5. Update @silvermine/eslint-config in @silvermine/eslint-plugin to the version that was just published
    • Note: All of the linting and tests in this build should now pass.
  6. Publish a new version of @silvermine/eslint-plugin to the NPM registry
  7. Update @silvermine/eslint-plugin in @silvermine/eslint-config using the version that was just published

License

This software is released under the MIT license. See the license file for more details.