项目作者: jamespamplin

项目描述 :
ESLint config for the idiomatic js style
高级语言: JavaScript
项目地址: git://github.com/jamespamplin/eslint-config-idiomatic.git
创建时间: 2015-08-23T21:16:58Z
项目社区:https://github.com/jamespamplin/eslint-config-idiomatic

开源协议:MIT License

下载


eslint-config-idiomatic

NPM
Build
Greenkeeper badge

An ESLint shareable config for the idiomatic js coding style.

Ensure your source code adheres to the idiomatic js coding style by linting
your code with ESLint. Hook ESLint into your editor and build pipeline for
maximum effect.

:memo: Note for upgrades from v2.x: this config no longer extends eslint:recommended. See Usage.

Idiomatic example:

  1. const thing = 'Hello',
  2. another = 'World',
  3. total = count([ 1, 2, 3]);
  4. function idiomatic( arg ) {
  5. let out = 'Bye';
  6. if ( !arg ) {
  7. out = thing;
  8. } else if ( arg === thing ) {
  9. out = another;
  10. }
  11. return out;
  12. }

Install

  1. npm install --save-dev eslint-config-idiomatic

Note:

  • use version ^3.0.0 for ESLint version ^3.x.x.
  • use version ^2.0.0 for ESLint version ^2.x.x.
  • use version ^1.0.0 for ESLint version ^1.x.x.

Usage

In your .eslintrc file:

  1. {
  2. "extends": "idiomatic"
  3. }

To use with ESLint’s recommended ruleset:

  1. {
  2. "extends": [
  3. "eslint:recommended",
  4. "idiomatic"
  5. ]
  6. }

Note: eslint:recommended should be listed first.

Overrides

You can easily override rules in your own .eslintrc config. For example, to
use 4 space indents instead of 2:

  1. {
  2. "extends": "idiomatic",
  3. "rules": {
  4. "indent": [2, 4]
  5. }
  6. }

ES5

eslint-config-idiomatic is ES6+ by default. To use ES5, extend idiomatic/es5
in your .eslintrc:

  1. {
  2. "extends": "idiomatic/es5"
  3. }

Slight differences

The rules enforces by this config may differ slightly from the idiomatic js
styleguide. These are outlined below.

Strict Indent

This config restricts to 2 spaces soft indent and will error when
indentation differs.

Single quotes

Idiomatic does not enforce a particular style for quotes, but recommends
consistency across the project. This config enforces 'single' quotes, but to
override to use "double" quotes in your project:

  1. {
  2. "extends": "idiomatic",
  3. "rules": {
  4. "quotes": [2, "double"]
  5. }
  6. }

Warn on missing function names

Names on functions are recommended as they will show in stack traces, which aids
debugging immensely. eslint-config-idiomatic will only issue a warning
instead of an error when a function name is omitted, which is useful for
anonymous functions.

  1. // Good (named function):
  2. function foo() {
  3. return 'bar';
  4. }
  5. // Anonymous function (will issue warning):
  6. var foo = function() {
  7. return 'bar';
  8. };
  9. // ES6 arrow function preferred for Anonymous functions (no warn, requires ES6+):
  10. let foo = () => 'bar';

Contributing

Issues and PRs more than welcome. Please ensure you have tests for your PRs, and
that npm test passes.