Skip to content

ESLint shareable config for the Smartcar JavaScript style guide

License

Notifications You must be signed in to change notification settings

smartcar/eslint-config-smartcar

Repository files navigation

@smartcar/eslint-config Build Status

ESLint shareable config for Smartcar

Installation

This package is intended for internal use and may not follow Semver guidelines

  1. Authenticate with GitHub package registry by following these steps.

  2. npm install --save-dev eslint @smartcar/eslint-config

  3. 🎉

You may also be able to integrate ESLint into your text editor, a list of integrations is available here.

Configuration

Create a .eslintrc.js file in the root of your project containing the following:

'use strict';

module.exports = {
  extends: [
    // required
    '@smartcar/eslint-config',

    // optional
    '@smartcar/eslint-config/mocha', // or '@smartcar/eslint-config/ava',
    '@smartcar/eslint-config/lodash',
  ],
};

Enabling the mocha, ava, and lodash configurations enables rules that are specific to those frameworks.

Add a npm bin script for linting

{
  "name": "my-awesome-project",
  "scripts": {
    "lint": "eslint . --cache"
  }
}

To run the linter on your project simply run npm run lint and ESLint will report back errors and warnings. You can also run npm run lint -- --fix to use ESLint's automatic fix mode, this will fix most simple style and spacing errors.

Ignoring

  • Ignore at a project level:
'use strict';

module.exports = {
  extends: '@smartcar/eslint-config',
  rules: {
    camelcase: 'off',
  },
};
  • Ignoring files or folders: Create a .eslintignore file at the root of your project

.eslintignore

# node_modules/* and bower_components/* are ignored by default
coverage/*
.vscode/*
.idea/*
  • Ignore at a file level:
'use strict';

/* eslint-disable no-console */
console.log("What's linting?");
  • Ignore block:
/* eslint-disable console */
console.log('No one can stop me!');
console.log("I'm free from the linter!");
console.log('bawahaha');
/* eslint-enable console */

console.log('crap...');
  • Ignore next line:
// eslint-disable-next-line no-console
console.log("I'm free!");
console.log("I'm an error :( ");
  • Inline ignore:
console.log("I'm free!"); // eslint-disable-line no-console
console.log("I'm an error :( ");

Related

License

MIT © Smartcar, Inc.