Skip to content

Commit

Permalink
feat: Updates various rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexseitsinger committed Jun 12, 2019
1 parent eef14e3 commit 3eb3940
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 99 deletions.
100 changes: 81 additions & 19 deletions rules/base/lib/best-practices.js
Expand Up @@ -163,14 +163,18 @@ module.exports = {
/**
* Disallow empty functions.
*
* NOTES:
* - We sometimes use empty functions for defaultProps in react. As a
* result, allow functions and methods to be empty.
*
* https://eslint.org/docs/rules/no-empty-function
*/
"no-empty-function": ["error", {
"allow": [
//"functions",
//"arrowFunctions",
"functions",
"arrowFunctions",
//"generatorFunctions",
//"methods",
"methods",
//"generatorMethods",
//"getters",
//"setters",
Expand Down Expand Up @@ -291,9 +295,13 @@ module.exports = {
/**
* Disallow this keywords outside of classes or class-like objects.
*
* NOTES:
* - We use 'this' for references the global scope when we use IIFE's, etc.
* As a result, disable this rule.
*
* https://eslint.org/docs/rules/no-invalid-this
*/
"no-invalid-this": "error",
"no-invalid-this": "off",

/**
* Disallow the use of the __iterator__ property.
Expand Down Expand Up @@ -406,8 +414,18 @@ module.exports = {
* https://eslint.org/docs/rules/no-param-reassign
*/
"no-param-reassign": ["error", {
"props": true, // Default: false
"ignorePropertyModificationsFor": [],
"props": true,
"ignorePropertyModificationsFor": [
"acc", // for reduce accumulators
"accumulator", // for reduce accumulators
"e", // for e.returnvalue
"event", // for event.returnvalue
"req", // for Express requests
"request", // for Express requests
"res", // for Express responses
"response", // for Express responses
"staticContext", // for ReactRouter context
],
}],

/**
Expand All @@ -432,15 +450,49 @@ module.exports = {
* https://eslint.org/docs/rules/no-restricted-properties
*/
"no-restricted-properties": ["error", {
"object": "",
"property": "",
"message": "",
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
}, {
object: 'global',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'self',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'window',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
}, {
object: 'global',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
object: 'self',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
object: 'window',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
}, {
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
}, {
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
}, {
object: 'Math',
property: 'pow',
message: 'Use the exponentiation operator (**) instead.',
}],

/**
* Disallow assignment operators in return statements.
*
* https://eslint.org/docs/rules/no-return-assign<Paste>
* https://eslint.org/docs/rules/no-return-assign
*/
"no-return-assign": ["error", "always"],

Expand Down Expand Up @@ -501,8 +553,8 @@ module.exports = {
* https://eslint.org/docs/rules/no-unused-expressions
*/
"no-unused-expressions": ["error", {
"allowShortCircuit": true,
"allowTernary": true,
"allowShortCircuit": false,
"allowTernary": false,
"allowTaggedTemplates": false
}],

Expand All @@ -518,9 +570,13 @@ module.exports = {
/**
* Disallow unnecessary calls to .call() and .apply().
*
* NOTES:
* - Sometimes, .call() and .apply() are used to invoke a function with a
* specific context/arguments. As a result, disable this rule.
*
* https://eslint.org/docs/rules/no-useless-call
*/
"no-useless-call": "error",
"no-useless-call": "off",

/**
* Disallow unnecessary catch clauses,
Expand Down Expand Up @@ -548,7 +604,7 @@ module.exports = {
*
* (fixable)
*
* https://eslint.org/docs/rules/no-useless-return<Paste>
* https://eslint.org/docs/rules/no-useless-return
*/
"no-useless-return": "error",

Expand Down Expand Up @@ -579,9 +635,12 @@ module.exports = {
/**
* Enforce using named capture group in regular expression.
*
* https://eslint.org/docs/rules/prefer-named-capture-group<Paste>
* NOTES:
* - This is only available in newer ecmascript version.
*
* https://eslint.org/docs/rules/prefer-named-capture-group
*/
"prefer-named-capture-group": "warn", // only available in newer envs.
"prefer-named-capture-group": "off",

/**
* Require using Error objects as Promise rejection reasons.
Expand All @@ -600,14 +659,17 @@ module.exports = {
/**
* Disallow async functions which have no await expression.
*
* NOTES:
* - Disabled this according to AirBNB eslint.
*
* https://eslint.org/docs/rules/require-await
*/
"require-await": "error",
"require-await": "off",

/**
* Enforce the use of u flag on RegExp.
*
* https://eslint.org/docs/rules/require-unicode-regexp<Paste>
* https://eslint.org/docs/rules/require-unicode-regexp
*/
"require-unicode-regexp": "off",

Expand All @@ -616,7 +678,7 @@ module.exports = {
*
* https://eslint.org/docs/rules/vars-on-top
*/
"vars-on-top": "warn",
"vars-on-top": "error",

/**
* Require parentheses around immediate function invocations.
Expand Down
20 changes: 15 additions & 5 deletions rules/base/lib/errors.js
Expand Up @@ -119,14 +119,18 @@ module.exports = {
"no-ex-assign": "error",

/**
* Disallow unnecessary boolean casts. (fixable)
* Disallow unnecessary boolean casts.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-extra-boolean-cast
*/
"no-extra-boolean-cast": "error",

/**
* Disallow unnecessary parentheses. (fixable)
* Disallow unnecessary parentheses.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-extra-parens
*/
Expand All @@ -139,7 +143,9 @@ module.exports = {
}],

/**
* Disallow unnecessary semicolons. (fixable)
* Disallow unnecessary semicolons.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-extra-semi
*/
Expand Down Expand Up @@ -202,7 +208,9 @@ module.exports = {
"no-prototype-builtins": "error",

/**
* Disallow multiple spaces in regular expressions. (fixable)
* Disallow multiple spaces in regular expressions.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-regex-spaces
*/
Expand Down Expand Up @@ -244,7 +252,9 @@ module.exports = {
"no-unsafe-finally": "error",

/**
* Disallow negating the left operand of relational operators. (fixable)
* Disallow negating the left operand of relational operators.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-unsafe-negation
*/
Expand Down
48 changes: 37 additions & 11 deletions rules/base/lib/es6.js
@@ -1,14 +1,18 @@
module.exports = {
rules: {
/**
* Require braces around arrow function bodies. (fixable)
* Require braces around arrow function bodies.
*
* (fixable)
*
* https://eslint.org/docs/rules/arrow-body-style
*/
"arrow-body-style": ["error", "as-needed"],

/**
* Require parentheses around arrow function arguments. (fixable)
* Require parentheses around arrow function arguments.
*
* (fixable)
*
* https://eslint.org/docs/rules/arrow-parens
*/
Expand All @@ -18,6 +22,7 @@ module.exports = {

/**
* Enforce consistent spacing before and after the arrow in arrow functions.
*
* (fixable)
*
* https://eslint.org/docs/rules/arrow-spacing
Expand All @@ -36,6 +41,7 @@ module.exports = {

/**
* Enforce consistent spacing around * operators in generator functions.
*
* (fixable)
*
* https://eslint.org/docs/rules/generator-star-spacing
Expand All @@ -54,6 +60,7 @@ module.exports = {

/**
* Disallow arrow functions where they could be confused with comparisons.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-confusing-arrow
Expand Down Expand Up @@ -110,7 +117,9 @@ module.exports = {
"no-this-before-super": "error",

/**
* Disallow unnecessary computed property keys in object literals. (fixable)
* Disallow unnecessary computed property keys in object literals.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-useless-computed-key
*/
Expand All @@ -125,7 +134,9 @@ module.exports = {

/**
* Disallow renaming import, export, and destructured assignments to the
* same name. (fixable)
* same name.
*
* (fixable)
*
* https://eslint.org/docs/rules/no-useless-rename
*/
Expand All @@ -144,7 +155,9 @@ module.exports = {

/**
* Require or disallow method and property shorthand syntax for object
* literals. (fixable)
* literals.
*
* (fixable)
*
* https://eslint.org/docs/rules/object-shorthand
*/
Expand All @@ -162,7 +175,9 @@ module.exports = {

/**
* Require const declarations for variables that are never reassigned after
* declared. (fixable)
* declared.
*
* (fixable)
*
* https://eslint.org/docs/rules/prefer-const
*/
Expand Down Expand Up @@ -191,7 +206,9 @@ module.exports = {

/**
* Disallow parseInt() and Number.parseInt() in favor of binary, octal, and
* hexadecimal literals. (fixable)
* hexadecimal literals.
*
* (fixable)
*
* https://eslint.org/docs/rules/prefer-numeric-literals
*/
Expand All @@ -212,7 +229,9 @@ module.exports = {
"prefer-spread": "error",

/**
* Require template literals instead of string concatenation. (fixable)
* Require template literals instead of string concatenation.
*
* (fixable)
*
* https://eslint.org/docs/rules/prefer-template
*/
Expand All @@ -227,14 +246,17 @@ module.exports = {

/**
* Enforce spacing between rest and spread operators and their expressions.
*
* (fixable)
*
* https://eslint.org/docs/rules/rest-spread-spacing
*/
"rest-spread-spacing": ["error", "never"],

/**
* Enforce sorted import declarations within modules. (fixable)
* Enforce sorted import declarations within modules.
*
* (fixable)
*
* https://eslint.org/docs/rules/sort-imports
*/
Expand All @@ -254,14 +276,18 @@ module.exports = {

/**
* Require or disallow spacing around embedded expressions of template
* strings. (fixable)
* strings.
*
* (fixable)
*
* https://eslint.org/docs/rules/template-curly-spacing
*/
"template-curly-spacing": ["error", "never"],

/**
* Require or disallow spacing around the * in yield* expressions. (fixable)
* Require or disallow spacing around the * in yield* expressions.
*
* (fixable)
*
* https://eslint.org/docs/rules/yield-star-spacing
*/
Expand Down

0 comments on commit 3eb3940

Please sign in to comment.