Coder Social home page Coder Social logo

eslint-config's Introduction

eslint-config-buildo

buildo's eslint shared config

Usage

In your project's .eslintrc

{
  "extends": "buildo"
}

If you need to override or turn off rules:

{
  "extends": "buildo",
  "rules": {
    "comma-dangle": 0, // disable trailing commas
    "jsx-quotes": "prefer-double" // change
  }
}

You will need the following npm packages:

npm i --save-dev babel-eslint\
                 eslint\
                 eslint-config-buildo

If you'd rather install them globally, you need to explictly require some plugins as well:

npm i -g babel-eslint\
         eslint\
         eslint-config-buildo\
         eslint-plugin-no-copy-paste-default-export\
         eslint-plugin-no-loops\
         eslint-plugin-react

Proposing a new rule

If you are proposing a new rule, you can use linto to pre-check whether it will cause new errors or warnings in the existing projects.

First, get the latest version of linto:

yarn global add linto
# or if you have time
npm install -g linto

Then you can use the configuration you'll find in this repo as a base.

Example

Suppose you want to propose the addition of guard-for-in. Edit the linto-config.yml by adding the rule under test to the eslintConfig section:

repos:
  // ...
eslintConfig:
  // ...
  rules:
    guard-for-in: 2
}

Then run linto

linto run -c linto-config.yml

This will generate a report that you can copy-paste on a GitHub issue.

NOTE

linto purposely ignores the project-specific configurations, so you may run into errors not directly related to the rule under test. If that's the case, simply turn off the offending rules in the configuration, to get more precise results. For instance, if you get a lot of max-len errors, just do:

repos:
  // ...
eslintConfig:
  // ...
  rules:
    max-len: 0
    guard-for-in: 2

You can also do the same for a single repo. For example, this turns off the semi rule only for the 'buildo/foo' repo:

repos:
  - owner: buildo
    name: foo
    eslintConfig:
      rules:
        semi: 0
  // ...
eslintConfig:
  // ...
  rules:
    guard-for-in: 2

Proposing a new plugin

Similarly to rules, you can test new plugins (and their rules). If you add any entries to the plugins section of the ESLint configuration, they will get installed and made available while linto runs.

Example

Suppose you want to propose the addition of eslint-plugin-import. Proceed like before, using a configuration like:

repos:
  // ...
eslintConfig:
  // ...,
  plugins:
    - import
  rules:
    import/named: 2

eslint-config's People

Contributors

gabro avatar giogonzo avatar francescocioria avatar ascariandrea avatar dhinus avatar nemobot avatar greenkeeper[bot] avatar veej avatar

Stargazers

Quoc Nguyen Trong avatar Ramoji avatar Eric Camellini avatar Stefano Saitta avatar

Watchers

 avatar James Cloos avatar  avatar  avatar  avatar Stefano Saitta avatar Eric Camellini avatar  avatar

eslint-config's Issues

update eslint peer dep

description

eslint peer dependency is fixed to 2.x while eslint has been using for months 3.x.

how to reproduce

  • {optional: describe steps to reproduce defect}

specs

update eslint peer dependency

misc

{optional: other useful info}

kill the comments

e.g. // (fixable)

they are useless and tedious to keep in sync with reality

Implicit return and arrow functions

I find this confusing:

[1, 2, 3].map((foo) =>
  bar.something(blabla).foo()
);

That's an implicit return, but I personally can't parse it easily because it's on a separate line.

I propose to always stick to either

[1, 2, 3].map((foo) => bar.something(blabla).foo());

or

[1, 2, 3].map((foo) => {
  return bar.something(blabla).foo();
});

This improves readability and predictability, imho. @buildo/frontend, thoughts?

upgrade eslint-plugin-react

requirements

let's upgrade eslint-plugin-react to v6.x

specs

{optional: describe technical specs to implement this feature, if not obvious}

misc

{optional: other useful info}

let's define our base sets of eslint rules!

@gabro @giogonzo @francescogior @ascariandrea

Hi everyone! In the last week only I fixed/updated like 4 .eslintrc configuration files so, as the base configuration is always the same, I created this new package where we can define our base sets.

For now we only have two files: default.js and production.js

But the point of this discussion is decide which sets we need and create a set of rule for each one (for example we could remove production.js if we don't need it or we could split default.js into es6.js, react.js )

How to use it:

If you want to use these rules in a project (a buildo project you're contributing to or a personal project) you can simply install this package and then extend your .eslintrc like this:

// ALL
"extends": "eslint-config-buildo"

// SOME
"extends": [
  "eslint-config-buildo/rules/SOME_RULE",
  "eslint-config-buildo/rules/SOME_OTHER_RULE"
]

jsx-quotes: 'prefer-single'

Currently we use jsx-quotes with prefer-double which enforces double quotes on JSX strings, but at the same time we use single quotes for strings.

Many others (see airbnb) do the same, and this is the usually the motivation:

Why? JSX attributes can't contain escaped quotes, so double quotes make conjunctions like "don't" easier to type. Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.

However, in our case:

  • you typically need apostrophes while writing English text in attributes. We don't usually do this (strings are in a separate json file) and in the rare circumstances you can always fallback on double quotes (eslint won't complain if you use a single quote inside the string)
  • about consistency with HTML attributes, I personally couldn't care less, do you?

I vote to keep consistency between strings and use single quotes for JSX too.

Thoughts?

/cc @buildo/frontend-opensource

fix dependencies

required dependencies are currently declared as dev-dependencies!

curly

http://eslint.org/docs/rules/curly

set on "all", basically:

ok

if (something) {
  somethingElse();
}

not ok

if (something) somethingElse();

Given that there are only 2 errors in the current LOL codebase (and both by @dhinus :P) it should be a relatively shared rule among buildojsers

@buildo/frontend thoughts?

upgrade eslint-plugin-no-loops

requirements

upgrade eslint-plugin-no-loops to v0.3.x

specs

{optional: describe technical specs to implement this feature, if not obvious}

misc

{optional: other useful info}

Add spaced-comment and no-multi-spaces

Proposing these together since both very minor.. note that both are fixable

spaced-comment and no-multi-spaces

Our average code base does not agree but I think mostly because it was never enforced. There's no convention in the failing projects and they are inconsistent

repo errors warnings
โœ… buildo/aliniq 0 0
โŒ buildo/web-shared 19 0
โŒ buildo/lexdoit 36 0
โŒ buildo/ipercron 10 0
โŒ buildo/bobafett 6 0
โŒ contactlab/contacthub-sdk-browser 3 0
โœ… contactlab/contacthub-sdk-nodejs 0 0
โŒ buildo/avenger 2 0
โŒ buildo/react-components 7 0
โŒ buildo/rc-datepicker 2 0
โŒ buildo/react-cookie-banner 2 0
โœ… buildo/react-autosize-textarea 0 0
โœ… buildo/react-input-link 0 0
โœ… buildo/react-flexview 0 0
โœ… buildo/react-placeholder 0 0
โŒ buildo/local-date 1 0
โŒ buildo/formo 12 0
โœ… buildo/hophop 0 0
โœ… buildo/nemobot 0 0
โŒ buildo/prisma 3 0
โœ… buildo/pledge 0 0

remove `production` rules

requirements

let's have only one source of truth for our rules, having production.js seems more complex than useful
(refer to comments in #1)

specs

move rules from 'production.js' to default one

Create test project to test our rules against

requirements

The idea is to have a test suite so that we can update rules and dependencies with some confidence.

specs

My current proposal is to create a comprehensive project compliant with our ESLint standards.

This allows us to run an updated configuration against the project and verify that nothing breaks.

comma dangle

I'm really tired of seeing diffs like this

const props = {
-  allowBlah: true
+  allowBlah: true,
+  isBaz: false
};

๐Ÿ˜ 

or

const props = {
- allowBlah: true,
- isBaz: false
+ allowBlah: true
};

๐Ÿ˜ง

I'm proposing to change comma-dangle from never to always-multiline, so that we can have nice diffs:

const props = {
  allowBlah: true,
+ isBaz: false,
};

๐ŸŽ‰

or

const props = {
  allowBlah: true,
- isBaz: false,
};

๐Ÿ’ฏ

I'm not a big fan of it from a purely aesthetic point of view, but the advantages are pretty huge when it comes to diffs.

It also makes much easier and less error prone to manipulate objects and arrays, as you don't have to remember to add/remove commas to the last lines.

/cc @buildo/frontend

custom eslint rules to enforce conventions

original issue: https://github.omnilab.our.buildo.io/buildo/labonline/issues/1305

requirements

eslint can be very effective to enforce some conventions. We're already using it to verify if a component's name is the same of its filename.
New rules to help us enforce some conventions::

  • a Component can import only one sass file and only if it has the same name (but in camelCase)
    • ex: MyBeautifulComponent can have import './myBeautifulComponent.scss'
  • the imported sass must be in the same folder (./*.scss)
  • if a component has a main class, this should be the component's name in kebab-case
    • ex: MyBeautifulComponent can have <div className='my-beautiful-component' ...

plugin idea: eslint-plugin-tcomb

A plugin to enforce some conventions in tcomb.

Possible rules:

no-unnamed-types

description

types should always have a name

specs

check last arguments of type definitions


no-loose-structs

description

structs should be strict by default

specs

second argument of t.struct should be an object with strict: true

List npm modules

requirements

The Readme should list the required npm modules.

specs

Add npm i ...

misc

Airbnb does it ;)

Empty lines

I would like to propose some rules to prevent enforce rules about empty lines:

@buildo/frontend what do you think??

add more rules to default config

some experiments in: https://github.omnilab.our.buildo.io/buildo/labonline/blob/web-1416-test_new_eslint_plugins/web/.eslintrc

that .eslintrc should contain exactly the proposed diff wrt current buildo/default

(note that no-this-before-super is already here but disabled (for no reason?))

Some of the rules that I added are a bit opinionated, e.g. no-plusplus.. but it made me discover this beauty: https://github.omnilab.our.buildo.io/buildo/labonline/blob/web-1416-test_new_eslint_plugins/web/src/app/components/Basic/Tabs/Tabs.js#L43-L56

Let's discuss these and/or other possible additions in this issue

Disable global find

requirements

  • eslint doesn't mark find as undefined variables (cause it's a js native function)

specs

  • turn off the global find var

misc

  • my experience is I only use the lodash find method and sometimes I forget to import in the current file. No lint errors, but code doesn't work and I lose time debugging :/

Find a way to document code

requirements

The code documentation should be enforced, at least for some cases, to let external devs understand better how app works, to improve code quality and organization.

specs

For "documentation" I don't mean jsdoc or any other standard, but I'm referring to the concept itself. So we need to define first what parts of code need to be documented and how.

misc

A possible solution could be an eslint rule (or a combo of rules):

but could be a lot of overhead.

add eslint-plugin-import/first

requirements

From their doc

Notably, imports are hoisted, which means the imported modules will be evaluated before any of the statements interspersed between them. Keeping all imports together at the top of the file may prevent surprises resulting from this part of the spec.

This is currently happening in every project we have that uses:

  • babel6
  • metarpheus
  • prelude

In these projects we call the prelude function before metarpheus import, but since babel6 that import is (correctly) hoisted to the top so the prelude is actually called after it leading to some defects

specs

{optional: describe technical specs to implement this feature, if not obvious}

misc

{optional: other useful info}

Add array-bracket-spacing

Add http://eslint.org/docs/rules/array-bracket-spacing

We essentially already follow the default, but using linto I've found a few instances where this isn't true.

linto report:

repo errors warnings
โŒ buildo/aliniq 4 0
โœ… buildo/web-shared 0 0
โŒ buildo/react-components 10 0
โŒ buildo/ipercron 4 0
โœ… buildo/avenger 0 0
โŒ buildo/bobafett 10 0
โœ… buildo/formo 0 0
โœ… buildo/hophop 0 0
โœ… buildo/pledge 0 0

add object-shorthand

not sure if it was there or not, but it's not anymore and it's not part of eslint:recommended

it should be: "object-shorthand": [2, "always"]

[Rules] Add max-len rule

requirements

We should add the rule to lint very long lines.
The default value for code line is 80, which could be fine (to test before) and comments are configurable.

specs

misc

{optional: other useful info}

c/c @buildo/frontend

Enfore space before '/>' in self-closing tags

requirements

In case of self-closing tags (e.g., <MyComponent />) a space should always be present before the closing />.

Example:
The following should be considered an error: <MyComponent/>

specs

{optional: describe technical specs to implement this feature, if not obvious}

misc

{optional: other useful info}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.