eslint-config-jhh
Version:
JHH ESLint config
288 lines (231 loc) • 9.12 kB
JavaScript
/**
* These rules relate to style guidelines, and are therefore quite subjective.
* As such, these will mostly warn as they are like, my opinion man.
*
* @see http://eslint.org/docs/rules/#stylistic-issues
*/
const tabWidth = 4
const depth = 4
const codeLength = 80
const maxStatements = 10
const chainDepth = 4
module.exports = {
rules: {
// enforce consistent spacing inside array brackets
'array-bracket-spacing': ['warn', 'never'],
// enforce consistent spacing inside single-line blocks
'block-spacing': ['warn', 'always'],
// enforce consistent brace style for blocks
'brace-style': ['warn', '1tbs', {
allowSingleLine: true
}],
// enforce camelcase naming convention
// This ain't Python
camelcase: ['warn', {
properties: 'never' // `foo.some_prop` is ok since that could very
// well be given to us by a server.
}],
// require or disallow trailing commas
'comma-dangle': 'warn',
// enforce consistent spacing before and after commas
'comma-spacing': ['warn', {
before: false,
after: true
}],
// enforce consistent comma style
'comma-style': ['warn', 'last'],
// enforce consistent spacing inside computed property brackets
'computed-property-spacing': ['warn', 'never'],
// require or disallow newline at the end of files
'eol-last': ['warn', 'always'],
// require or disallow spacing between function identifiers and their
// invocations
'func-call-spacing': ['warn', 'never'],
// require function names to match the name of the variable or property
// to which they are assigned
'func-name-matching': ['warn', 'always', {
includeCommonJSModuleExports: false
}],
// require or disallow named function expressions
'func-names': 'warn',
// enforce the consistent use of either function declarations or
// expressions
// Because of hoisting which we are trying to prevent anyway.
'func-style': ['warn', 'expression', {
allowArrowFunctions: true
}],
// enforce consistent indentation
indent: ['warn', tabWidth, {
FunctionDeclaration: {
parameters: 1,
body: 1
},
FunctionExpression: {
parameters: 1,
body: 1
},
SwitchCase: 1,
VariableDeclarator: 1
}],
// enforce the consistent use of either double or single quotes in
// JSX attributes
'jsx-quotes': ['warn', 'prefer-double'],
// enforce consistent spacing between keys and values in object
// literal properties
'key-spacing': ['warn', {
beforeColon: false,
afterColon: true
}],
// enforce consistent spacing before and after keywords
'keyword-spacing': ['warn', {
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true }
}
}],
// enforce consistent linebreak style
'linebreak-style': ['warn', 'unix'],
// require or disallow newlines around directives
'lines-around-directive': ['warn', {
before: 'always',
after: 'always'
}],
// enforce a maximum depth that blocks can be nested
'max-depth': ['warn', depth],
// enforce a maximum line length
'max-len': ['warn', codeLength, tabWidth, {
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true
}],
// enforce a maximum number of lines per file
'max-lines': ['warn', {
max: 300,
skipBlankLines: true,
skipComments: true
}],
// enforce a maximum number of statements allowed per line
'max-statements-per-line': ['warn', {
max: 1
}],
// enforce a maximum number of statements allowed in function blocks
'max-statements': ['warn', maxStatements],
// require constructor names to begin with a capital letter
// @todo might need to investigate impact with react
'new-cap': ['error', {
capIsNew: false,
capIsNewExceptions: [],
newIsCap: true,
newIsCapExceptions: []
}],
// require parentheses when invoking a constructor with no arguments
'new-parens': 'error',
// require a newline after each call in a method chain
'newline-per-chained-call': ['warn', {
ignoreChainWithDepth: chainDepth
}],
// disallow Array constructors
'no-array-constructor': 'error',
// disallow continue statements
'no-continue': 'error',
// disallow if statements as the only statement in else blocks
'no-lonely-if': 'warn',
// disallow mixed binary operators
'no-mixed-operators': ['error', {
groups: [
['+', '-', '*', '/', '%', '**'],
['&', '|', '^', '~', '<<', '>>', '>>>'],
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||'],
['in', 'instanceof']
],
allowSamePrecedence: false
}],
// disallow mixed spaces and tabs for indentation
// Go home, you're drunk.
'no-mixed-spaces-and-tabs': 'warn',
// disallow multiple empty lines
'no-multiple-empty-lines': ['warn', {
max: 2,
maxEOF: 1
}],
// disallow nested ternary expressions
'no-nested-ternary': 'warn',
// disallow Object constructors
'no-new-object': 'error',
// disallow the unary operators ++ and --
// Because whitespace can change the meaning and screw things up
'no-plusplus': 'error',
// disallow all tabs
// Literally Hitler
'no-tabs': 'warn',
// disallow trailing whitespace at the end of lines
// To avoid whitespace causes unnecessary diffs from people playing code
// janitor and altering unneeded whitespace.
'no-trailing-spaces': ['warn'],
// disallow ternary operators when simpler alternatives exist
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
// disallow whitespace before properties
'no-whitespace-before-property': 'warn',
// enforce consistent spacing inside braces
'object-curly-spacing': ['warn', 'always'],
// enforce placing object properties on separate lines
'object-property-newline': ['warn', {
allowMultiplePropertiesPerLine: true
}],
// require or disallow newlines around variable declarations
'one-var-declaration-per-line': ['warn', 'always'],
// equire or disallow assignment operator shorthand where possible
'operator-assignment': ['warn', 'always'],
// require or disallow padding within blocks
'padded-blocks': ['warn', 'never'],
// require quotes around object literal property names
'quote-props': ['warn', 'as-needed', {
keywords: false,
numbers: false,
unnecessary: true
}],
// enforce the consistent use of either backticks, double, or
// single quotes
// @todo Check that this doesnt class with React using double quotes
quotes: ['warn', 'single', {
avoidEscape: true
}],
// enforce consistent spacing before and after semicolons
'semi-spacing': ['warn', {
before: false,
after: true
}],
// enforce consistent spacing before blocks
'space-before-blocks': 'warn',
// enforce consistent spacing before function definition opening
// parenthesis
'space-before-function-paren': ['warn', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always'
}],
// enforce consistent spacing inside parentheses
'space-in-parens': ['warn', 'never'],
// require spacing around infix operators
'space-infix-ops': 'warn',
// enforce consistent spacing before or after unary operators
'space-unary-ops': ['warn', {
nonwords: false,
words: true
}],
// enforce consistent spacing after the // or /* in a comment
'spaced-comment': ['warn', 'always', {
block: {
balanced: true
}
}],
// require or disallow Unicode byte order mark (BOM)
'unicode-bom': ['error', 'never']
}
}