@ig3/eslint-config-entrain

3.0.1 • Public • Published

eslint-config-entrain

npm travis

eslint sharable config for Entrain

Install

npm install --save-dev @ig3/eslint-config-entrain

Usage

In package.json of the package where you want to use @ig3/eslint-config-entrain, add a section to configure eslint to use the shared configuration:

  "eslintConfig": {
    "extends": "@ig3/eslint-config-entrain"
  }

You can add any other configuration you want to the same section. For example, one project required:

  "eslintConfig": {
    "extends": "@ig3/eslint-config-entrain",
    "rules": {
      "node/no-callback-literal": "off"
    },
    "parserOptions": {
      "sourceType": "script"
    }
  }

This overrode one rule setting and changed one parser option, otherwise all settings as per eslint-config-entrain.

For full details of creating and using shared configurations, see: sharable configs.

Alternatively, you can use an eslint configuration file. Again, this is merely a configuration of eslint, so everything in the eslint documentation works as expected.

Rules

eslint-config-entrain is based on eslint-config-standard.

Three rules are changed:

{
  "extends": "standard",

  "rules": {
    "semi": [2, "always"],
    "no-extra-semi": 2,
    "indent": [ "error", 2, { "MemberExpression": 0 }],
    "object-shorthand": ["error", "consistent"]
  }
}

Semicolons are required but no extra semicolons are allowed, and 2 spaces indentation (no tabs) without enforced indentaton of multi-line property chains.

Object shorthand must be used consistently (all shorthand or all long-form) but isn't required.

For example:

  functionReturningPromise()
  .then(result => {
    console.log('the result is: ', result);
  })
  .catch(err => {
    console.error('failed with: ', err);
  });

But if you prefer to indent the promise chain, that's OK too:

  functionReturningPromise()
    .then(result => {
      console.log('the result is: ', result);
    })
    .catch(err => {
      console.error('failed with: ', err);
    });

Motivation

I quite like standardjs except:

  1. For consistency with other languages that require semicolons (e.g. Perl, C, etc.) I prefer to use semicolons to terminate statements. Automatic Semicolon Insertion is an unfortunate misfeature of JavaScript. It is not ambiguous at all (despite much argument, disagreement and misunderstanding) but it requires the developer to be familiar with and pay attention to the rules: something that computers are good at but humans are not.

  2. I don't like indenting promise chains. One of the advantages of promises over callbacks is avoiding indentation and requiring the chain to be indented removes some of this benefit. But eslint-config-entrain doesn't enforce no indentation, so feel free to indent if that's your preference.

  3. Sometimes it is necessary to override settings. standardjs makes doing so difficult to impossible (e.g. it is practically impossible to set parser options when using standard). While consistency is good, sometimes exceptions are appropriate or even necessary (e.g. when developing a common node CJS module that is not using strict mode), particularly when working with existing / legacy code.

  4. Working with a linter which I know is based on eslint but which doesn't behave according to the eslint documentation is frustrating, particularly as some of the features of standardjs are not documented (e.g. details of the command line options).

With this configuration, I can have all the rules of standardjs, with just a couple of personal preference deviations, by using the configuration as-is, but can easily change anything, according to the needs of the specific project, following standard eslint documentation: the best of both worlds.

License

ISC

Changes

3.0.1 - 20220503

Override object-shorthand to consistent

3.0.0 - 20220503

Update dependencies.

 eslint-config-standard   ^16.0.3  →   ^17.0.0     
 eslint-plugin-import    >=2.25.3  →  >=2.26.0     
 eslint-plugin-promise    >=5.1.1  →   >=6.0.0     
 eslint                    ^8.2.0  →   ^8.14.0     
 tape                      ^5.3.1  →    ^5.5.3     

2.0.5 - 20211116

Update dependencies

2.0.4 - 20211027

  • Update dependencies.
  • Adapt tests to the new version of eslint.
  • Add an eslint configuration

2.0.3 - 20210722

Update README.

2.0.2 - 20210720

Change peerDependencies to dependencies.

2.0.1 - 20210718

Removed peer dependency on eslint-plugin-standard

2.0.0 - 20210718

Update dependencies:

 eslint                   >=6.0.1  →  >=7.31.0
 eslint-config-standard   ^14.1.1  →   ^16.0.3
 eslint-plugin-import    >=2.18.0  →  >=2.23.4
 eslint-plugin-node       >=9.1.0  →  >=11.1.0
 eslint-plugin-promise    >=4.2.1  →   >=5.1.0
 eslint-plugin-standard   >=4.0.0  →   >=5.0.0
 tape                      ^4.9.1  →    ^5.2.2

Package Sidebar

Install

npm i @ig3/eslint-config-entrain

Weekly Downloads

0

Version

3.0.1

License

ISC

Unpacked Size

8.15 kB

Total Files

5

Last publish

Collaborators

  • ian.goodacre