Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

📝 Enumerating eslint rules + package refactoring #1

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["./index.js"],
"rules": {
"no-magic-numbers": 0 // because rules are 0, 1, 2
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
node_modules
npm-debug.log
yarn-error.log
yarn.lock
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.editorconfig
.gitignore
.travis.yml
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 87 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,95 @@
# eslint-config-casumo
Holds Casumo's base JS .eslintrc as an extensible shared config
<h1 align="center">eslint-config-casumo</h1>

## Install
<p align="center">
<a title='npm version' href="https://www.npmjs.com/package/eslint-config-casumo">
<img src='https://img.shields.io/npm/v/eslint-config-casumo.svg?style=flat-square' />
</a>
<a title='MIT License' href="https://opensource.org/licenses/MIT">
<img src='https://img.shields.io/npm/l/eslint-config-casumo.svg?style=flat-square' />
</a>
<a title='Downloads' href='http://npm-stat.com/charts.html?package=eslint-config-casumo&from=2015-08-01'>
<img src='https://img.shields.io/npm/dm/eslint-config-casumo.svg?style=flat-square' />
</a>
<a title='Commitizen friendly' href='http://commitizen.github.io/cz-cli/'>
<img src='https://img.shields.io/badge/commitizen-friendly-brightgreen.svg' />
</a>
</p>

<h4 align="center">
ESLint shareable config for the Casumo JavaScript code style
</h4>

***

## Installation

```bash
npm install eslint-config-casumo
npm install --save-dev eslint-config-casumo
```

## Usage
Add the following to your `.eslintrc` file:
```javascript
Once the `eslint-config-casumo` package is installed, you can use it by specifying `casumo` in the [`extends`](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) section of your [ESLint configuration](http://eslint.org/docs/user-guide/configuring).

```js
{
"extends": "eslint-config-casumo"
"extends": "casumo",
"rules": {
// Additional, per-project rules...
}
}
```
```

_Note: We omitted the `eslint-config-` prefix since it is automatically assumed by ESLint._

You can override settings from the shareable config by adding them directly into your `.eslintrc` file.

### Configuration structure
- `casumo/rules/...` - grouping for rules by category (f.ex `eslint`, `mocha`, etc.)
- Each group ideally would have `on/off.js` configurations files which will be used for composing presets
- `causmo/configuration/...` - composition of rules into 'presets'

#### Why `on.js` and `off.js`?
The idea is to always ship a complete list of ESLint rules and explicitly turn off rule groups which are not needed. This is mostly useful for when `eslint-find-rules` runs. In case any new rule is added the plugin will call out the missing rule.

For example if we want to completely ignore `ecma-script-6` rules we just extend the configuration preset with `/rules/eslint/ecma-script-6/off.js`.

### Full configurations

This package includes the following complete and ready to use configurations:

- `casumo` - ES5 config
- `casumo/configurations/es5` - ES5 config
- `casumo/configurations/es5-browser` - ES5 + browser
- `casumo/configurations/es5-node` - ES5 + node
- `casumo/configurations/es5-test` - ES5 + test
- `casumo/configurations/es6` - ES6 config
- `casumo/configurations/es6-browser` - ES6 + browser
- `casumo/configurations/es6-node` - ES6 + node
- `casumo/configurations/es6-test` - ES6 + test
- `casumo/configurations/off` - All rules disabled

## NPM scripts

- `commit` - use this if you do not have [`commitizen`](https://github.com/commitizen/cz-cli) installed globally
- `lint` - lints the current project
- `find-new-eslint-rules` - checks for new (missing) rules
- `test` - runs a couple of tests

## Contributing

To contribute to the project, please follow these steps:

0. File an issue with the idea you wish to put forward
0. Fork the repo
0. Make a branch for your change
0. Run `npm` or `yarn install`
0. Make your changes
0. Run `npm` or `yarn test`
0. Run `git add -A` to add your changes
0. Run `npm` or `yarn run commit` (do not use git commit - unless you have [`commitizen`](https://github.com/commitizen/cz-cli) installed globally)
0. Push your changes
0. Create the Pull Request
0. Get merged and 🎉!

## Thanks to
- [eslint-config-walmart](https://github.com/walmartlabs/eslint-config-walmart) - for inspiration
6 changes: 6 additions & 0 deletions configurations/es5-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: './es5.js',
env: {
browser: true
}
};
12 changes: 12 additions & 0 deletions configurations/es5-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: [
'./es5.js',
'../rules/eslint/node-js-and-common-js/on.js'
],
env: {
node: true
},
rules: {
strict: [2, 'global']
}
};
13 changes: 13 additions & 0 deletions configurations/es5-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: [
'./es5.js',
'../rules/mocha/on.js'
],
env: {
mocha: true
},
rules: {
'max-nested-callbacks': 0,
'no-magic-numbers': 0
}
};
27 changes: 27 additions & 0 deletions configurations/es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
extends: [
'../rules/eslint/best-practices/on.js',
'../rules/eslint/possible-errors/on.js',
'../rules/eslint/ecma-script-6/off.js',
'../rules/eslint/node-js-and-common-js/off.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any benefit of requiring in the turned off rules explicitly here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because the idea is to always ship a full set of rules including on and off.

Like this we are explicitly ignoring ecma-script-6 and node-js-and-common-js rules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

'../rules/eslint/strict-mode/on.js',
'../rules/eslint/stylistic-issues/on.js',
'../rules/eslint/variables/on.js',
// The following line is needed since `eslint-find-rules -u` does not skip deprecated rules.
// This can be removed once https://github.com/sarbbottam/eslint-find-rules/issues/172 is resolved.
'../rules/eslint/deprecated/off.js'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we require in turned off rules here?
'../rules/eslint/deprecated/off.js'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get a green light from eslint-find-rules.

Currently it is throwing an error if the deprecated rules are not included.

Waiting on sarbbottam/eslint-find-rules#172 to be resolved and then we can safely remove them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, ok, I see now. Can we add a comment or a todo to these, so they are describing why they are there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree :)

],
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
ecmaFeatures: {}
},
env: {
amd: true
},
globals: {
module: false,
process: false
},
rules: {}
};
6 changes: 6 additions & 0 deletions configurations/es6-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: './es6.js',
env: {
browser: true
}
};
18 changes: 18 additions & 0 deletions configurations/es6-node-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
extends: [
'./es6-test.js'
],
env: {
mocha: true,
phantomjs: true
},
globals: {
expect: true,
sandbox: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add

    describe: true,
    it: true

as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env mocha does the trick :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaa, cool I missed that :P 👍

},
rules: {
'max-nested-callbacks': 0,
'no-unused-expressions': 0,
'no-magic-numbers': 0
}
};
24 changes: 24 additions & 0 deletions configurations/es6-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
extends: [
'./es6.js',
'../rules/eslint/node-js-and-common-js/on.js'
],
env: {
node: true
},
parserOptions: {
sourceType: 'script',
ecmaFeatures: {
impliedStrict: false
}
},
globals: {},
rules: {
'constructor-super': 0,
'no-class-assign': 0,
'no-dupe-class-members': 0,
'no-this-before-super': 0,
'prefer-reflect': 0,
strict: [2, 'global']
}
};
13 changes: 13 additions & 0 deletions configurations/es6-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: [
'./es6.js'
],
env: {
mocha: true,
phantomjs: true
},
rules: {
'max-nested-callbacks': 0,
'no-magic-numbers': 0
}
};
18 changes: 18 additions & 0 deletions configurations/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
extends: [
'./es5.js',
'../rules/eslint/ecma-script-6/on.js'
],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true
}
},
env: {
es6: true
},
globals: {},
rules: {}
};
22 changes: 22 additions & 0 deletions configurations/off.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a composition file for the turned off rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be useful if someone wants to have only small number of rules turned on. Composing a config file with off.js and their overrides

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I think it is descriptive enough if you only import / define the rules that you would like to enable. As no eslint rules are enabled by default, when would someone need to import this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As no eslint rules are enabled by default, when would someone need to import this?

If you do not import all the off rules then eslint-find-rules would fail with the -u option

extends: [
'../rules/eslint/best-practices/off.js',
'../rules/eslint/possible-errors/off.js',
'../rules/eslint/ecma-script-6/off.js',
'../rules/eslint/node-js-and-common-js/off.js',
'../rules/eslint/strict-mode/off.js',
'../rules/eslint/stylistic-issues/off.js',
'../rules/eslint/variables/off.js',
// The following line is needed since `eslint-find-rules -u` does not skip deprecated rules.
// This can be removed once https://github.com/sarbbottam/eslint-find-rules/issues/172 is resolved.
'../rules/eslint/deprecated/off.js'
],
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
ecmaFeatures: {}
},
env: {},
globals: {},
rules: {}
};
Loading