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

Conversation

camilleriluke
Copy link
Contributor

@camilleriluke camilleriluke commented Dec 22, 2016

This is a non breaking change.

Followed the basic structure of eslint-config-walmart and migrated our rules.

What changed

  • Split the rules into categories according to http://eslint.org/docs/rules/
  • Added supports for different configurations (es5, es5-test, es6, etc.)
  • Added support for commitizen
  • Added validation on commit messages (husky and validate-commit-msg)
  • Added eslint as a dependency and peer dependency
  • Added npm scripts
    • npm run commit for those who don't have commitizen installed globally
    • npm run lint self linting
    • npm run find-new-eslint-rules - checks for new (missing) rules inside for all the configurations
    • npm run test - lints and checks for rules
  • Pimped up README
  • Added a license files
  • Added ignore on debug files

More things to look into

Copy link
Contributor

@leventebalogh leventebalogh left a comment

Choose a reason for hiding this comment

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

Our first PR 🚀 🥇
Nice job! :)

[![version](https://img.shields.io/npm/v/eslint-config-casumo.svg?style=flat-square)](https://www.npmjs.com/package/eslint-config-casumo)
[![downloads](https://img.shields.io/npm/dm/eslint-config-casumo.svg?style=flat-square)](http://npm-stat.com/charts.html?package=eslint-config-casumo&from=2015-08-01)
[![MIT License](https://img.shields.io/npm/l/eslint-config-casumo.svg?style=flat-square)](http://opensource.org/licenses/MIT)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, just wanted to recommend the commitizen-friendly badge, but see it's already there 😛

@@ -0,0 +1,77 @@
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.

I think it would be nice to move these rule categories to a sub-directory, like /rules

browser: true,
node: true
},
rules: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't include any environment setup in the rules themselves to make them more composable.
So like:

module.exports = {
    rules: {
        /* ... */
    }
}

// NO_RULE 'require-await': 2,
'vars-on-top': 2,
'wrap-iife': 2
// 'yoda': 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition name yoda still makes me laugh 😄

// 'accessor-pairs': 2,
// 'array-callback-return': 2,
// 'block-scoped-var': 2,
// NO_RULE 'class-methods-use-this': 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really agree that we should add all the rules we don't use commented out. This makes it harder to read, and requires you to read the README to understand why are they commented out and to get what NO_RULE means. Also we have to maintain the commented out rules as well as ESLint is updating.

I would rather just remove these rules for now (the ones we don't use) and add them back 1 by 1 by PRs when we feel the need for them. Then the conversation on that specific rule can be tracked down in the PR itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I the main reason I added this is for ease of use.

Pre this PR someone would have to cross reference the rules with the eslint site and copy and paste the config files in here (check if already exists and so on). My intention was to make it easy for someone to look at the category file (f.ex stylistic.js) and get a fast clear picture of what are the possible rules they can enabled.

I will add the suggested workflow to follow in a contribution guide. That would give all the information to anyone who would like to contribute.

'./stylistic-issues.js',
'./ecma-script-6.js'
],
rules: {},
globals: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think globals setup should go with environments, e.g. we have different globals needed for a test environment, for a browser and a node environment.

@leventebalogh
Copy link
Contributor

I don't know the right solution yet, I am just starting out from that I would like to use something like this:

// tests/.eslintrc
{
    "extends": [
        "casumo",
        "casumo/es6"
        "casumo/mocha"
    ]
}
// gulp/.eslintrc
{
    "extends": [
        "casumo",
        "casumo/es6"
        "casumo/node"
    ]
}

So the environment specific stuff would be only in casumo/node and casumo/mocha in this case. What do you think about that?

@camilleriluke
Copy link
Contributor Author

Had a change of heart and completely changed the direction.

Now we have

  • ./configurations all configurations every application should ideally pick from here
  • ./rules rules grouped by plugin type
  • ./rules/eslint eslint rules split by categories
  • ./rules/mocha relevant mocha rules

So you could use it like this:

By default it is es5 config

{
    "extends": "casumo"
}

or

{
    "extends": "casumo/configurations/es5-browser"
}

and in the gulp folder

{
    "extends": "casumo/configurations/es5-node"
}

Also all rules are enabled (no commented rules), this is to prepare for the check for missing rules npm script

@camilleriluke camilleriluke force-pushed the enumerating-linting-rules branch from 44f9784 to fb65164 Compare December 23, 2016 12:47
@@ -0,0 +1,13 @@
module.exports = {
extends: [
'../configurations/es5.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

./es5.js would be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha I was following the pattern ../ to be consistent and easy on the eye 😄

this looks ugly 😛

extends: [
    './es5.js',
    '../rules/mocha/on.js'
],

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 thought it was accidental.
Yea, it's really easier to read that way and communicates the context. Agreed :)

@@ -0,0 +1,12 @@
module.exports = {
extends: [
'../configurations/es5.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

./es5.js would be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as #1 (comment)

'../rules/eslint/strict-mode/on.js',
'../rules/eslint/stylistic-issues/on.js',
'../rules/eslint/variables/on.js',
'../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 :)

@@ -0,0 +1,18 @@
module.exports = {
extends: [
'../configurations/es6-test.js'
Copy link
Contributor

Choose a reason for hiding this comment

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

'./es6-test.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.

same as #1 (comment)

},
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/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.

👍

@@ -0,0 +1,24 @@
module.exports = {
extends: [
'../configurations/es6.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

Relative path ./es6.js?

Copy link
Contributor Author

@camilleriluke camilleriluke Dec 23, 2016

Choose a reason for hiding this comment

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

same as #1 (comment)

@@ -0,0 +1,20 @@
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

@leventebalogh
Copy link
Contributor

One thing that I miss is the contribution guideline for it, as I don't really get the main differences between on and off rules, and how to update / use them, so I think new people wouldn't get it as well.

First I thought that the off rule files are containing rules that we don't use, however I saw that the on files contain also the same rules. Are they used to turn off categories explicitly?

@camilleriluke camilleriluke force-pushed the enumerating-linting-rules branch 3 times, most recently from c80e1cc to eb439b5 Compare December 23, 2016 15:32
@camilleriluke camilleriluke force-pushed the enumerating-linting-rules branch from eb439b5 to 72a3ab1 Compare December 24, 2016 17:01
Luke Camilleri added 2 commits January 9, 2017 14:48
Updated contribution steps and added better explenation of the configuration structure
Version bump to 1.1.0
@camilleriluke
Copy link
Contributor Author

PR changes complete. Bumped the version to v1.1.0.

Waiting for 👍 so I will merge it in and publish the package.

@camilleriluke camilleriluke changed the title 📝 Enumerating eslint rules 📝 Enumerating eslint rules + package refactoring Jan 9, 2017
@camilleriluke camilleriluke merged commit b3951fd into casumo-archive:master Jan 9, 2017
@camilleriluke camilleriluke deleted the enumerating-linting-rules branch January 9, 2017 16:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants