eslint-config-ableat

1.1.0 • Public • Published

eslint-config-ableat

npm downloads Run Status

Usage

  1. Add this as a dev dependency to your package.json

    npm install --save-dev eslint-config-ableat
  2. Add ableat to your eslint configuration file

    .eslintrc

    {
        "extends": [
            "ableat"
        ]
    }

    .eslintrc.yml

    extends:
      - ableat
  3. (OPTIONAL) If you're using an editor like Atom or VSCode, you can install this configuration globally

    npm install -g eslint-config-ableat

All the Information!

Environments

ECMAScript 6 (es6)

Enable all ECMAScript 6 features except for modules. This also automatically sets the ecmaVersion parser option to 6. ES6 White Paper

Node

Adds the Node.js global variables and Node.js scoping

Parser Options

Module Source Type

Our code will mostly be written as ECMAScript modules.

Rules

Table of Contents

array-bracket-spacingarrow-parensarrow-spacingbrace-stylecamelcasecurlydefault-casedot-notationeol-lasteqeqeqfor-directionindentkeyword-spacinglinebreak-stylenew-capnewline-per-chained-callno-array-constructorno-confusing-arrowno-consoleno-dupe-class-membersno-duplicate-importsno-else-returnno-empty-functionno-eq-nullno-extra-parensno-fallthroughno-multi-spacesno-multiple-empty-linesno-new-funcno-new-objectno-param-reassignno-useless-constructorno-useless-escapeno-useless-returnno-varno-whitespace-before-propertynonblock-statement-body-positionobject-curly-spacingobject-shorthandpadded-blocksprefer-arrow-callbackprefer-constprefer-templatequote-propsquotessemispace-before-blocksspace-in-parensspaced-commenttemplate-curly-spacingvars-on-topyoda

array-bracket-spacing

// Correct
var arr = []
var arr = ['foo', 'bar', 'baz']
var arr = [['foo'], 'bar', 'baz']
// Incorrect
var arr = [ 'foo', 'bar' ]
var arr = ['foo', 'bar' ]
var arr = [ ['foo'], 'bar']
var arr = [[ 'foo' ], 'bar']

arrow-parens

// Correct
(a) => {}
(a) => {'\n'}
a => ({})
() => {}
a => a
a.then((foo) => {})
a.then((foo) => { if (true) {} })
a((foo) => { if (true) {} })
(a, b, c) => a
(a = 10) => a
([a, b]) => a
({a, b}) => a
// Incorrect
(a) => a
a => {}
a => {'\n'}
a.map((x) => x * x)
a.map(x => {
    return x * x;
})
a.then(foo => {})

arrow-spacing

// Correct
() => {}
(a) => {}
a => a
() => {'\n'}
// Incorrect
()=> {}
() =>{}
(a)=> {}
(a) =>{}
a =>a
a=> a
()=> {'\n'}
() =>{'\n'}

brace-style

// Correct
function foo() {
    return true
}

if (foo) {
    bar()
}

if (foo) {
    bar()
}
else {
    baz()
}

try {
    somethingRisky()
}
catch(e) {
    handleError()
}

// when there are no braces, there are no problems
if (foo) bar()
else if (baz) boom()
// Incorrect
function foo()
{
    return true
}

if (foo)
{
    bar()
}

try
{
    somethingRisky()
} catch(e)
{
    handleError()
}

if (foo) {
    bar()
} else {
    baz()
}

camelcase

// Correct
import { no_camelcased as camelCased } from "external-module"

var myFavoriteColor   = "#112C85"
var _myFavoriteColor  = "#112C85"
var myFavoriteColor_  = "#112C85"
var MY_FAVORITE_COLOR = "#112C85"
var foo = bar.baz_boom
var foo = { qux: bar.baz_boom }

obj.do_something()
do_something()
new do_something()

var { category_id: category } = query

function foo({ isCamelCased }) {
    // ...
}

function foo({ isCamelCased: isAlsoCamelCased }) {
    // ...
}

function foo({ isCamelCased = 'default value' }) {
    // ...
}

var obj = {
    my_pref: 1
}

var { categoryId = 1 } = query

var { foo: isCamelCased } = bar

var { foo: isCamelCased = 1 } = quz
// Incorrect
import { no_camelcased } from "external-module"

var my_favorite_color = "#112C85"

function do_something() {
    // ...
}

obj.do_something = function() {
    // ...
}

function foo({ no_camelcased }) {
    // ...
}

function foo({ isCamelcased: no_camelcased }) {
    // ...
}

function foo({ no_camelcased = 'default value' }) {
    // ...
}

var { category_id = 1 } = query

var { foo: no_camelcased } = bar

var { foo: bar_baz = 1 } = quz

curly

// Correct
if (foo) foo++; else doSomething()

if (foo) foo++
else if (bar) baz()
else doSomething()

do something()
while (foo)

while (foo
  && bar) baz()

if (foo) {
    foo++
}

if (foo) { foo++ }

while (true) {
    doSomething();
    doSomethingElse()
}
// Incorrect
if (foo)
    doSomething()
else
    doSomethingElse()

if (foo) foo(
    bar,
    baz)

default-case

// Correct
switch (a) {
    case 1:
        /* code */
        break

    default:
        /* code */
        break
}


switch (a) {
    case 1:
        /* code */
        break

    // no default
}

switch (a) {
    case 1:
        /* code */
        break

    // No Default
}
// Incorrect
switch (a) {
    case 1:
        /* code */
        break
}

dot-notation

// Correct
var x = foo.bar

var x = foo[bar]    // Property name is a variable, square-bracket notation required
// Incorrect
var x = foo["bar"]

eol-last

// Correct
function doSmth() {
    var foo = 2
} // \n
// Incorrect
function doSmth() {
  var foo = 2
}

eqeqeq

// Correct
a === b
foo === true
bananas !== 1
value === undefined
typeof foo === 'undefined'
'hello' !== 'world'
0 === 0
true === true
foo === null
// Incorrect
a == b
foo == true
bananas != 1
value == undefined
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null

for-direction

// Correct
for (var i = 0; i < 10; i++) {
}
// Incorrect
for (var i = 0; i < 10; i--) {
}

for (var i = 10; i >= 0; i++) {
}

indent

// Correct
if (a) {
    b=c
    function foo(d) {
        e=f
    }
}
// Incorrect
if (a) {
  b=c
  function foo(d) {
    e=f
  }
}

keyword-spacing

// Correct
if (foo) {
    //...
}
else if (bar) {
    //...
}
else {
    //...
}
// Incorrect
if(foo) {
    //...
}
else if(bar) {
    //...
}
else{
    //...
}

linebreak-style

// Correct
var a = 'a', // \n
    b = 'b' // \n
// \n
function foo(params) { // \n
    // do stuff \n
}// \n
// Incorrect
var a = 'a' // \r\n

new-cap

// Correct
var friend = new Person()
// Incorrect
var friend = new person()

newline-per-chained-call

// Correct
_
  .chain({})
  .map(foo)
  .filter(bar)
  .value()

// Or
_
  .chain({})
  .map(foo)
  .filter(bar)

// Or
_.chain({})
  .map(foo)
  .filter(bar)

// Or
obj
  .prop
  .method().prop

// Or
obj
  .prop.method()
  .method2()
  .method3().prop
// Incorrect
_.chain({}).map(foo).filter(bar).value()

// Or
_.chain({}).map(foo).filter(bar)

// Or
_
  .chain({}).map(foo)
  .filter(bar)

// Or
obj.method().method2().method3()

no-array-constructor

// Correct
Array(500)
new Array(someOtherArray.length)
// Incorrect
Array(0, 1, 2)
new Array(0, 1, 2)

no-confusing-arrow

// Correct
var x = a => { return 1 ? 2 : 3; }
var x = (a) => { return 1 ? 2 : 3; }
// Incorrect
var x = a => 1 ? 2 : 3
var x = (a) => 1 ? 2 : 3
var x = (a) => (1 ? 2 : 3)

no-else-return

// Correct
function foo() {
    if (x) {
        return y
    }

    return z
}

function foo() {
    if (x) {
        return y
    } else if (z) {
        var t = "foo"
    } else {
        return w
    }
}

function foo() {
    if (x) {
        if (z) {
            return y
        }
    } else {
        return z
    }
}

function foo() {
    if (error) {
        return 'It failed'
    } else if (loading) {
        return "It's still loading"
    }
}
// Incorrect
function foo() {
    if (x) {
        return y
    } else {
        return z
    }
}

function foo() {
    if (x) {
        return y
    } else if (z) {
        return w
    } else {
        return t
    }
}

function foo() {
    if (x) {
        return y
    } else {
        var t = "foo"
    }

    return t
}

function foo() {
    if (error) {
        return 'It failed'
    } else {
        if (loading) {
            return "It's still loading"
        }
    }
}

no-empty-function

// Correct
function foo() {
    // do nothing.
}

var foo = function() {
    // any clear comments.
}

var foo = () => {
    bar();
}

function* foo() {
    // do nothing.
}

var foo = function*() {
    // do nothing.
}

var obj = {
    foo: function() {
        // do nothing.
    },

    foo: function*() {
        // do nothing.
    },

    foo() {
        // do nothing.
    },

    *foo() {
        // do nothing.
    },

    get foo() {
        // do nothing.
    },

    set foo(value) {
        // do nothing.
    }
}

class A {
    constructor() {
        // do nothing.
    }

    foo() {
        // do nothing.
    }

    *foo() {
        // do nothing.
    }

    get foo() {
        // do nothing.
    }

    set foo(value) {
        // do nothing.
    }

    static foo() {
        // do nothing.
    }

    static *foo() {
        // do nothing.
    }

    static get foo() {
        // do nothing.
    }

    static set foo(value) {
        // do nothing.
    }
}
// Incorrect
function foo() {}

var foo = function() {}

var foo = () => {}

function* foo() {}

var foo = function*() {}

var obj = {
    foo: function() {},

    foo: function*() {},

    foo() {},

    *foo() {},

    get foo() {},

    set foo(value) {}
}

class A {
    constructor() {}

    foo() {}

    *foo() {}

    get foo() {}

    set foo(value) {}

    static foo() {}

    static *foo() {}

    static get foo() {}

    static set foo(value) {}
}

no-eq-null

// Correct
if (foo === null) {
    bar()
}

while (qux !== null) {
    baz()
}
// Incorrect
if (foo == null) {
    bar()
}

while (qux != null) {
    baz()
}

no-extra-parens

// Correct
(0).toString()

(Object.prototype.toString.call())

({}.toString.call())

(function(){}) ? a() : b()

(/^a$/).test(x)
// Incorrect
a = (b * c)

(a * b) + c

typeof (a)

(function(){} ? a() : b())

no-fallthrough

// Correct
switch(foo) {
    case 1:
        doSomething()
        break;

    case 2:
        doSomething()
}

function bar(foo) {
    switch(foo) {
        case 1:
            doSomething()
            return;

        case 2:
            doSomething()
    }
}

switch(foo) {
    case 1:
        doSomething()
        throw new Error("Boo!")

    case 2:
        doSomething()
}

switch(foo) {
    case 1:
    case 2:
        doSomething()
}

switch(foo) {
    case 1:
        doSomething()
        // falls through

    case 2:
        doSomething()
}
// Incorrect
switch(foo) {
    case 1:
        doSomething()

    case 2:
        doSomething()
}

no-multi-spaces

// Correct
var a = 1

if (foo === "bar") {}

a << b

var arr = [1, 2]

a ? b: c
// Incorrect
var a =  1

if(foo   === "bar") {}

a <<  b

var arr = [1,  2]

a ?  b: c

no-multiple-empty-lines

// Correct
var foo = 5

var bar = 3
// Incorrect
var foo = 5



var bar = 3

no-new-func

// Correct
var x = function (a, b) {
    return a + b
}
// Incorrect
var x = new Function("a", "b", "return a + b")
var x = Function("a", "b", "return a + b")

no-new-object

// Correct
var myObject = new CustomObject()

var myObject = {}
// Incorrect
var myObject = new Object()

var myObject = new Object

no-param-reassign

// Correct
function foo(bar) {
    var baz = bar
}
// Incorrect
function foo(bar) {
    bar = 13
}

function foo(bar) {
    bar++
}

no-useless-constructor

// Correct
class A { }

class A {
    constructor () {
        doSomething()
    }
}

class A extends B {
    constructor() {
        super('foo')
    }
}

class A extends B {
    constructor() {
        super()
        doSomething()
    }
}
// Incorrect
class A {
    constructor () {
    }
}

class A extends B {
    constructor (...args) {
      super(...args)
    }
}

no-dupe-class-members

// Correct
class Foo {
    bar() { }
    qux() { }
}

class Foo {
    get bar() { }
    set bar(value) { }
}

class Foo {
    static bar() { }
    bar() { }
}
// Incorrect
class Foo {
    bar() { }
    bar() { }
}

class Foo {
    bar() { }
    get bar() { }
}

class Foo {
    static bar() { }
    static bar() { }
}

no-duplicate-imports

// Correct
import { merge, find } from 'module'
import something from 'another-module'
// Incorrect
import { merge } from 'module'
import something from 'another-module'
import { find } from 'module'

no-useless-escape

// Correct
"\""
'\''
"\x12"
"\u00a9"
"\371"
"xs\u2111"
`\``
`\${${foo}\}`
`$\{${foo}\}`
/\\/g
/\t/g
/\w\$\*\^\./
// Incorrect
"\'"
'\"'
"\#"
"\e"
`\"`
`\"${foo}\"`
`\#{foo}`
/\!/
/\@/

no-useless-return

// Correct
function foo() { return 5 }

function foo() {
  return doSomething()
}

function foo() {
    if (condition) {
        bar();
        return
    }
    else {
        baz()
    }
    qux()
}

function foo() {
    switch (bar) {
        case 1:
            doSomething();
            return
        default:
            doSomethingElse()
    }
}

function foo() {
    for (const foo of bar) {
        return
    }
}
// Incorrect
function foo() { return }

function foo() {
    doSomething()
    return
}

function foo() {
    if (condition) {
        bar()
        return
    }
    else {
        baz()
    }
}

function foo() {
    switch (bar) {
        case 1:
            doSomething();
        default:
            doSomethingElse();
            return
    }
}

no-var

// Correct
let x = "y"
const CONFIG = {}
// Incorrect
var x = "y"
var CONFIG = {}

no-whitespace-before-property

// Correct
foo.bar

foo[bar]

foo[ bar ]

foo.bar.baz

foo
    .bar().baz()

foo
    .bar()
    .baz()

foo.
    bar().
    baz()
// Incorrect
foo [bar]

foo. bar

foo .bar

foo. bar. baz

foo. bar()
    .baz()

foo
    .bar(). baz()

nonblock-statement-body-position

// Correct
if (foo) bar()
else baz()

while (foo) bar()

for (let i = 1; i < foo; i++) bar()

do bar(); while (foo)

if (foo) { // block statements are always allowed with this rule
    bar()
}
else {
    baz()
}
// Incorrect
if (foo)
    bar()
else
    baz()

while (foo)
    bar()

for (let i = 1; i < foo; i++)
    bar()

do
    bar()
while (foo)

object-curly-spacing

// Correct
var obj = {}
var obj = { 'foo': 'bar' }
var obj = { 'foo': { 'bar': 'baz' }, 'qux': 'quxx' }
var obj = {
  'foo': 'bar'
}
var { x } = y
import { foo } from 'bar'
// Incorrect
var obj = {'foo': 'bar'}
var obj = {'foo': 'bar' }
var obj = { baz: {'foo': 'qux'}, bar}
var obj = {baz: { 'foo': 'qux' }, bar}
var obj = {'foo': 'bar'
}
var obj = {
    'foo':'bar'}
var {x} = y
import {foo } from 'bar'

object-shorthand

// Correct
const foo = {
    w() {},
    *x() {},
    [y]() {},
    z
}
// Incorrect
const foo = {
    w: function() {},
    x: function *() {},
    [y]: function() {},
    z: z
}

padded-blocks

// Correct
if (a) {
    b()
}

if (a)
{
    b()
}
// Incorrect
if (a) {

    b()

}

if (a)
{

    b()

}

if (a) {

    b()
}

if (a) {
    b()

}

prefer-arrow-callback

// Correct
foo(a => a)

foo(() => this.a)
// Incorrect
foo(function(a) { return a })

foo(function() { return this.a }.bind(this))

prefer-const

// Correct
// using const.
const a = 0

// it's never initialized.
let a
console.log(a)

// it's reassigned after initialized.
let a
a = 0
a = 1
console.log(a)

// it's initialized in a different block from the declaration.
let a
if (true) {
    a = 0
}
console.log(a)

// it's initialized at a place that we cannot write a variable declaration.
let a
if (true) a = 0
console.log(a)

// `i` gets a new binding each iteration
for (const i in [1, 2, 3]) {
    console.log(i)
}

// `a` gets a new binding each iteration
for (const a of [1, 2, 3]) {
    console.log(a)
}

// `end` is never reassigned, but we cannot separate the declarations without modifying the scope.
for (let i = 0, end = 10; i < end; ++i) {
    console.log(a)
}

// suggest to use `no-var` rule.
var b = 3
console.log(b)
// Incorrect
// it's initialized and never reassigned.
let a = 3
console.log(a)

let a
a = 0
console.log(a)

// `i` is redefined (not reassigned) on each loop step.
for (let i in [1, 2, 3]) {
    console.log(i)
}

// `a` is redefined (not reassigned) on each loop step.
for (let a of [1, 2, 3]) {
    console.log(a)
}

prefer-template

// Correct
var str = "Hello World!"
var str = `Hello, ${name}!`
var str = `Time: ${12 * 60 * 60 * 1000}`
// Incorrect
var str = "Hello, " + name + "!"
var str = "Time: " + (12 * 60 * 60 * 1000)

quote-props

// Correct
var object1 = {
    "a-b": 0,
    "0x0": 0,
    "1e2": 0
}

var object2 = {
    foo: 'bar',
    baz: 42,
    true: 0,
    0: 0,
    'qux-lorem': true
}

var object3 = {
    foo() {
        return
    }
}
// Incorrect
var object = {
    "a": 0,
    "0": 0,
    "true": 0,
    "null": 0
}

quotes

// Correct
var single = 'single'
var backtick = `back${x}tick` // backticks are allowed due to substitution
// Incorrect
var double = "double";
var unescaped = "a string containing 'single' quotes"

semi

// Correct
var name = "ESLint"

object.method = function() {
    // ...
}

var name = "ESLint"

;(function() {
    // ...
})()

import a from "a"
(function() {
    // ...
})()

import b from "b"
;(function() {
    // ...
})()
// Incorrect
var name = "ESLint";

object.method = function() {
    // ...
};

space-before-blocks

// Correct
if (a) {
    b()
}

if (a) {
    b()
} else{ /*no error. this is checked by `keyword-spacing` rule.*/
    c()
}


function a() {}

for (;;) {
    b()
}

try {} catch(a) {}
// Incorrect
if (a){
    b()
}

function a(){}

for (;;){
    b()
}

try {} catch(a){}

class Foo{
  constructor(){}
}

space-in-parens

// Correct
foo()

foo('bar')

var foo = (1 + 2) * 3
(function () { return 'bar'; }())
// Incorrect
foo( 'bar')
foo('bar' )
foo( 'bar' )

var foo = ( 1 + 2 ) * 3
( function () { return 'bar'; }() )

spaced-comment

// Correct
/* eslint spaced-comment: ["error", "always"] */

// This is a comment with a whitespace at the beginning

/* This is a comment with a whitespace at the beginning */

/*
 * This is a comment with a whitespace at the beginning
 */

/*
This comment has a newline
*/
// Incorrect
/*eslint spaced-comment: ["error", "always"]*/

//This is a comment with no whitespace at the beginning

/*This is a comment with no whitespace at the beginning */

template-curly-spacing

// Correct
`hello, ${people.name}!`

`hello, ${
    people.name
}!`
// Incorrect
`hello, ${ people.name}!`
`hello, ${people.name }!`

`hello, ${ people.name }!`

vars-on-top

// Correct
function doSomething() {
    var first
    var second //multiple declarations are allowed at the top
    if (true) {
        first = true
    }
}

function doSomething() {
    var i
    for (i=0; i<10; i++) {}
}
// Incorrect
// Variable declarations in a block:
function doSomething() {
    var first
    if (true) {
        first = true
    }
    var second
}

// Variable declaration in for initializer:
function doSomething() {
    for (var i=0; i<10; i++) {}
}

yoda

// Correct
if (5 & value) {
    // ...
}

if (value === "red") {
    // ...
}

if (x < -1 || 9 < x) {
}

if (x !== 'foo' && 'bar' !== x) {
}
// Incorrect
if ("red" === color) {
    // ...
}

if (true == flag) {
    // ...
}

if (5 > count) {
    // ...
}

if (-1 < str.indexOf(substr)) {
    // ...
}

if (0 <= x && x < 1) {
    // ...
}

Readme

Keywords

Package Sidebar

Install

npm i eslint-config-ableat

Weekly Downloads

1

Version

1.1.0

License

SEE LICENSE IN LICENSE.txt

Unpacked Size

34.5 kB

Total Files

9

Last publish

Collaborators

  • binarybeard