diff --git a/.editorconfig b/.editorconfig
index db6f34c77c..3229d321a4 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -2,7 +2,7 @@ root = true
[*]
indent_style = space
-indent_size = 2
+indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
diff --git a/.eslintrc b/.eslintrc
new file mode 100755
index 0000000000..e9455cf570
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,1924 @@
+{
+ "extends": [
+ "eslint:recommended",
+ "plugin:mithril/recommended"
+ ],
+ "env": {
+ "node": true,
+ "browser": true,
+ "es6": true,
+ "jasmine": true
+ },
+ "globals": {
+ "Modernizr": true,
+ "Uint8Array": true,
+ "ga": true,
+ "m": true
+ },
+ "parser": "babel-eslint",
+ "parserOptions": {
+ "ecmaVersion": 6,
+ "ecmaFeatures": {}
+ },
+ "rules": {
+ "mithril/jsx-key": 0,
+ "accessor-pairs": "off",
+ // enforces return statements in callbacks of array"s methods
+ // https://eslint.org/docs/rules/array-callback-return
+ "array-callback-return": [
+ "error",
+ {
+ "allowImplicit": true
+ }
+ ],
+ // treat var statements as if they were block scoped
+ "block-scoped-var": "error",
+ // specify the maximum cyclomatic complexity allowed in a program
+ "complexity": [
+ "off",
+ 11
+ ],
+ // enforce that class methods use "this"
+ // https://eslint.org/docs/rules/class-methods-use-this
+ "class-methods-use-this": [
+ "error",
+ {
+ "exceptMethods": []
+ }
+ ],
+ // require return statements to either always or never specify values
+ "consistent-return": "error",
+ // specify curly brace conventions for all control statements
+ "curly": [
+ "error",
+ "multi-line"
+ ],
+ // multiline
+
+ // require default case in switch statements
+ "default-case": [
+ "error",
+ {
+ "commentPattern": "^no default$"
+ }
+ ],
+ // Enforce default clauses in switch statements to be last
+ // https://eslint.org/docs/rules/default-case-last
+ // TODO: enable, semver-minor, when eslint v7 is required (which is a major)
+ "default-case-last": "off",
+ // https://eslint.org/docs/rules/default-param-last
+ // TODO: enable, semver-minor, when eslint v6.4 is required (which is a major)
+ "default-param-last": "off",
+ // encourages use of dot notation whenever possible
+ "dot-notation": [
+ "error",
+ {
+ "allowKeywords": true
+ }
+ ],
+ // enforces consistent newlines before or after dots
+ // https://eslint.org/docs/rules/dot-location
+ "dot-location": [
+ "error",
+ "property"
+ ],
+ // require the use of === and !==
+ // https://eslint.org/docs/rules/eqeqeq
+ "eqeqeq": [
+ "error",
+ "always",
+ {
+ "null": "ignore"
+ }
+ ],
+ // Require grouped accessor pairs in object literals and classes
+ // https://eslint.org/docs/rules/grouped-accessor-pairs
+ // TODO: enable in next major, altho the guide forbids getters/setters anyways
+ "grouped-accessor-pairs": "off",
+ // make sure for-in loops have an if statement
+ "guard-for-in": "error",
+ // enforce a maximum number of classes per file
+ // https://eslint.org/docs/rules/max-classes-per-file
+ "max-classes-per-file": [
+ "error",
+ 1
+ ],
+ // disallow the use of alert, confirm, and prompt
+ "no-alert": "warn",
+ // disallow use of arguments.caller or arguments.callee
+ "no-caller": "error",
+ // disallow lexical declarations in case/default clauses
+ // https://eslint.org/docs/rules/no-case-declarations.html
+ "no-case-declarations": "error",
+ // Disallow returning value in constructor
+ // https://eslint.org/docs/rules/no-constructor-return
+ // TODO: enable, semver-major
+ "no-constructor-return": "off",
+ // disallow division operators explicitly at beginning of regular expression
+ // https://eslint.org/docs/rules/no-div-regex
+ "no-div-regex": "off",
+ // disallow else after a return in an if
+ // https://eslint.org/docs/rules/no-else-return
+ "no-else-return": [
+ "error",
+ {
+ "allowElseIf": false
+ }
+ ],
+ // disallow empty functions, except for standalone funcs/arrows
+ // https://eslint.org/docs/rules/no-empty-function
+ "no-empty-function": [
+ "error",
+ {
+ "allow": [
+ "arrowFunctions",
+ "functions",
+ "methods"
+ ]
+ }
+ ],
+ // disallow empty destructuring patterns
+ // https://eslint.org/docs/rules/no-empty-pattern
+ "no-empty-pattern": "error",
+ // disallow comparisons to null without a type-checking operator
+ "no-eq-null": "off",
+ // disallow use of eval()
+ "no-eval": "error",
+ // disallow adding to native types
+ "no-extend-native": "error",
+ // disallow unnecessary function binding
+ "no-extra-bind": "error",
+ // disallow Unnecessary Labels
+ // https://eslint.org/docs/rules/no-extra-label
+ "no-extra-label": "error",
+ // disallow fallthrough of case statements
+ "no-fallthrough": "error",
+ // disallow the use of leading or trailing decimal points in numeric literals
+ "no-floating-decimal": "error",
+ // disallow reassignments of native objects or read-only globals
+ // https://eslint.org/docs/rules/no-global-assign
+ "no-global-assign": [
+ "error",
+ {
+ "exceptions": []
+ }
+ ],
+ // deprecated in favor of no-global-assign
+ "no-native-reassign": "off",
+ // disallow implicit type conversions
+ // https://eslint.org/docs/rules/no-implicit-coercion
+ "no-implicit-coercion": [
+ "off",
+ {
+ "boolean": false,
+ "number": true,
+ "string": true,
+ "allow": []
+ }
+ ],
+ // disallow var and named functions in global scope
+ // https://eslint.org/docs/rules/no-implicit-globals
+ "no-implicit-globals": "off",
+ // disallow use of eval()-like methods
+ "no-implied-eval": "error",
+ // disallow this keywords outside of classes or class-like objects
+ "no-invalid-this": "off",
+ // disallow usage of __iterator__ property
+ "no-iterator": "error",
+ // disallow use of labels for anything other then loops and switches
+ "no-labels": [
+ "error",
+ {
+ "allowLoop": false,
+ "allowSwitch": false
+ }
+ ],
+ // disallow unnecessary nested blocks
+ "no-lone-blocks": "error",
+ // disallow creation of functions within loops
+ "no-loop-func": "error",
+ // disallow magic numbers
+ // https://eslint.org/docs/rules/no-magic-numbers
+ "no-magic-numbers": [
+ "off",
+ {
+ "ignore": [],
+ "ignoreArrayIndexes": true,
+ "enforceConst": true,
+ "detectObjects": false
+ }
+ ],
+ // disallow use of multiple spaces
+ "no-multi-spaces": [
+ "error",
+ {
+ "ignoreEOLComments": false
+ }
+ ],
+ // disallow use of multiline strings
+ "no-multi-str": "error",
+ // disallow use of new operator when not part of the assignment or comparison
+ "no-new": "error",
+ // disallow use of new operator for Function object
+ "no-new-func": "error",
+ // disallows creating new instances of String, Number, and Boolean
+ "no-new-wrappers": "error",
+ // disallow use of (old style) octal literals
+ "no-octal": "error",
+ // disallow use of octal escape sequences in string literals, such as
+ // var foo = "Copyright \251";
+ "no-octal-escape": "error",
+ // disallow reassignment of function parameters
+ // disallow parameter object manipulation except for specific exclusions
+ // rule: https://eslint.org/docs/rules/no-param-reassign.html
+ "no-param-reassign": [
+ "error",
+ {
+ "props": true,
+ "ignorePropertyModificationsFor": [
+ "acc",
+ // for reduce accumulators
+ "accumulator",
+ // for reduce accumulators
+ "e",
+ // for e.returnvalue
+ "ctx",
+ // for Koa routing
+ "context",
+ // for Koa routing
+ "req",
+ // for Express requests
+ "request",
+ // for Express requests
+ "res",
+ // for Express responses
+ "response",
+ // for Express responses
+ "$scope",
+ // for Angular 1 scopes
+ "staticContext"
+ // for ReactRouter context
+ ]
+ }
+ ],
+ // disallow usage of __proto__ property
+ "no-proto": "error",
+ // disallow declaring the same variable more then once
+ "no-redeclare": "error",
+ // disallow certain object properties
+ // https://eslint.org/docs/rules/no-restricted-properties
+ "no-restricted-properties": [
+ "error",
+ {
+ "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 use of assignment in return statement
+ "no-return-assign": [
+ "error",
+ "always"
+ ],
+ // disallow redundant `return await`
+ "no-return-await": "error",
+ // disallow use of `javascript:` urls.
+ "no-script-url": "error",
+ // disallow self assignment
+ // https://eslint.org/docs/rules/no-self-assign
+ "no-self-assign": [
+ "error",
+ {
+ "props": true
+ }
+ ],
+ // disallow comparisons where both sides are exactly the same
+ "no-self-compare": "error",
+ // disallow use of comma operator
+ "no-sequences": "error",
+ // restrict what can be thrown as an exception
+ "no-throw-literal": "error",
+ // disallow unmodified conditions of loops
+ // https://eslint.org/docs/rules/no-unmodified-loop-condition
+ "no-unmodified-loop-condition": "off",
+ // disallow usage of expressions in statement position
+ "no-unused-expressions": [
+ "error",
+ {
+ "allowShortCircuit": false,
+ "allowTernary": false,
+ "allowTaggedTemplates": false
+ }
+ ],
+ // disallow unused labels
+ // https://eslint.org/docs/rules/no-unused-labels
+ "no-unused-labels": "error",
+ // disallow unnecessary .call() and .apply()
+ "no-useless-call": "off",
+ // Disallow unnecessary catch clauses
+ // https://eslint.org/docs/rules/no-useless-catch
+ "no-useless-catch": "error",
+ // disallow useless string concatenation
+ // https://eslint.org/docs/rules/no-useless-concat
+ "no-useless-concat": "error",
+ // disallow unnecessary string escaping
+ // https://eslint.org/docs/rules/no-useless-escape
+ "no-useless-escape": "error",
+ // disallow redundant return; keywords
+ // https://eslint.org/docs/rules/no-useless-return
+ "no-useless-return": "error",
+ // disallow use of void operator
+ // https://eslint.org/docs/rules/no-void
+ "no-void": "error",
+ // disallow usage of configurable warning terms in comments: e.g. todo
+ "no-warning-comments": [
+ "off",
+ {
+ "terms": [
+ "todo",
+ "fixme",
+ "xxx"
+ ],
+ "location": "start"
+ }
+ ],
+ // disallow use of the with statement
+ "no-with": "error",
+ // require using Error objects as Promise rejection reasons
+ // https://eslint.org/docs/rules/prefer-promise-reject-errors
+ "prefer-promise-reject-errors": [
+ "error",
+ {
+ "allowEmptyReject": true
+ }
+ ],
+ // Suggest using named capture group in regular expression
+ // https://eslint.org/docs/rules/prefer-named-capture-group
+ "prefer-named-capture-group": "off",
+ // https://eslint.org/docs/rules/prefer-regex-literals
+ // TODO; enable, semver-minor, once eslint v6.4 is required (which is a major)
+ "prefer-regex-literals": "off",
+ // require use of the second argument for parseInt()
+ "radix": "error",
+ // require `await` in `async function` (note: this is a horrible rule that should never be used)
+ // https://eslint.org/docs/rules/require-await
+ "require-await": "off",
+ // Enforce the use of u flag on RegExp
+ // https://eslint.org/docs/rules/require-unicode-regexp
+ "require-unicode-regexp": "off",
+ // requires to declare all vars on top of their containing scope
+ "vars-on-top": "error",
+ // require immediate function invocation to be wrapped in parentheses
+ // https://eslint.org/docs/rules/wrap-iife.html
+ "wrap-iife": [
+ "error",
+ "outside",
+ {
+ "functionPrototypeMethods": false
+ }
+ ],
+ // require or disallow Yoda conditions
+ "yoda": "error",
+ // Enforce “for” loop update clause moving the counter in the right direction
+ // https://eslint.org/docs/rules/for-direction
+ "for-direction": "error",
+ // Enforces that a return statement is present in property getters
+ // https://eslint.org/docs/rules/getter-return
+ "getter-return": [
+ "error",
+ {
+ "allowImplicit": true
+ }
+ ],
+ // disallow using an async function as a Promise executor
+ // https://eslint.org/docs/rules/no-async-promise-executor
+ "no-async-promise-executor": "error",
+ // Disallow await inside of loops
+ // https://eslint.org/docs/rules/no-await-in-loop
+ "no-await-in-loop": "error",
+ // Disallow comparisons to negative zero
+ // https://eslint.org/docs/rules/no-compare-neg-zero
+ "no-compare-neg-zero": "error",
+ // disallow assignment in conditional expressions
+ "no-cond-assign": [
+ "error",
+ "always"
+ ],
+ // disallow use of console
+ "no-console": "warn",
+ // disallow use of constant expressions in conditions
+ "no-constant-condition": "warn",
+ // disallow control characters in regular expressions
+ "no-control-regex": "error",
+ // disallow use of debugger
+ "no-debugger": "error",
+ // disallow duplicate arguments in functions
+ "no-dupe-args": "error",
+ // Disallow duplicate conditions in if-else-if chains
+ // https://eslint.org/docs/rules/no-dupe-else-if
+ // TODO: enable, semver-major
+ "no-dupe-else-if": "off",
+ // disallow duplicate keys when creating object literals
+ "no-dupe-keys": "error",
+ // disallow a duplicate case label.
+ "no-duplicate-case": "error",
+ // disallow empty statements
+ "no-empty": "error",
+ // disallow the use of empty character classes in regular expressions
+ "no-empty-character-class": "error",
+ // disallow assigning to the exception in a catch block
+ "no-ex-assign": "error",
+ // disallow double-negation boolean casts in a boolean context
+ // https://eslint.org/docs/rules/no-extra-boolean-cast
+ "no-extra-boolean-cast": "error",
+ // disallow unnecessary parentheses
+ // https://eslint.org/docs/rules/no-extra-parens
+ "no-extra-parens": [
+ "off",
+ "all",
+ {
+ "conditionalAssign": true,
+ "nestedBinaryExpressions": false,
+ "returnAssign": false,
+ "ignoreJSX": "all",
+ // delegate to eslint-plugin-react
+ "enforceForArrowConditionals": false
+ }
+ ],
+ // disallow unnecessary semicolons
+ "no-extra-semi": "error",
+ // disallow overwriting functions written as function declarations
+ "no-func-assign": "error",
+ // https://eslint.org/docs/rules/no-import-assign
+ // TODO: enable, semver-minor, once eslint v6.4 is required (which is a major)
+ "no-import-assign": "off",
+ // disallow function or variable declarations in nested blocks
+ "no-inner-declarations": "error",
+ // disallow invalid regular expression strings in the RegExp constructor
+ "no-invalid-regexp": "error",
+ // disallow irregular whitespace outside of strings and comments
+ "no-irregular-whitespace": "error",
+ // Disallow Number Literals That Lose Precision
+ // https://eslint.org/docs/rules/no-loss-of-precision
+ // TODO: enable, semver-minor, once eslint v7.1 is required (which is major)
+ "no-loss-of-precision": "off",
+ // Disallow characters which are made with multiple code points in character class syntax
+ // https://eslint.org/docs/rules/no-misleading-character-class
+ "no-misleading-character-class": "error",
+ // disallow the use of object properties of the global object (Math and JSON) as functions
+ "no-obj-calls": "error",
+ // disallow use of Object.prototypes builtins directly
+ // https://eslint.org/docs/rules/no-prototype-builtins
+ "no-prototype-builtins": "error",
+ // disallow multiple spaces in a regular expression literal
+ "no-regex-spaces": "error",
+ // Disallow returning values from setters
+ // https://eslint.org/docs/rules/no-setter-return
+ // TODO: enable, semver-major (altho the guide forbids getters/setters already)
+ "no-setter-return": "off",
+ // disallow sparse arrays
+ "no-sparse-arrays": "error",
+ // Disallow template literal placeholder syntax in regular strings
+ // https://eslint.org/docs/rules/no-template-curly-in-string
+ "no-template-curly-in-string": "error",
+ // Avoid code that looks like two expressions but is actually one
+ // https://eslint.org/docs/rules/no-unexpected-multiline
+ "no-unexpected-multiline": "error",
+ // disallow unreachable statements after a return, throw, continue, or break statement
+ "no-unreachable": "error",
+ // disallow return/throw/break/continue inside finally blocks
+ // https://eslint.org/docs/rules/no-unsafe-finally
+ "no-unsafe-finally": "error",
+ // disallow negating the left operand of relational operators
+ // https://eslint.org/docs/rules/no-unsafe-negation
+ "no-unsafe-negation": "error",
+ // Disallow useless backreferences in regular expressions
+ // https://eslint.org/docs/rules/no-useless-backreference
+ // TODO: enable, semver-minor, once eslint v7 is required (which is major)
+ "no-useless-backreference": "off",
+ // disallow negation of the left operand of an in expression
+ // deprecated in favor of no-unsafe-negation
+ "no-negated-in-lhs": "off",
+ // Disallow assignments that can lead to race conditions due to usage of await or yield
+ // https://eslint.org/docs/rules/require-atomic-updates
+ // note: not enabled because it is very buggy
+ "require-atomic-updates": "off",
+ // disallow comparisons with the value NaN
+ "use-isnan": "error",
+ // ensure JSDoc comments are valid
+ // https://eslint.org/docs/rules/valid-jsdoc
+ "valid-jsdoc": "off",
+ // ensure that the results of typeof are compared against a valid string
+ // https://eslint.org/docs/rules/valid-typeof
+ "valid-typeof": [
+ "error",
+ {
+ "requireStringLiterals": true
+ }
+ ],
+ // enforces no braces where they can be omitted
+ // https://eslint.org/docs/rules/arrow-body-style
+ // TODO: enable requireReturnForObjectLiteral?
+ "arrow-body-style": [
+ "error",
+ "as-needed",
+ {
+ "requireReturnForObjectLiteral": false
+ }
+ ],
+ // require parens in arrow function arguments
+ // https://eslint.org/docs/rules/arrow-parens
+ "arrow-parens": [
+ "error",
+ "as-needed"
+ ],
+ // require space before/after arrow function"s arrow
+ // https://eslint.org/docs/rules/arrow-spacing
+ "arrow-spacing": [
+ "error",
+ {
+ "before": true,
+ "after": true
+ }
+ ],
+ // verify super() callings in constructors
+ "constructor-super": "error",
+ // enforce the spacing around the * in generator functions
+ // https://eslint.org/docs/rules/generator-star-spacing
+ "generator-star-spacing": [
+ "error",
+ {
+ "before": false,
+ "after": true
+ }
+ ],
+ // disallow modifying variables of class declarations
+ // https://eslint.org/docs/rules/no-class-assign
+ "no-class-assign": "error",
+ // disallow arrow functions where they could be confused with comparisons
+ // https://eslint.org/docs/rules/no-confusing-arrow
+ "no-confusing-arrow": [
+ "error",
+ {
+ "allowParens": true
+ }
+ ],
+ // disallow modifying variables that are declared using const
+ "no-const-assign": "error",
+ // disallow duplicate class members
+ // https://eslint.org/docs/rules/no-dupe-class-members
+ "no-dupe-class-members": "error",
+ // disallow importing from the same path more than once
+ // https://eslint.org/docs/rules/no-duplicate-imports
+ // replaced by https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
+ "no-duplicate-imports": "off",
+ // disallow symbol constructor
+ // https://eslint.org/docs/rules/no-new-symbol
+ "no-new-symbol": "error",
+ // Disallow specified names in exports
+ // https://eslint.org/docs/rules/no-restricted-exports
+ // TODO enable, semver-minor, once eslint v7 is required (which is major)
+ "no-restricted-exports": [
+ "off",
+ {
+ "restrictedNamedExports": [
+ "default",
+ // use `export default` to provide a default export
+ "then"
+ // this will cause tons of confusion when your module is dynamically `import()`ed
+ ]
+ }
+ ],
+ // disallow specific imports
+ // https://eslint.org/docs/rules/no-restricted-imports
+ "no-restricted-imports": [
+ "off",
+ {
+ "paths": [],
+ "patterns": []
+ }
+ ],
+ // disallow to use this/super before super() calling in constructors.
+ // https://eslint.org/docs/rules/no-this-before-super
+ "no-this-before-super": "error",
+ // disallow useless computed property keys
+ // https://eslint.org/docs/rules/no-useless-computed-key
+ "no-useless-computed-key": "error",
+ // disallow unnecessary constructor
+ // https://eslint.org/docs/rules/no-useless-constructor
+ "no-useless-constructor": "error",
+ // disallow renaming import, export, and destructured assignments to the same name
+ // https://eslint.org/docs/rules/no-useless-rename
+ "no-useless-rename": [
+ "error",
+ {
+ "ignoreDestructuring": false,
+ "ignoreImport": false,
+ "ignoreExport": false
+ }
+ ],
+ // require let or const instead of var
+ "no-var": "error",
+ // require method and property shorthand syntax for object literals
+ // https://eslint.org/docs/rules/object-shorthand
+ "object-shorthand": [
+ "error",
+ "always",
+ {
+ "ignoreConstructors": false,
+ "avoidQuotes": true
+ }
+ ],
+ // suggest using arrow functions as callbacks
+ "prefer-arrow-callback": [
+ "error",
+ {
+ "allowNamedFunctions": false,
+ "allowUnboundThis": true
+ }
+ ],
+ // suggest using of const declaration for variables that are never modified after declared
+ "prefer-const": [
+ "error",
+ {
+ "destructuring": "any",
+ "ignoreReadBeforeAssign": true
+ }
+ ],
+ // Prefer destructuring from arrays and objects
+ // https://eslint.org/docs/rules/prefer-destructuring
+ "prefer-destructuring": [
+ "error",
+ {
+ "VariableDeclarator": {
+ "array": false,
+ "object": true
+ },
+ "AssignmentExpression": {
+ "array": true,
+ "object": false
+ }
+ },
+ {
+ "enforceForRenamedProperties": false
+ }
+ ],
+ // disallow parseInt() in favor of binary, octal, and hexadecimal literals
+ // https://eslint.org/docs/rules/prefer-numeric-literals
+ "prefer-numeric-literals": "error",
+ // suggest using Reflect methods where applicable
+ // https://eslint.org/docs/rules/prefer-reflect
+ "prefer-reflect": "off",
+ // use rest parameters instead of arguments
+ // https://eslint.org/docs/rules/prefer-rest-params
+ "prefer-rest-params": "error",
+ // suggest using the spread operator instead of .apply()
+ // https://eslint.org/docs/rules/prefer-spread
+ "prefer-spread": "error",
+ // suggest using template literals instead of string concatenation
+ // https://eslint.org/docs/rules/prefer-template
+ "prefer-template": "error",
+ // disallow generator functions that do not have yield
+ // https://eslint.org/docs/rules/require-yield
+ "require-yield": "error",
+ // enforce spacing between object rest-spread
+ // https://eslint.org/docs/rules/rest-spread-spacing
+ "rest-spread-spacing": [
+ "error",
+ "never"
+ ],
+ // import sorting
+ // https://eslint.org/docs/rules/sort-imports
+ "sort-imports": [
+ "off",
+ {
+ "ignoreCase": false,
+ "ignoreDeclarationSort": false,
+ "ignoreMemberSort": false,
+ "memberSyntaxSortOrder": [
+ "none",
+ "all",
+ "multiple",
+ "single"
+ ]
+ }
+ ],
+ // require a Symbol description
+ // https://eslint.org/docs/rules/symbol-description
+ "symbol-description": "error",
+ // enforce usage of spacing in template strings
+ // https://eslint.org/docs/rules/template-curly-spacing
+ "template-curly-spacing": "error",
+ // enforce spacing around the * in yield* expressions
+ // https://eslint.org/docs/rules/yield-star-spacing
+ "yield-star-spacing": [
+ "error",
+ "after"
+ ],
+ // Static analysis:
+
+ // ensure imports point to files/modules that can be resolved
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
+ "import/no-unresolved": [
+ "error",
+ {
+ "commonjs": true,
+ "caseSensitive": true
+ }
+ ],
+ // ensure named imports coupled with named exports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
+ "import/named": "error",
+ // ensure default import coupled with default export
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
+ "import/default": "off",
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/namespace.md
+ "import/namespace": "off",
+ // Helpful warnings:
+
+ // disallow invalid exports, e.g. multiple defaults
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
+ "import/export": "error",
+ // do not allow a default import name to match a named export
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
+ "import/no-named-as-default": "error",
+ // warn on accessing default export property names that are also named exports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
+ "import/no-named-as-default-member": "error",
+ // disallow use of jsdoc-marked-deprecated imports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
+ "import/no-deprecated": "off",
+ // Forbid the use of extraneous packages
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
+ // paths are treated both as absolute paths, and relative to process.cwd()
+ "import/no-extraneous-dependencies": [
+ "error",
+ {
+ "devDependencies": [
+ "test/**",
+ // tape, common npm pattern
+ "tests/**",
+ // also common npm pattern
+ "spec/**",
+ // mocha, rspec-like pattern
+ "**/__tests__/**",
+ // jest pattern
+ "**/__mocks__/**",
+ // jest pattern
+ "test.{js,jsx}",
+ // repos with a single test file
+ "test-*.{js,jsx}",
+ // repos with multiple top-level test files
+ "**/*{.,_}{test,spec}.{js,jsx}",
+ // tests where the extension or filename suffix denotes that it is a test
+ "**/jest.config.js",
+ // jest config
+ "**/jest.setup.js",
+ // jest setup
+ "**/vue.config.js",
+ // vue-cli config
+ "**/webpack.config.js",
+ // webpack config
+ "**/webpack.config.*.js",
+ // webpack config
+ "**/rollup.config.js",
+ // rollup config
+ "**/rollup.config.*.js",
+ // rollup config
+ "**/gulpfile.js",
+ // gulp config
+ "**/gulpfile.*.js",
+ // gulp config
+ "**/Gruntfile{,.js}",
+ // grunt config
+ "**/protractor.conf.js",
+ // protractor config
+ "**/protractor.conf.*.js",
+ // protractor config
+ "**/karma.conf.js"
+ // karma config
+ ],
+ "optionalDependencies": false
+ }
+ ],
+ // Forbid mutable exports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
+ "import/no-mutable-exports": "error",
+ // Module systems:
+
+ // disallow require()
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
+ "import/no-commonjs": "off",
+ // disallow AMD require/define
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-amd.md
+ "import/no-amd": "error",
+ // No Node.js builtin modules
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
+ // TODO: enable?
+ "import/no-nodejs-modules": "off",
+ // Style guide:
+
+ // disallow non-import statements appearing before import statements
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md
+ "import/first": "error",
+ // disallow non-import statements appearing before import statements
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
+ // deprecated: use `import/first`
+ "import/imports-first": "off",
+ // disallow duplicate imports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
+ "import/no-duplicates": "error",
+ // disallow namespace imports
+ // TODO: enable?
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
+ "import/no-namespace": "off",
+ // Ensure consistent use of file extension within the import path
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
+ "import/extensions": [
+ "error",
+ "ignorePackages",
+ {
+ "js": "never",
+ "mjs": "never",
+ "jsx": "never"
+ }
+ ],
+ // ensure absolute imports are above relative imports and that unassigned imports are ignored
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
+ // TODO: enforce a stricter convention in module import order?
+ "import/order": [
+ "error",
+ {
+ "groups": [
+ [
+ "builtin",
+ "external",
+ "internal"
+ ]
+ ]
+ }
+ ],
+ // Require a newline after the last import/require in a group
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
+ "import/newline-after-import": "error",
+ // Require modules with a single export to use a default export
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
+ "import/prefer-default-export": "error",
+ // Restrict which files can be imported in a given folder
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
+ "import/no-restricted-paths": "off",
+ // Forbid modules to have too many dependencies
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md
+ "import/max-dependencies": [
+ "off",
+ {
+ "max": 10
+ }
+ ],
+ // Forbid import of modules using absolute paths
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
+ "import/no-absolute-path": "error",
+ // Forbid require() calls with expressions
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
+ "import/no-dynamic-require": "error",
+ // prevent importing the submodules of other modules
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
+ "import/no-internal-modules": [
+ "off",
+ {
+ "allow": []
+ }
+ ],
+ // Warn if a module could be mistakenly parsed as a script by a consumer
+ // leveraging Unambiguous JavaScript Grammar
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/unambiguous.md
+ // this should not be enabled until this proposal has at least been *presented* to TC39.
+ // At the moment, it"s not a thing.
+ "import/unambiguous": "off",
+ // Forbid Webpack loader syntax in imports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
+ "import/no-webpack-loader-syntax": "error",
+ // Prevent unassigned imports
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
+ // importing for side effects is perfectly acceptable, if you need side effects.
+ "import/no-unassigned-import": "off",
+ // Prevent importing the default as if it were named
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
+ "import/no-named-default": "error",
+ // Reports if a module"s default export is unnamed
+ // https://github.com/benmosher/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
+ "import/no-anonymous-default-export": [
+ "off",
+ {
+ "allowArray": false,
+ "allowArrowFunction": false,
+ "allowAnonymousClass": false,
+ "allowAnonymousFunction": false,
+ "allowLiteral": false,
+ "allowObject": false
+ }
+ ],
+ // This rule enforces that all exports are declared at the bottom of the file.
+ // https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
+ // TODO: enable?
+ "import/exports-last": "off",
+ // Reports when named exports are not grouped together in a single export declaration
+ // or when multiple assignments to CommonJS module.exports or exports object are present
+ // in a single file.
+ // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
+ "import/group-exports": "off",
+ // forbid default exports. this is a terrible rule, do not use it.
+ // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
+ "import/no-default-export": "off",
+ // Prohibit named exports. this is a terrible rule, do not use it.
+ // https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
+ "import/no-named-export": "off",
+ // Forbid a module from importing itself
+ // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
+ "import/no-self-import": "error",
+ // Forbid cyclical dependencies between modules
+ // https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
+ "import/no-cycle": [
+ "error",
+ {
+ "maxDepth": "infinity"
+ }
+ ],
+ // Ensures that there are no useless path segments
+ // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
+ "import/no-useless-path-segments": [
+ "error",
+ {
+ "commonjs": true
+ }
+ ],
+ // dynamic imports require a leading comment with a webpackChunkName
+ // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
+ "import/dynamic-import-chunkname": [
+ "off",
+ {
+ "importFunctions": [],
+ "webpackChunknameFormat": "[0-9a-zA-Z-_/.]+"
+ }
+ ],
+ // Use this rule to prevent imports to folders in relative parent paths.
+ // https://github.com/benmosher/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
+ "import/no-relative-parent-imports": "off",
+ // Reports modules without any exports, or with unused exports
+ // https://github.com/benmosher/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
+ // TODO: enable, semver-major
+ "import/no-unused-modules": [
+ "off",
+ {
+ "ignoreExports": [],
+ "missingExports": true,
+ "unusedExports": true
+ }
+ ],
+ // enforce return after a callback
+ "callback-return": "off",
+ // require all requires be top-level
+ // https://eslint.org/docs/rules/global-require
+ "global-require": "error",
+ // enforces error handling in callbacks (node environment)
+ "handle-callback-err": "off",
+ // disallow use of the Buffer() constructor
+ // https://eslint.org/docs/rules/no-buffer-constructor
+ "no-buffer-constructor": "error",
+ // disallow mixing regular variable and require declarations
+ "no-mixed-requires": [
+ "off",
+ false
+ ],
+ // disallow use of new operator with the require function
+ "no-new-require": "error",
+ // disallow string concatenation with __dirname and __filename
+ // https://eslint.org/docs/rules/no-path-concat
+ "no-path-concat": "error",
+ // disallow use of process.env
+ "no-process-env": "off",
+ // disallow process.exit()
+ "no-process-exit": "off",
+ // restrict usage of specified node modules
+ "no-restricted-modules": "off",
+ // disallow use of synchronous methods (off by default)
+ "no-sync": "off",
+ "strict": [
+ "error",
+ "never"
+ ],
+ // enforce line breaks after opening and before closing array brackets
+ // https://eslint.org/docs/rules/array-bracket-newline
+ // TODO: enable? semver-major
+ "array-bracket-newline": [
+ "off",
+ "consistent"
+ ],
+ // object option alternative: { multiline: true, minItems: 3 }
+
+ // enforce line breaks between array elements
+ // https://eslint.org/docs/rules/array-element-newline
+ // TODO: enable? semver-major
+ "array-element-newline": [
+ "off",
+ {
+ "multiline": true,
+ "minItems": 3
+ }
+ ],
+ // enforce spacing inside array brackets
+ "array-bracket-spacing": [
+ "error",
+ "never"
+ ],
+ // enforce spacing inside single-line blocks
+ // https://eslint.org/docs/rules/block-spacing
+ "block-spacing": [
+ "error",
+ "always"
+ ],
+ // enforce one true brace style
+ "brace-style": [
+ "error",
+ "1tbs",
+ {
+ "allowSingleLine": true
+ }
+ ],
+ // require camel case names
+ "camelcase": [
+ "error",
+ {
+ "properties": "never",
+ "ignoreDestructuring": false
+ }
+ ],
+ // enforce or disallow capitalization of the first letter of a comment
+ // https://eslint.org/docs/rules/capitalized-comments
+ "capitalized-comments": [
+ "off",
+ "never",
+ {
+ "line": {
+ "ignorePattern": ".*",
+ "ignoreInlineComments": true,
+ "ignoreConsecutiveComments": true
+ },
+ "block": {
+ "ignorePattern": ".*",
+ "ignoreInlineComments": true,
+ "ignoreConsecutiveComments": true
+ }
+ }
+ ],
+ // never have comma dangle in multiline.
+ "comma-dangle": [
+ "error", "never"
+ ],
+ // enforce spacing before and after comma
+ "comma-spacing": [
+ "error",
+ {
+ "before": false,
+ "after": true
+ }
+ ],
+ // enforce one true comma style
+ "comma-style": [
+ "error",
+ "last",
+ {
+ "exceptions": {
+ "ArrayExpression": false,
+ "ArrayPattern": false,
+ "ArrowFunctionExpression": false,
+ "CallExpression": false,
+ "FunctionDeclaration": false,
+ "FunctionExpression": false,
+ "ImportDeclaration": false,
+ "ObjectExpression": false,
+ "ObjectPattern": false,
+ "VariableDeclaration": false,
+ "NewExpression": false
+ }
+ }
+ ],
+ // disallow padding inside computed properties
+ "computed-property-spacing": [
+ "error",
+ "never"
+ ],
+ // enforces consistent naming when capturing the current execution context
+ "consistent-this": "off",
+ // enforce newline at the end of file, with no multiple empty lines
+ "eol-last": [
+ "error",
+ "always"
+ ],
+ // https://eslint.org/docs/rules/function-call-argument-newline
+ "function-call-argument-newline": [
+ "error",
+ "consistent"
+ ],
+ // enforce spacing between functions and their invocations
+ // https://eslint.org/docs/rules/func-call-spacing
+ "func-call-spacing": [
+ "error",
+ "never"
+ ],
+ // requires function names to match the name of the variable or property to which they are
+ // assigned
+ // https://eslint.org/docs/rules/func-name-matching
+ "func-name-matching": [
+ "off",
+ "always",
+ {
+ "includeCommonJSModuleExports": false,
+ "considerPropertyDescriptor": true
+ }
+ ],
+ // require function expressions to have a name
+ // https://eslint.org/docs/rules/func-names
+ "func-names": "warn",
+ // enforces use of function declarations or expressions
+ // https://eslint.org/docs/rules/func-style
+ // TODO: enable
+ "func-style": [
+ "off",
+ "expression"
+ ],
+ // enforce consistent line breaks inside function parentheses
+ // https://eslint.org/docs/rules/function-paren-newline
+ "function-paren-newline": [
+ "error",
+ "consistent"
+ ],
+ // Blacklist certain identifiers to prevent them being used
+ // https://eslint.org/docs/rules/id-blacklist
+ "id-blacklist": "off",
+ // this option enforces minimum and maximum identifier lengths
+ // (variable names, property names etc.)
+ "id-length": "off",
+ // require identifiers to match the provided regular expression
+ "id-match": "off",
+ // Enforce the location of arrow function bodies with implicit returns
+ // https://eslint.org/docs/rules/implicit-arrow-linebreak
+ "implicit-arrow-linebreak": [
+ "error",
+ "beside"
+ ],
+ // this option sets a specific tab width for your code
+ // https://eslint.org/docs/rules/indent
+ "indent": [
+ "error",
+ 2,
+ {
+ "SwitchCase": 1,
+ "VariableDeclarator": 1,
+ "outerIIFEBody": 1,
+ // MemberExpression: null,
+ "FunctionDeclaration": {
+ "parameters": 1,
+ "body": 1
+ },
+ "FunctionExpression": {
+ "parameters": 1,
+ "body": 1
+ },
+ "CallExpression": {
+ "arguments": 1
+ },
+ "ArrayExpression": 1,
+ "ObjectExpression": 1,
+ "ImportDeclaration": 1,
+ "flatTernaryExpressions": false,
+ // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
+ "ignoredNodes": [
+ "JSXElement",
+ "JSXElement > *",
+ "JSXAttribute",
+ "JSXIdentifier",
+ "JSXNamespacedName",
+ "JSXMemberExpression",
+ "JSXSpreadAttribute",
+ "JSXExpressionContainer",
+ "JSXOpeningElement",
+ "JSXClosingElement",
+ "JSXFragment",
+ "JSXOpeningFragment",
+ "JSXClosingFragment",
+ "JSXText",
+ "JSXEmptyExpression",
+ "JSXSpreadChild"
+ ],
+ "ignoreComments": false
+ }
+ ],
+ // specify whether double or single quotes should be used in JSX attributes
+ // https://eslint.org/docs/rules/jsx-quotes
+ "jsx-quotes": [
+ "off",
+ "prefer-double"
+ ],
+ // enforces spacing between keys and values in object literal properties
+ "key-spacing": [
+ "error",
+ {
+ "beforeColon": false,
+ "afterColon": true
+ }
+ ],
+ // require a space before & after certain keywords
+ "keyword-spacing": [
+ "error",
+ {
+ "before": true,
+ "after": true,
+ "overrides": {
+ "return": {
+ "after": true
+ },
+ "throw": {
+ "after": true
+ },
+ "case": {
+ "after": true
+ }
+ }
+ }
+ ],
+ // enforce position of line comments
+ // https://eslint.org/docs/rules/line-comment-position
+ // TODO: enable?
+ "line-comment-position": [
+ "off",
+ {
+ "position": "above",
+ "ignorePattern": "",
+ "applyDefaultPatterns": true
+ }
+ ],
+ // disallow mixed "LF" and "CRLF" as linebreaks
+ // https://eslint.org/docs/rules/linebreak-style
+ "linebreak-style": [
+ "error",
+ "unix"
+ ],
+ // require or disallow an empty line between class members
+ // https://eslint.org/docs/rules/lines-between-class-members
+ "lines-between-class-members": [
+ "error",
+ "always",
+ {
+ "exceptAfterSingleLine": false
+ }
+ ],
+ // enforces empty lines around comments
+ "lines-around-comment": "off",
+ // require or disallow newlines around directives
+ // https://eslint.org/docs/rules/lines-around-directive
+ "lines-around-directive": [
+ "error",
+ {
+ "before": "always",
+ "after": "always"
+ }
+ ],
+ // specify the maximum depth that blocks can be nested
+ "max-depth": [
+ "off",
+ 4
+ ],
+ // specify the maximum length of a line in your program
+ // https://eslint.org/docs/rules/max-len
+ "max-len": [
+ "error",
+ 100,
+ 2,
+ {
+ "ignoreUrls": true,
+ "ignoreComments": false,
+ "ignoreRegExpLiterals": true,
+ "ignoreStrings": true,
+ "ignoreTemplateLiterals": true
+ }
+ ],
+ // specify the max number of lines in a file
+ // https://eslint.org/docs/rules/max-lines
+ "max-lines": [
+ "off",
+ {
+ "max": 300,
+ "skipBlankLines": true,
+ "skipComments": true
+ }
+ ],
+ // enforce a maximum function length
+ // https://eslint.org/docs/rules/max-lines-per-function
+ "max-lines-per-function": [
+ "off",
+ {
+ "max": 50,
+ "skipBlankLines": true,
+ "skipComments": true,
+ "IIFEs": true
+ }
+ ],
+ // specify the maximum depth callbacks can be nested
+ "max-nested-callbacks": "off",
+ // limits the number of parameters that can be used in the function declaration.
+ "max-params": [
+ "off",
+ 3
+ ],
+ // specify the maximum number of statement allowed in a function
+ "max-statements": [
+ "off",
+ 10
+ ],
+ // restrict the number of statements per line
+ // https://eslint.org/docs/rules/max-statements-per-line
+ "max-statements-per-line": [
+ "off",
+ {
+ "max": 1
+ }
+ ],
+ // enforce a particular style for multiline comments
+ // https://eslint.org/docs/rules/multiline-comment-style
+ "multiline-comment-style": [
+ "off",
+ "starred-block"
+ ],
+ // require multiline ternary
+ // https://eslint.org/docs/rules/multiline-ternary
+ // TODO: enable?
+ "multiline-ternary": [
+ "off",
+ "never"
+ ],
+ // require a capital letter for constructors
+ "new-cap": [
+ "error",
+ {
+ "newIsCap": true,
+ "newIsCapExceptions": [],
+ "capIsNew": false,
+ "capIsNewExceptions": [
+ "Immutable.Map",
+ "Immutable.Set",
+ "Immutable.List"
+ ]
+ }
+ ],
+ // disallow the omission of parentheses when invoking a constructor with no arguments
+ // https://eslint.org/docs/rules/new-parens
+ "new-parens": "error",
+ // allow/disallow an empty newline after var statement
+ "newline-after-var": "off",
+ // https://eslint.org/docs/rules/newline-before-return
+ "newline-before-return": "off",
+ // enforces new line after each method call in the chain to make it
+ // more readable and easy to maintain
+ // https://eslint.org/docs/rules/newline-per-chained-call
+ "newline-per-chained-call": [
+ "error",
+ {
+ "ignoreChainWithDepth": 4
+ }
+ ],
+ // disallow use of the Array constructor
+ "no-array-constructor": "error",
+ // disallow use of bitwise operators
+ // https://eslint.org/docs/rules/no-bitwise
+ "no-bitwise": "error",
+ // disallow use of the continue statement
+ // https://eslint.org/docs/rules/no-continue
+ "no-continue": "error",
+ // disallow comments inline after code
+ "no-inline-comments": "off",
+ // disallow if as the only statement in an else block
+ // https://eslint.org/docs/rules/no-lonely-if
+ "no-lonely-if": "error",
+ // disallow un-paren"d mixes of different operators
+ // https://eslint.org/docs/rules/no-mixed-operators
+ "no-mixed-operators": [
+ "error",
+ {
+ // the list of arthmetic groups disallows mixing `%` and `**`
+ // with other arithmetic operators.
+ "groups": [
+ [
+ "%",
+ "**"
+ ],
+ [
+ "%",
+ "+"
+ ],
+ [
+ "%",
+ "-"
+ ],
+ [
+ "%",
+ "*"
+ ],
+ [
+ "%",
+ "/"
+ ],
+ [
+ "/",
+ "*"
+ ],
+ [
+ "&",
+ "|",
+ "<<",
+ ">>",
+ ">>>"
+ ],
+ [
+ "==",
+ "!=",
+ "===",
+ "!=="
+ ],
+ [
+ "&&",
+ "||"
+ ]
+ ],
+ "allowSamePrecedence": false
+ }
+ ],
+ // disallow mixed spaces and tabs for indentation
+ "no-mixed-spaces-and-tabs": "error",
+ // disallow use of chained assignment expressions
+ // https://eslint.org/docs/rules/no-multi-assign
+ "no-multi-assign": [
+ "error"
+ ],
+ // disallow multiple empty lines, only one newline at the end, and no new lines at the beginning
+ // https://eslint.org/docs/rules/no-multiple-empty-lines
+ "no-multiple-empty-lines": [
+ "error",
+ {
+ "max": 1,
+ "maxBOF": 0,
+ "maxEOF": 0
+ }
+ ],
+ // disallow negated conditions
+ // https://eslint.org/docs/rules/no-negated-condition
+ "no-negated-condition": "off",
+ // disallow nested ternary expressions
+ "no-nested-ternary": "error",
+ // disallow use of the Object constructor
+ "no-new-object": "error",
+
+ // disallow certain syntax forms
+ // https://eslint.org/docs/rules/no-restricted-syntax
+ "no-restricted-syntax": [
+ "error",
+ {
+ "selector": "ForInStatement",
+ "message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array."
+ },
+ {
+ "selector": "ForOfStatement",
+ "message": "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations."
+ },
+ {
+ "selector": "LabeledStatement",
+ "message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
+ },
+ {
+ "selector": "WithStatement",
+ "message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
+ }
+ ],
+ // disallow space between function identifier and application
+ "no-spaced-func": "error",
+ // disallow tab characters entirely
+ "no-tabs": "error",
+ // disallow the use of ternary operators
+ "no-ternary": "off",
+ // disallow trailing whitespace at the end of lines
+ "no-trailing-spaces": [
+ "error",
+ {
+ "skipBlankLines": false,
+ "ignoreComments": false
+ }
+ ],
+ // disallow dangling underscores in identifiers
+ // https://eslint.org/docs/rules/no-underscore-dangle
+ "no-underscore-dangle": [
+ "error",
+ {
+ "allow": [],
+ "allowAfterThis": false,
+ "allowAfterSuper": false,
+ "enforceInMethodNames": true
+ }
+ ],
+ // disallow the use of Boolean literals in conditional expressions
+ // also, prefer `a || b` over `a ? a : b`
+ // https://eslint.org/docs/rules/no-unneeded-ternary
+ "no-unneeded-ternary": [
+ "error",
+ {
+ "defaultAssignment": false
+ }
+ ],
+ // disallow whitespace before properties
+ // https://eslint.org/docs/rules/no-whitespace-before-property
+ "no-whitespace-before-property": "error",
+ // enforce the location of single-line statements
+ // https://eslint.org/docs/rules/nonblock-statement-body-position
+ "nonblock-statement-body-position": [
+ "error",
+ "beside",
+ {
+ "overrides": {}
+ }
+ ],
+ // require padding inside curly braces
+ "object-curly-spacing": [
+ "error",
+ "always"
+ ],
+ // enforce line breaks between braces
+ // https://eslint.org/docs/rules/object-curly-newline
+ "object-curly-newline": [
+ "error",
+ {
+ "ObjectExpression": {
+ "minProperties": 4,
+ "multiline": true,
+ "consistent": true
+ },
+ "ObjectPattern": {
+ "minProperties": 4,
+ "multiline": true,
+ "consistent": true
+ },
+ "ImportDeclaration": {
+ "minProperties": 4,
+ "multiline": true,
+ "consistent": true
+ },
+ "ExportDeclaration": {
+ "minProperties": 4,
+ "multiline": true,
+ "consistent": true
+ }
+ }
+ ],
+ // enforce "same line" or "multiple line" on object properties.
+ // https://eslint.org/docs/rules/object-property-newline
+ "object-property-newline": [
+ "error",
+ {
+ "allowAllPropertiesOnSameLine": true
+ }
+ ],
+ // allow just one var statement per function
+ "one-var": [
+ "error",
+ "never"
+ ],
+ // require a newline around variable declaration
+ // https://eslint.org/docs/rules/one-var-declaration-per-line
+ "one-var-declaration-per-line": [
+ "error",
+ "always"
+ ],
+ // require assignment operator shorthand where possible or prohibit it entirely
+ // https://eslint.org/docs/rules/operator-assignment
+ "operator-assignment": [
+ "error",
+ "always"
+ ],
+ // Requires operator at the beginning of the line in multiline statements
+ // https://eslint.org/docs/rules/operator-linebreak
+ "operator-linebreak": [
+ "error",
+ "before",
+ {
+ "overrides": {
+ "=": "none"
+ }
+ }
+ ],
+ // disallow padding within blocks
+ "padded-blocks": [
+ "error",
+ {
+ "blocks": "never",
+ "classes": "never",
+ "switches": "never"
+ },
+ {
+ "allowSingleLineBlocks": true
+ }
+ ],
+ // Require or disallow padding lines between statements
+ // https://eslint.org/docs/rules/padding-line-between-statements
+ "padding-line-between-statements": "off",
+ // Disallow the use of Math.pow in favor of the ** operator
+ // https://eslint.org/docs/rules/prefer-exponentiation-operator
+ // TODO: enable, semver-major when eslint 5 is dropped
+ "prefer-exponentiation-operator": "off",
+ // Prefer use of an object spread over Object.assign
+ // https://eslint.org/docs/rules/prefer-object-spread
+ "prefer-object-spread": "error",
+ // require quotes around object literal property names
+ // https://eslint.org/docs/rules/quote-props.html
+ "quote-props": [
+ "error",
+ "as-needed",
+ {
+ "keywords": false,
+ "unnecessary": true,
+ "numbers": false
+ }
+ ],
+ // specify whether double or single quotes should be used
+ "quotes": [
+ "error",
+ "single",
+ {
+ "avoidEscape": true
+ }
+ ],
+ // do not require jsdoc
+ // https://eslint.org/docs/rules/require-jsdoc
+ "require-jsdoc": "off",
+ // require or disallow use of semicolons instead of ASI
+ "semi": [
+ "error",
+ "always"
+ ],
+ // enforce spacing before and after semicolons
+ "semi-spacing": [
+ "error",
+ {
+ "before": false,
+ "after": true
+ }
+ ],
+ // Enforce location of semicolons
+ // https://eslint.org/docs/rules/semi-style
+ "semi-style": [
+ "error",
+ "last"
+ ],
+ // requires object keys to be sorted
+ "sort-keys": [
+ "off",
+ "asc",
+ {
+ "caseSensitive": false,
+ "natural": true
+ }
+ ],
+ // sort variables within the same declaration block
+ "sort-vars": "off",
+ // require or disallow space before blocks
+ "space-before-blocks": "error",
+ // require or disallow space before function opening parenthesis
+ // https://eslint.org/docs/rules/space-before-function-paren
+ "space-before-function-paren": [
+ "error",
+ {
+ "anonymous": "always",
+ "named": "never",
+ "asyncArrow": "always"
+ }
+ ],
+ // require or disallow spaces inside parentheses
+ "space-in-parens": [
+ "error",
+ "never"
+ ],
+ // require spaces around operators
+ "space-infix-ops": "error",
+ // Require or disallow spaces before/after unary operators
+ // https://eslint.org/docs/rules/space-unary-ops
+ "space-unary-ops": [
+ "error",
+ {
+ "words": true,
+ "nonwords": false,
+ "overrides": {
+ }
+ }
+ ],
+ // require or disallow a space immediately following the // or /* in a comment
+ // https://eslint.org/docs/rules/spaced-comment
+ "spaced-comment": [
+ "error",
+ "always",
+ {
+ "line": {
+ "exceptions": [
+ "-",
+ "+"
+ ],
+ "markers": [
+ "=",
+ "!",
+ "/"
+ ]
+ // space here to support sprockets directives, slash for TS /// comments
+ },
+ "block": {
+ "exceptions": [
+ "-",
+ "+"
+ ],
+ "markers": [
+ "=",
+ "!",
+ ":",
+ "::"
+ ],
+ // space here to support sprockets directives and flow comment types
+ "balanced": true
+ }
+ }
+ ],
+ // Enforce spacing around colons of switch statements
+ // https://eslint.org/docs/rules/switch-colon-spacing
+ "switch-colon-spacing": [
+ "error",
+ {
+ "after": true,
+ "before": false
+ }
+ ],
+ // Require or disallow spacing between template tags and their literals
+ // https://eslint.org/docs/rules/template-tag-spacing
+ "template-tag-spacing": [
+ "error",
+ "never"
+ ],
+ // require or disallow the Unicode Byte Order Mark
+ // https://eslint.org/docs/rules/unicode-bom
+ "unicode-bom": [
+ "error",
+ "never"
+ ],
+ // require regex literals to be wrapped in parentheses
+ "wrap-regex": "off",
+ // enforce or disallow variable initializations at definition
+ "init-declarations": "off",
+ // disallow the catch clause parameter name being the same as a variable in the outer scope
+ "no-catch-shadow": "off",
+ // disallow deletion of variables
+ "no-delete-var": "error",
+ // disallow labels that share a name with a variable
+ // https://eslint.org/docs/rules/no-label-var
+ "no-label-var": "error",
+ // disallow specific globals
+ "no-restricted-globals": [
+ "error",
+ "isFinite",
+ "isNaN",
+ "addEventListener",
+ "blur",
+ "close",
+ "closed",
+ "confirm",
+ "defaultStatus",
+ "defaultstatus",
+ "event",
+ "external",
+ "find",
+ "focus",
+ "frameElement",
+ "frames",
+ "history",
+ "innerHeight",
+ "innerWidth",
+ "length",
+ "location",
+ "locationbar",
+ "menubar",
+ "moveBy",
+ "moveTo",
+ "name",
+ "onblur",
+ "onerror",
+ "onfocus",
+ "onload",
+ "onresize",
+ "onunload",
+ "open",
+ "opener",
+ "opera",
+ "outerHeight",
+ "outerWidth",
+ "pageXOffset",
+ "pageYOffset",
+ "parent",
+ "print",
+ "removeEventListener",
+ "resizeBy",
+ "resizeTo",
+ "screen",
+ "screenLeft",
+ "screenTop",
+ "screenX",
+ "screenY",
+ "scroll",
+ "scrollbars",
+ "scrollBy",
+ "scrollTo",
+ "scrollX",
+ "scrollY",
+ "self",
+ "status",
+ "statusbar",
+ "stop",
+ "toolbar",
+ "top"
+ ],
+ // disallow declaration of variables already declared in the outer scope
+ "no-shadow": "error",
+ // disallow shadowing of names such as arguments
+ "no-shadow-restricted-names": "error",
+ // disallow use of undeclared variables unless mentioned in a /*global */ block
+ "no-undef": "error",
+ // disallow use of undefined when initializing variables
+ "no-undef-init": "error",
+ // disallow use of undefined variable
+ // https://eslint.org/docs/rules/no-undefined
+ // TODO: enable?
+ "no-undefined": "off",
+ // disallow declaration of variables that are not used in the code
+ "no-unused-vars": [
+ "error",
+ {
+ "vars": "all",
+ "args": "after-used",
+ "ignoreRestSiblings": true
+ }
+ ],
+ // disallow use of variables before they are defined
+ "no-use-before-define": [
+ "error",
+ {
+ "functions": true,
+ "classes": true,
+ "variables": true
+ }
+ ]
+ }
+}
diff --git a/.gitignore b/.gitignore
index ac10dfe528..44065a7f64 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,9 @@ node_modules
# Only apps should have lockfiles
yarn.lock
package-lock.json
+.idea/inspectionProfiles/Project_Default.xml
+.idea/javascript.iml
+.idea/jsLinters/jshint.xml
+.idea/misc.xml
+.idea/modules.xml
+.idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000000..e7e9d11d4b
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000000..a55e7a179b
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index b7eb96d7ae..0000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,108 +0,0 @@
-language: node_js
-node_js:
- - "14"
- - "12"
- - "10"
-before_install:
- - 'nvm install-latest-npm'
-install:
- - 'if [ -n "${PACKAGE-}" ]; then cd "packages/${PACKAGE}"; fi'
- - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
- - 'if [ -n "${ESLINT}" ]; then npm install --no-save "eslint@${ESLINT}"; fi'
- - 'if [ -n "${REACT_HOOKS}" ]; then npm install --no-save "eslint-plugin-react-hooks@${REACT_HOOKS}"; fi'
-script:
- - 'if [ -n "${PREPUBLISH-}" ]; then npm run pretravis && npm run prepublish && npm run posttravis; elif [ -n "${LINT-}" ]; then npm run lint; else npm run travis; fi'
-sudo: false
-env:
- matrix:
- - 'TEST=true ESLINT=7 PACKAGE=eslint-config-airbnb-base'
- - 'TEST=true ESLINT=7 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=7 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=7 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=7 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb-base'
- - 'TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=6 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=6 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base'
- - 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=5 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=5 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb'
- - 'TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb'
-matrix:
- fast_finish: true
- include:
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=7 PACKAGE=eslint-config-airbnb-base
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=7 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=7 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=7 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=7 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=6 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=6 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=5 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=5 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: PREPUBLISH=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: LINT=true
- - node_js: "lts/*"
- env: LINT=true PACKAGE=eslint-config-airbnb
- - node_js: "lts/*"
- env: LINT=true PACKAGE=eslint-config-airbnb-base
- - node_js: "8"
- env: TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
- - node_js: "8"
- env: TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=6 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=6 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- - node_js: "8"
- env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=5 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=5 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "8"
- env: TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- - node_js: "6"
- env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- - node_js: "6"
- env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb
- - node_js: "6"
- env: TEST=true ESLINT=5 REACT_HOOKS=3 PACKAGE=eslint-config-airbnb
- - node_js: "6"
- env: TEST=true ESLINT=5 REACT_HOOKS=2.3 PACKAGE=eslint-config-airbnb
- - node_js: "6"
- env: TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
- exclude:
- allow_failures:
- - env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
- - env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb
- - env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
- - env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb
diff --git a/LICENSE.md b/LICENSE.md
deleted file mode 100644
index 69d80c0252..0000000000
--- a/LICENSE.md
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2012 Airbnb
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
index 57ebc57624..3e73c782d2 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,12 @@
-# Airbnb JavaScript Style Guide() {
+# Unearth JavaScript Style Guide() {
*A mostly reasonable approach to JavaScript*
-> **Note**: this guide assumes you are using [Babel](https://babeljs.io), and requires that you use [babel-preset-airbnb](https://npmjs.com/babel-preset-airbnb) or the equivalent. It also assumes you are installing shims/polyfills in your app, with [airbnb-browser-shims](https://npmjs.com/airbnb-browser-shims) or the equivalent.
-
-[](https://www.npmjs.com/package/eslint-config-airbnb)
-[](https://www.npmjs.com/package/eslint-config-airbnb-base)
-[](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
-
-This guide is available in other languages too. See [Translation](#translation)
-
Other Style Guides
- - [ES5 (Deprecated)](https://github.com/airbnb/javascript/tree/es5-deprecated/es5)
- - [React](react/)
- - [CSS-in-JavaScript](css-in-javascript/)
- - [CSS & Sass](https://github.com/airbnb/css)
- - [Ruby](https://github.com/airbnb/ruby)
+ - [Mithril.js](mithril/)
+
+ Lint rules can be found in the [eslintrc](.eslintrc).
## Table of Contents
@@ -73,14 +63,14 @@ Other Style Guides
- `symbol`
- `bigint`
- ```javascript
+```javascript
const foo = 1;
let bar = foo;
bar = 9;
console.log(foo, bar); // => 1, 9
- ```
+```
- Symbols and BigInts cannot be faithfully polyfilled, so they should not be used when targeting browsers/environments that don’t support them natively.
@@ -91,14 +81,14 @@ Other Style Guides
- `array`
- `function`
- ```javascript
+```javascript
const foo = [1, 2];
const bar = foo;
bar[0] = 9;
console.log(foo[0], bar[0]); // => 9, 9
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -109,7 +99,7 @@ Other Style Guides
> Why? This ensures that you can’t reassign your references, which can lead to bugs and difficult to comprehend code.
- ```javascript
+```javascript
// bad
var a = 1;
var b = 2;
@@ -117,39 +107,39 @@ Other Style Guides
// good
const a = 1;
const b = 2;
- ```
+```
- [2.2](#references--disallow-var) If you must reassign references, use `let` instead of `var`. eslint: [`no-var`](https://eslint.org/docs/rules/no-var.html)
> Why? `let` is block-scoped rather than function-scoped like `var`.
- ```javascript
+```JavaScript
// bad
var count = 1;
if (true) {
- count += 1;
+ count += 1;
}
// good, use the let.
let count = 1;
if (true) {
- count += 1;
+ count += 1;
}
- ```
+```
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped.
- ```javascript
+```javascript
// const and let only exist in the blocks they are defined in.
{
- let a = 1;
- const b = 1;
+ let a = 1;
+ const b = 1;
}
console.log(a); // ReferenceError
console.log(b); // ReferenceError
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -158,50 +148,50 @@ Other Style Guides
- [3.1](#objects--no-new) Use the literal syntax for object creation. eslint: [`no-new-object`](https://eslint.org/docs/rules/no-new-object.html)
- ```javascript
+```javascript
// bad
const item = new Object();
// good
const item = {};
- ```
+```
- [3.2](#es6-computed-properties) Use computed property names when creating objects with dynamic property names.
> Why? They allow you to define all the properties of an object in one place.
- ```javascript
+```javascript
function getKey(k) {
- return `a key named ${k}`;
+ return `a key named ${k}`;
}
- // bad
+ // ok
const obj = {
- id: 5,
- name: 'San Francisco',
+ id: 5,
+ name: 'San Francisco',
};
obj[getKey('enabled')] = true;
- // good
+ // better
const obj = {
- id: 5,
- name: 'San Francisco',
- [getKey('enabled')]: true,
+ id: 5,
+ name: 'San Francisco',
+ [getKey('enabled')]: true,
};
- ```
+```
- [3.3](#es6-object-shorthand) Use object method shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html)
- ```javascript
+```javascript
// bad
const atom = {
- value: 1,
+ value: 1,
addValue: function (value) {
- return atom.value + value;
+ return atom.value + value;
},
};
@@ -213,14 +203,14 @@ Other Style Guides
return atom.value + value;
},
};
- ```
+```
- [3.4](#es6-object-concise) Use property value shorthand. eslint: [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand.html)
> Why? It is shorter and descriptive.
- ```javascript
+```javascript
const lukeSkywalker = 'Luke Skywalker';
// bad
@@ -232,14 +222,14 @@ Other Style Guides
const obj = {
lukeSkywalker,
};
- ```
+```
- [3.5](#objects--grouped-shorthand) Group your shorthand properties at the beginning of your object declaration.
> Why? It’s easier to tell which properties are using the shorthand.
- ```javascript
+```javascript
const anakinSkywalker = 'Anakin Skywalker';
const lukeSkywalker = 'Luke Skywalker';
@@ -262,14 +252,14 @@ Other Style Guides
episodeThree: 3,
mayTheFourth: 4,
};
- ```
+```
- [3.6](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](https://eslint.org/docs/rules/quote-props.html)
> Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
- ```javascript
+```javascript
// bad
const bad = {
'foo': 3,
@@ -283,14 +273,14 @@ Other Style Guides
bar: 4,
'data-blah': 5,
};
- ```
+```
- [3.7](#objects--prototype-builtins) Do not call `Object.prototype` methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and `isPrototypeOf`. eslint: [`no-prototype-builtins`](https://eslint.org/docs/rules/no-prototype-builtins)
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
- ```javascript
+```javascript
// bad
console.log(object.hasOwnProperty(key));
@@ -303,18 +293,18 @@ Other Style Guides
/* or */
import has from 'has'; // https://www.npmjs.com/package/has
console.log(has(object, key));
- ```
+```
- [3.8](#objects--rest-spread) Prefer the object spread operator over [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.
- ```javascript
+```javascript
// very bad
const original = { a: 1, b: 2 };
const copy = Object.assign(original, { c: 3 }); // this mutates `original` ಠ_ಠ
delete copy.a; // so does this
- // bad
+ // ok, but not preferred.
const original = { a: 1, b: 2 };
const copy = Object.assign({}, original, { c: 3 }); // copy => { a: 1, b: 2, c: 3 }
@@ -323,7 +313,7 @@ Other Style Guides
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
const { a, ...noA } = copy; // noA => { b: 2, c: 3 }
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -332,18 +322,18 @@ Other Style Guides
- [4.1](#arrays--literals) Use the literal syntax for array creation. eslint: [`no-array-constructor`](https://eslint.org/docs/rules/no-array-constructor.html)
- ```javascript
+```javascript
// bad
const items = new Array();
// good
const items = [];
- ```
+```
- [4.2](#arrays--push) Use [Array#push](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push) instead of direct assignment to add items to an array.
- ```javascript
+```javascript
const someStack = [];
// bad
@@ -351,12 +341,12 @@ Other Style Guides
// good
someStack.push('abracadabra');
- ```
+```
- [4.3](#es6-array-spreads) Use array spreads `...` to copy arrays.
- ```javascript
+```javascript
// bad
const len = items.length;
const itemsCopy = [];
@@ -366,15 +356,20 @@ Other Style Guides
itemsCopy[i] = items[i];
}
+ // OK
+ items.forEach((item) => {
+ itemsCopy.push(item);
+ });
+
// good
const itemsCopy = [...items];
- ```
+```
- [4.4](#arrays--from-iterable) To convert an iterable object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
- ```javascript
+```javascript
const foo = document.querySelectorAll('.foo');
// good
@@ -382,12 +377,12 @@ Other Style Guides
// best
const nodes = [...foo];
- ```
+```
- [4.5](#arrays--from-array-like) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) for converting an array-like object to an array.
- ```javascript
+```javascript
const arrLike = { 0: 'foo', 1: 'bar', 2: 'baz', length: 3 };
// bad
@@ -395,23 +390,23 @@ Other Style Guides
// good
const arr = Array.from(arrLike);
- ```
+```
- [4.6](#arrays--mapping) Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) instead of spread `...` for mapping over iterables, because it avoids creating an intermediate array.
- ```javascript
+```javascript
// bad
const baz = [...foo].map(bar);
// good
const baz = Array.from(foo, bar);
- ```
+```
- [4.7](#arrays--callback-return) Use return statements in array method callbacks. It’s ok to omit the return if the function body consists of a single statement returning an expression without side effects, following [8.2](#arrows--implicit-return). eslint: [`array-callback-return`](https://eslint.org/docs/rules/array-callback-return)
- ```javascript
+```javascript
// good
[1, 2, 3].map((x) => {
const y = x + 1;
@@ -451,23 +446,20 @@ Other Style Guides
return false;
});
- ```
+```
- [4.8](#arrays--bracket-newline) Use line breaks after open and before close array brackets if an array has multiple lines
- ```javascript
+ [TODO] Not sure if I hate this one
+
+
+```javascript
// bad
const arr = [
[0, 1], [2, 3], [4, 5],
];
- const objectInArray = [{
- id: 1,
- }, {
- id: 2,
- }];
-
const numberInArray = [
1, 2,
];
@@ -475,6 +467,12 @@ Other Style Guides
// good
const arr = [[0, 1], [2, 3], [4, 5]];
+ const objectInArray = [{
+ id: 1,
+ }, {
+ id: 2,
+ }];
+
const objectInArray = [
{
id: 1,
@@ -488,7 +486,7 @@ Other Style Guides
1,
2,
];
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -499,7 +497,7 @@ Other Style Guides
> Why? Destructuring saves you from creating temporary references for those properties.
- ```javascript
+```javascript
// bad
function getFullName(user) {
const firstName = user.firstName;
@@ -518,12 +516,12 @@ Other Style Guides
function getFullName({ firstName, lastName }) {
return `${firstName} ${lastName}`;
}
- ```
+```
- [5.2](#destructuring--array) Use array destructuring. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring)
- ```javascript
+```javascript
const arr = [1, 2, 3, 4];
// bad
@@ -532,14 +530,14 @@ Other Style Guides
// good
const [first, second] = arr;
- ```
+```
- [5.3](#destructuring--object-over-array) Use object destructuring for multiple return values, not array destructuring.
> Why? You can add new properties over time or change the order of things without breaking call sites.
- ```javascript
+```javascript
// bad
function processInput(input) {
// then a miracle occurs
@@ -557,7 +555,7 @@ Other Style Guides
// the caller selects only the data they need
const { left, top } = processInput(input);
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -566,7 +564,7 @@ Other Style Guides
- [6.1](#strings--quotes) Use single quotes `''` for strings. eslint: [`quotes`](https://eslint.org/docs/rules/quotes.html)
- ```javascript
+```javascript
// bad
const name = "Capt. Janeway";
@@ -575,35 +573,14 @@ Other Style Guides
// good
const name = 'Capt. Janeway';
- ```
-
-
- - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation.
-
- > Why? Broken strings are painful to work with and make code less searchable.
-
- ```javascript
- // bad
- const errorMessage = 'This is a super long error that was thrown because \
- of Batman. When you stop to think about how Batman had anything to do \
- with this, you would get nowhere \
- fast.';
-
- // bad
- const errorMessage = 'This is a super long error that was thrown because ' +
- 'of Batman. When you stop to think about how Batman had anything to do ' +
- 'with this, you would get nowhere fast.';
-
- // good
- const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
- ```
+```
- [6.3](#es6-template-literals) When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](https://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](https://eslint.org/docs/rules/template-curly-spacing)
> Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
- ```javascript
+```javascript
// bad
function sayHi(name) {
return 'How are you, ' + name + '?';
@@ -623,7 +600,7 @@ Other Style Guides
function sayHi(name) {
return `How are you, ${name}?`;
}
- ```
+```
- [6.4](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. eslint: [`no-eval`](https://eslint.org/docs/rules/no-eval)
@@ -633,14 +610,14 @@ Other Style Guides
> Why? Backslashes harm readability, thus they should only be present when necessary.
- ```javascript
+```javascript
// bad
const foo = '\'this\' \i\s \"quoted\"';
// good
const foo = '\'this\' is "quoted"';
const foo = `my name is '${name}'`;
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -651,7 +628,7 @@ Other Style Guides
> Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error’s call stack. ([Discussion](https://github.com/airbnb/javascript/issues/794))
- ```javascript
+```javascript
// bad
function foo() {
// ...
@@ -667,19 +644,19 @@ Other Style Guides
const short = function longUniqueMoreDescriptiveLexicalFoo() {
// ...
};
- ```
+```
- [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](https://eslint.org/docs/rules/wrap-iife.html)
> Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
- ```javascript
+```javascript
// immediately-invoked function expression (IIFE)
(function () {
console.log('Welcome to the Internet. Please follow me.');
}());
- ```
+```
- [7.3](#functions--in-blocks) Never declare a function in a non-function block (`if`, `while`, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. eslint: [`no-loop-func`](https://eslint.org/docs/rules/no-loop-func.html)
@@ -687,7 +664,7 @@ Other Style Guides
- [7.4](#functions--note-on-blocks) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement.
- ```javascript
+```javascript
// bad
if (currentUser) {
function test() {
@@ -702,12 +679,12 @@ Other Style Guides
console.log('Yup.');
};
}
- ```
+```
- [7.5](#functions--arguments-shadow) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.
- ```javascript
+```javascript
// bad
function foo(name, options, arguments) {
// ...
@@ -717,14 +694,14 @@ Other Style Guides
function foo(name, options, args) {
// ...
}
- ```
+```
- [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. eslint: [`prefer-rest-params`](https://eslint.org/docs/rules/prefer-rest-params)
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
- ```javascript
+```javascript
// bad
function concatenateAll() {
const args = Array.prototype.slice.call(arguments);
@@ -735,12 +712,12 @@ Other Style Guides
function concatenateAll(...args) {
return args.join('');
}
- ```
+```
- [7.7](#es6-default-parameters) Use default parameter syntax rather than mutating function arguments.
- ```javascript
+```javascript
// really bad
function handleThings(opts) {
// No! We shouldn’t mutate function arguments.
@@ -762,14 +739,14 @@ Other Style Guides
function handleThings(opts = {}) {
// ...
}
- ```
+```
- [7.8](#functions--default-side-effects) Avoid side effects with default parameters.
> Why? They are confusing to reason about.
- ```javascript
+```javascript
var b = 1;
// bad
function count(a = b++) {
@@ -779,12 +756,12 @@ Other Style Guides
count(); // 2
count(3); // 3
count(); // 3
- ```
+```
- [7.9](#functions--defaults-last) Always put default parameters last.
- ```javascript
+```javascript
// bad
function handleThings(opts = {}, name) {
// ...
@@ -794,27 +771,27 @@ Other Style Guides
function handleThings(name, opts = {}) {
// ...
}
- ```
+```
- [7.10](#functions--constructor) Never use the Function constructor to create a new function. eslint: [`no-new-func`](https://eslint.org/docs/rules/no-new-func)
> Why? Creating a function in this way evaluates a string similarly to `eval()`, which opens vulnerabilities.
- ```javascript
+```javascript
// bad
var add = new Function('a', 'b', 'return a + b');
// still bad
var subtract = Function('a', 'b', 'return a - b');
- ```
+```
- [7.11](#functions--signature-spacing) Spacing in a function signature. eslint: [`space-before-function-paren`](https://eslint.org/docs/rules/space-before-function-paren) [`space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks)
> Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.
- ```javascript
+```javascript
// bad
const f = function(){};
const g = function (){};
@@ -823,14 +800,14 @@ Other Style Guides
// good
const x = function () {};
const y = function a() {};
- ```
+```
- [7.12](#functions--mutate-params) Never mutate parameters. eslint: [`no-param-reassign`](https://eslint.org/docs/rules/no-param-reassign.html)
> Why? Manipulating objects passed in as parameters can cause unwanted variable side effects in the original caller.
- ```javascript
+```javascript
// bad
function f1(obj) {
obj.key = 1;
@@ -840,14 +817,14 @@ Other Style Guides
function f2(obj) {
const key = Object.prototype.hasOwnProperty.call(obj, 'key') ? obj.key : 1;
}
- ```
+```
- [7.13](#functions--reassign-params) Never reassign parameters. eslint: [`no-param-reassign`](https://eslint.org/docs/rules/no-param-reassign.html)
> Why? Reassigning parameters can lead to unexpected behavior, especially when accessing the `arguments` object. It can also cause optimization issues, especially in V8.
- ```javascript
+```javascript
// bad
function f1(a) {
a = 1;
@@ -868,14 +845,14 @@ Other Style Guides
function f4(a = 1) {
// ...
}
- ```
+```
- [7.14](#functions--spread-vs-apply) Prefer the use of the spread operator `...` to call variadic functions. eslint: [`prefer-spread`](https://eslint.org/docs/rules/prefer-spread)
> Why? It’s cleaner, you don’t need to supply a context, and you can not easily compose `new` with `apply`.
- ```javascript
+```javascript
// bad
const x = [1, 2, 3, 4, 5];
console.log.apply(console, x);
@@ -889,40 +866,53 @@ Other Style Guides
// good
new Date(...[2016, 8, 5]);
- ```
-
-
- - [7.15](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself, with a trailing comma on the last item. eslint: [`function-paren-newline`](https://eslint.org/docs/rules/function-paren-newline)
-
- ```javascript
- // bad
- function foo(bar,
- baz,
- quux) {
- // ...
- }
-
- // good
- function foo(
- bar,
- baz,
- quux,
- ) {
- // ...
- }
+```
+
+ - [7.15](#functions--function-call-spacing) Function argument spacing should be consistent within the function.
+
+```javascript
+ /*eslint function-call-argument-newline: ["error", "consistent"]*/
+
+ foo("one", "two", "three");
+ // or
+ foo(
+ "one",
+ "two",
+ "three"
+ );
- // bad
- console.log(foo,
- bar,
- baz);
+ bar("one", "two", {
+ one: 1,
+ two: 2
+ });
+ // or
+ bar(
+ "one",
+ "two",
+ { one: 1, two: 2 }
+ );
+ // or
+ bar(
+ "one",
+ "two",
+ {
+ one: 1,
+ two: 2
+ }
+ );
- // good
- console.log(
- foo,
- bar,
- baz,
+ baz("one", "two", (x) => {
+ console.log(x);
+ });
+ // or
+ baz(
+ "one",
+ "two",
+ (x) => {
+ console.log(x);
+ }
);
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -935,7 +925,7 @@ Other Style Guides
> Why not? If you have a fairly complicated function, you might move that logic out into its own named function expression.
- ```javascript
+```javascript
// bad
[1, 2, 3].map(function (x) {
const y = x + 1;
@@ -947,14 +937,14 @@ Other Style Guides
const y = x + 1;
return x * y;
});
- ```
+```
- [8.2](#arrows--implicit-return) If the function body consists of a single statement returning an [expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](https://eslint.org/docs/rules/arrow-body-style.html)
> Why? Syntactic sugar. It reads well when multiple functions are chained together.
- ```javascript
+```javascript
// bad
[1, 2, 3].map((number) => {
const nextNumber = number + 1;
@@ -992,69 +982,37 @@ Other Style Guides
foo(() => {
bool = true;
});
- ```
-
-
- - [8.3](#arrows--paren-wrap) In case the expression spans over multiple lines, wrap it in parentheses for better readability.
-
- > Why? It shows clearly where the function starts and ends.
-
- ```javascript
- // bad
- ['get', 'post', 'put'].map((httpMethod) => Object.prototype.hasOwnProperty.call(
- httpMagicObjectWithAVeryLongName,
- httpMethod,
- )
- );
-
- // good
- ['get', 'post', 'put'].map((httpMethod) => (
- Object.prototype.hasOwnProperty.call(
- httpMagicObjectWithAVeryLongName,
- httpMethod,
- )
- ));
- ```
-
-
- - [8.4](#arrows--one-arg-parens) Always include parentheses around arguments for clarity and consistency. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html)
-
- > Why? Minimizes diff churn when adding or removing arguments.
-
- ```javascript
- // bad
- [1, 2, 3].map(x => x * x);
-
- // good
- [1, 2, 3].map((x) => x * x);
-
- // bad
- [1, 2, 3].map(number => (
- `A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
- ));
-
- // good
- [1, 2, 3].map((number) => (
- `A long string with the ${number}. It’s so long that we don’t want it to take up space on the .map line!`
- ));
-
- // bad
- [1, 2, 3].map(x => {
- const y = x + 1;
- return x * y;
- });
-
- // good
- [1, 2, 3].map((x) => {
- const y = x + 1;
- return x * y;
- });
- ```
+```
+
+ - [8.4](#arrows--one-arg-parens) Include parentheses as-needed around arguments. eslint: [`arrow-parens`](https://eslint.org/docs/rules/arrow-parens.html)
+
+```javascript
+ // bad
+ (a) => {};
+ (a) => a;
+ (a) => {'\n'};
+ a.then((foo) => {});
+ a.then((foo) => a);
+ a((foo) => { if (true) {} });
+ const f = /** @type {number} */(a) => a + a;
+ const g = /* comment */ (a) => a + a;
+ const h = (a) /* comment */ => a + a;
+
+ // good
+ () => {};
+ a => a;
+ (a, b, c) => a;
+ (a = 10) => a;
+ ([a, b]) => a;
+ ({a, b}) => a;
+ const g = (/* comment */ a) => a + a;
+ const h = (a /* comment */) => a + a;
+```
- [8.5](#arrows--confusing) Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](https://eslint.org/docs/rules/no-confusing-arrow)
- ```javascript
+```javascript
// bad
const itemHeight = (item) => item.height <= 256 ? item.largeSize : item.smallSize;
@@ -1069,12 +1027,12 @@ Other Style Guides
const { height, largeSize, smallSize } = item;
return height <= 256 ? largeSize : smallSize;
};
- ```
+```
- [8.6](#whitespace--implicit-arrow-linebreak) Enforce the location of arrow function bodies with implicit returns. eslint: [`implicit-arrow-linebreak`](https://eslint.org/docs/rules/implicit-arrow-linebreak)
- ```javascript
+```javascript
// bad
(foo) =>
bar;
@@ -1088,7 +1046,7 @@ Other Style Guides
(foo) => (
bar
)
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -1099,66 +1057,67 @@ Other Style Guides
> Why? `class` syntax is more concise and easier to reason about.
- ```javascript
+```javascript
// bad
function Queue(contents = []) {
- this.queue = [...contents];
+ this.queue = [...contents];
}
Queue.prototype.pop = function () {
- const value = this.queue[0];
- this.queue.splice(0, 1);
- return value;
+ const value = this.queue[0];
+ this.queue.splice(0, 1);
+ return value;
};
// good
class Queue {
- constructor(contents = []) {
- this.queue = [...contents];
- }
- pop() {
- const value = this.queue[0];
- this.queue.splice(0, 1);
- return value;
- }
+ constructor(contents = []) {
+ this.queue = [...contents];
+ }
+ pop() {
+ const value = this.queue[0];
+ this.queue.splice(0, 1);
+ return value;
+ }
}
- ```
+```
- [9.2](#constructors--extends) Use `extends` for inheritance.
> Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.
- ```javascript
+```javascript
// bad
const inherits = require('inherits');
function PeekableQueue(contents) {
- Queue.apply(this, contents);
+ Queue.apply(this, contents);
}
inherits(PeekableQueue, Queue);
PeekableQueue.prototype.peek = function () {
- return this.queue[0];
+ return this.queue[0];
};
// good
class PeekableQueue extends Queue {
- peek() {
- return this.queue[0];
- }
+ peek() {
+ return this.queue[0];
+ }
}
- ```
+```
- [9.3](#constructors--chaining) Methods can return `this` to help with method chaining.
- ```javascript
+```javascript
// bad
Jedi.prototype.jump = function () {
- this.jumping = true;
- return true;
+ this.jumping = true;
+ return true;
};
+ // bad
Jedi.prototype.setHeight = function (height) {
- this.height = height;
+ this.height = height;
};
const luke = new Jedi();
@@ -1167,77 +1126,81 @@ Other Style Guides
// good
class Jedi {
- jump() {
- this.jumping = true;
- return this;
- }
+ jump() {
+ this.jumping = true;
+ return this;
+ }
- setHeight(height) {
- this.height = height;
- return this;
- }
+ setHeight(height) {
+ this.height = height;
+ return this;
+ }
}
const luke = new Jedi();
- luke.jump()
- .setHeight(20);
- ```
+ luke.jump().setHeight(20);
+```
- [9.4](#constructors--tostring) It’s okay to write a custom `toString()` method, just make sure it works successfully and causes no side effects.
- ```javascript
+```javascript
class Jedi {
- constructor(options = {}) {
- this.name = options.name || 'no name';
- }
+ constructor(options = {}) {
+ this.name = options.name || 'no name';
+ }
- getName() {
- return this.name;
- }
+ getName() {
+ return this.name;
+ }
- toString() {
- return `Jedi - ${this.getName()}`;
- }
+ toString() {
+ return `Jedi - ${this.getName()}`;
+ }
}
- ```
+```
- [9.5](#constructors--no-useless) Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. eslint: [`no-useless-constructor`](https://eslint.org/docs/rules/no-useless-constructor)
- ```javascript
+```javascript
// bad
- class Jedi {
- constructor() {}
-
- getName() {
- return this.name;
- }
- }
+ class Jedi {
+ constructor() {}
+
+ getName() {
+ return this.name;
+ }
+ }
+
+ // bad
+ class Rey extends Jedi {
+ constructor(...args) {
+ super(...args);
+ }
+ }
+
+ // good
+ class Rey extends Jedi {
+ constructor(...args) {
+ super(...args);
+ this.name = 'Rey';
+ }
+ }
- // bad
- class Rey extends Jedi {
- constructor(...args) {
- super(...args);
- }
- }
+ // good
+ class Rey extends Jedi {
- // good
- class Rey extends Jedi {
- constructor(...args) {
- super(...args);
- this.name = 'Rey';
- }
- }
- ```
+ }
+```
- [9.6](#classes--no-duplicate-members) Avoid duplicate class members. eslint: [`no-dupe-class-members`](https://eslint.org/docs/rules/no-dupe-class-members)
> Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug.
- ```javascript
+```javascript
// bad
class Foo {
bar() { return 1; }
@@ -1251,53 +1214,22 @@ Other Style Guides
// good
class Foo {
- bar() { return 2; }
- }
- ```
-
-
- - [9.7](#classes--methods-use-this) Class methods should use `this` or be made into a static method unless an external library or framework requires to use specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: [`class-methods-use-this`](https://eslint.org/docs/rules/class-methods-use-this)
-
- ```javascript
- // bad
- class Foo {
- bar() {
- console.log('bar');
- }
- }
-
- // good - this is used
- class Foo {
- bar() {
- console.log(this.bar);
- }
- }
-
- // good - constructor is exempt
- class Foo {
- constructor() {
- // ...
- }
- }
-
- // good - static methods aren't expected to use this
- class Foo {
- static bar() {
- console.log('bar');
- }
+ bar() { return 2; }
}
- ```
+```
**[⬆ back to top](#table-of-contents)**
## Modules
+ [TODO] I don't have strong preferences on imports.
+
- [10.1](#modules--use-them) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system.
> Why? Modules are the future, let’s start using the future now.
- ```javascript
+```javascript
// bad
const AirbnbStyleGuide = require('./AirbnbStyleGuide');
module.exports = AirbnbStyleGuide.es6;
@@ -1309,27 +1241,27 @@ Other Style Guides
// best
import { es6 } from './AirbnbStyleGuide';
export default es6;
- ```
+```
- [10.2](#modules--no-wildcard) Do not use wildcard imports.
> Why? This makes sure you have a single default export.
- ```javascript
+```javascript
// bad
import * as AirbnbStyleGuide from './AirbnbStyleGuide';
// good
import AirbnbStyleGuide from './AirbnbStyleGuide';
- ```
+```
- [10.3](#modules--no-export-from-import) And do not export directly from an import.
> Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.
- ```javascript
+```javascript
// bad
// filename es6.js
export { es6 as default } from './AirbnbStyleGuide';
@@ -1338,14 +1270,14 @@ Other Style Guides
// filename es6.js
import { es6 } from './AirbnbStyleGuide';
export default es6;
- ```
+```
- [10.4](#modules--no-duplicate-imports) Only import from a path in one place.
eslint: [`no-duplicate-imports`](https://eslint.org/docs/rules/no-duplicate-imports)
> Why? Having multiple lines that import from the same path can make code harder to maintain.
- ```javascript
+```javascript
// bad
import foo from 'foo';
// … some other imports … //
@@ -1359,14 +1291,14 @@ Other Style Guides
named1,
named2,
} from 'foo';
- ```
+```
- [10.5](#modules--no-mutable-exports) Do not export mutable bindings.
eslint: [`import/no-mutable-exports`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md)
> Why? Mutation should be avoided in general, but in particular when exporting mutable bindings. While this technique may be needed for some special cases, in general, only constant references should be exported.
- ```javascript
+```javascript
// bad
let foo = 3;
export { foo };
@@ -1374,27 +1306,27 @@ Other Style Guides
// good
const foo = 3;
export { foo };
- ```
+```
- [10.6](#modules--prefer-default-export) In modules with a single export, prefer default export over named export.
eslint: [`import/prefer-default-export`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md)
> Why? To encourage more files that only ever export one thing, which is better for readability and maintainability.
- ```javascript
+```javascript
// bad
export function foo() {}
// good
export default function foo() {}
- ```
+```
- [10.7](#modules--imports-first) Put all `import`s above non-import statements.
eslint: [`import/first`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md)
> Why? Since `import`s are hoisted, keeping them all at the top prevents surprising behavior.
- ```javascript
+```javascript
// bad
import foo from 'foo';
foo.init();
@@ -1406,34 +1338,23 @@ Other Style Guides
import bar from 'bar';
foo.init();
- ```
+```
- - [10.8](#modules--multiline-imports-over-newlines) Multiline imports should be indented just like multiline array and object literals.
+ - [10.8](#modules--multiline-imports-over-newlines) Single line imports are ok.
eslint: [`object-curly-newline`](https://eslint.org/docs/rules/object-curly-newline)
- > Why? The curly braces follow the same indentation rules as every other curly brace block in the style guide, as do the trailing commas.
-
- ```javascript
- // bad
- import {longNameA, longNameB, longNameC, longNameD, longNameE} from 'path';
-
+```javascript
// good
- import {
- longNameA,
- longNameB,
- longNameC,
- longNameD,
- longNameE,
- } from 'path';
- ```
+ import {longNameA, longNameB, longNameC, longNameD, longNameE} from 'path';
+```
- [10.9](#modules--no-webpack-loader-syntax) Disallow Webpack loader syntax in module import statements.
eslint: [`import/no-webpack-loader-syntax`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md)
> Why? Since using Webpack syntax in the imports couples the code to a module bundler. Prefer using the loader syntax in `webpack.config.js`.
- ```javascript
+```javascript
// bad
import fooSass from 'css!sass!foo.scss';
import barCss from 'style!css!bar.css';
@@ -1441,14 +1362,14 @@ Other Style Guides
// good
import fooSass from 'foo.scss';
import barCss from 'bar.css';
- ```
+```
- [10.10](#modules--import-extensions) Do not include JavaScript filename extensions
eslint: [`import/extensions`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md)
> Why? Including extensions inhibits refactoring, and inappropriately hardcodes implementation details of the module you're importing in every consumer.
- ```javascript
+```javascript
// bad
import foo from './foo.js';
import bar from './bar.jsx';
@@ -1458,7 +1379,7 @@ Other Style Guides
import foo from './foo';
import bar from './bar';
import baz from './baz';
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -1471,20 +1392,20 @@ Other Style Guides
> Use `map()` / `every()` / `filter()` / `find()` / `findIndex()` / `reduce()` / `some()` / ... to iterate over arrays, and `Object.keys()` / `Object.values()` / `Object.entries()` to produce arrays so you can iterate over objects.
- ```javascript
+```javascript
const numbers = [1, 2, 3, 4, 5];
// bad
let sum = 0;
for (let num of numbers) {
- sum += num;
+ sum += num;
}
sum === 15;
// good
let sum = 0;
numbers.forEach((num) => {
- sum += num;
+ sum += num;
});
sum === 15;
@@ -1495,18 +1416,18 @@ Other Style Guides
// bad
const increasedByOne = [];
for (let i = 0; i < numbers.length; i++) {
- increasedByOne.push(numbers[i] + 1);
+ increasedByOne.push(numbers[i] + 1);
}
// good
const increasedByOne = [];
numbers.forEach((num) => {
- increasedByOne.push(num + 1);
+ increasedByOne.push(num + 1);
});
// best (keeping it functional)
const increasedByOne = numbers.map((num) => num + 1);
- ```
+```
- [11.2](#generators--nope) Don’t use generators for now.
@@ -1518,7 +1439,7 @@ Other Style Guides
> Why? `function` and `*` are part of the same conceptual keyword - `*` is not a modifier for `function`, `function*` is a unique construct, different from `function`.
- ```javascript
+```javascript
// bad
function * foo() {
// ...
@@ -1572,7 +1493,7 @@ Other Style Guides
const foo = function* () {
// ...
};
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -1581,10 +1502,10 @@ Other Style Guides
- [12.1](#properties--dot) Use dot notation when accessing properties. eslint: [`dot-notation`](https://eslint.org/docs/rules/dot-notation.html)
- ```javascript
+```javascript
const luke = {
- jedi: true,
- age: 28,
+ jedi: true,
+ age: 28,
};
// bad
@@ -1592,34 +1513,34 @@ Other Style Guides
// good
const isJedi = luke.jedi;
- ```
+```
- [12.2](#properties--bracket) Use bracket notation `[]` when accessing properties with a variable.
- ```javascript
+```javascript
const luke = {
- jedi: true,
- age: 28,
+ jedi: true,
+ age: 28,
};
function getProp(prop) {
- return luke[prop];
+ return luke[prop];
}
const isJedi = getProp('jedi');
- ```
+```
- [12.3](#es2016-properties--exponentiation-operator) Use exponentiation operator `**` when calculating exponentiations. eslint: [`no-restricted-properties`](https://eslint.org/docs/rules/no-restricted-properties).
- ```javascript
+```javascript
// bad
const binary = Math.pow(2, 10);
// good
const binary = 2 ** 10;
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -1628,20 +1549,20 @@ Other Style Guides
- [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
- ```javascript
+```javascript
// bad
superPower = new SuperPower();
// good
const superPower = new SuperPower();
- ```
+```
- [13.2](#variables--one-const) Use one `const` or `let` declaration per variable or assignment. eslint: [`one-var`](https://eslint.org/docs/rules/one-var.html)
> Why? It’s easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
- ```javascript
+```javascript
// bad
const items = getItems(),
goSportsTeam = true,
@@ -1657,14 +1578,16 @@ Other Style Guides
const items = getItems();
const goSportsTeam = true;
const dragonball = 'z';
- ```
+
+
+```
- [13.3](#variables--const-let-group) Group all your `const`s and then group all your `let`s.
> Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.
- ```javascript
+```javascript
// bad
let i, len, dragonball,
items = getItems(),
@@ -1683,53 +1606,53 @@ Other Style Guides
let dragonball;
let i;
let length;
- ```
+```
- [13.4](#variables--define-where-used) Assign variables where you need them, but place them in a reasonable place.
> Why? `let` and `const` are block scoped and not function scoped.
- ```javascript
+```javascript
// bad - unnecessary function call
function checkName(hasName) {
- const name = getName();
-
- if (hasName === 'test') {
- return false;
- }
-
- if (name === 'test') {
- this.setName('');
- return false;
- }
-
- return name;
+ const name = getName();
+
+ if (hasName === 'test') {
+ return false;
+ }
+
+ if (name === 'test') {
+ this.setName('');
+ return false;
+ }
+
+ return name;
}
// good
function checkName(hasName) {
- if (hasName === 'test') {
- return false;
- }
-
- const name = getName();
-
- if (name === 'test') {
- this.setName('');
- return false;
- }
-
- return name;
+ if (hasName === 'test') {
+ return false;
+ }
+
+ const name = getName();
+
+ if (name === 'test') {
+ this.setName('');
+ return false;
+ }
+
+ return name;
}
- ```
+```
- [13.5](#variables--no-chain-assignment) Don’t chain variable assignments. eslint: [`no-multi-assign`](https://eslint.org/docs/rules/no-multi-assign)
> Why? Chaining variable assignments creates implicit global variables.
- ```javascript
+```javascript
// bad
(function example() {
// JavaScript interprets this as
@@ -1755,48 +1678,14 @@ Other Style Guides
console.log(c); // throws ReferenceError
// the same applies for `const`
- ```
-
-
- - [13.6](#variables--unary-increment-decrement) Avoid using unary increments and decrements (`++`, `--`). eslint [`no-plusplus`](https://eslint.org/docs/rules/no-plusplus)
-
- > Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num++` or `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.
-
- ```javascript
- // bad
-
- const array = [1, 2, 3];
- let num = 1;
- num++;
- --num;
-
- let sum = 0;
- let truthyCount = 0;
- for (let i = 0; i < array.length; i++) {
- let value = array[i];
- sum += value;
- if (value) {
- truthyCount++;
- }
- }
-
- // good
-
- const array = [1, 2, 3];
- let num = 1;
- num += 1;
- num -= 1;
-
- const sum = array.reduce((a, b) => a + b, 0);
- const truthyCount = array.filter(Boolean).length;
- ```
+```
- [13.7](#variables--linebreak) Avoid linebreaks before or after `=` in an assignment. If your assignment violates [`max-len`](https://eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [`operator-linebreak`](https://eslint.org/docs/rules/operator-linebreak.html).
> Why? Linebreaks surrounding `=` can obfuscate the value of an assignment.
- ```javascript
+```javascript
// bad
const foo =
superLongLongLongLongLongLongLongLongFunctionName();
@@ -1812,14 +1701,14 @@ Other Style Guides
// good
const foo = 'superLongLongLongLongLongLongLongLongString';
- ```
+```
- [13.8](#variables--no-unused-vars) Disallow unused variables. eslint: [`no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars)
> Why? Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.
- ```javascript
+```javascript
// bad
var some_unused_var = 42;
@@ -1852,7 +1741,7 @@ Other Style Guides
// This is a form of extracting an object that omits the specified keys.
var { type, ...coords } = data;
// 'coords' is now the 'data' object without its 'type' property.
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -1861,11 +1750,11 @@ Other Style Guides
- [14.1](#hoisting--about) `var` declarations get hoisted to the top of their closest enclosing function scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone). It’s important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).
- ```javascript
+```javascript
// we know this wouldn’t work (assuming there
// is no notDefined global variable)
function example() {
- console.log(notDefined); // => throws a ReferenceError
+ console.log(notDefined); // => throws a ReferenceError
}
// creating a variable declaration after you
@@ -1873,83 +1762,83 @@ Other Style Guides
// variable hoisting. Note: the assignment
// value of `true` is not hoisted.
function example() {
- console.log(declaredButNotAssigned); // => undefined
- var declaredButNotAssigned = true;
+ console.log(declaredButNotAssigned); // => undefined
+ var declaredButNotAssigned = true;
}
// the interpreter is hoisting the variable
// declaration to the top of the scope,
// which means our example could be rewritten as:
function example() {
- let declaredButNotAssigned;
- console.log(declaredButNotAssigned); // => undefined
- declaredButNotAssigned = true;
+ let declaredButNotAssigned;
+ console.log(declaredButNotAssigned); // => undefined
+ declaredButNotAssigned = true;
}
// using const and let
function example() {
- console.log(declaredButNotAssigned); // => throws a ReferenceError
- console.log(typeof declaredButNotAssigned); // => throws a ReferenceError
- const declaredButNotAssigned = true;
+ console.log(declaredButNotAssigned); // => throws a ReferenceError
+ console.log(typeof declaredButNotAssigned); // => throws a ReferenceError
+ const declaredButNotAssigned = true;
}
- ```
+```
- [14.2](#hoisting--anon-expressions) Anonymous function expressions hoist their variable name, but not the function assignment.
- ```javascript
+```javascript
function example() {
- console.log(anonymous); // => undefined
+ console.log(anonymous); // => undefined
- anonymous(); // => TypeError anonymous is not a function
+ anonymous(); // => TypeError anonymous is not a function
- var anonymous = function () {
- console.log('anonymous function expression');
- };
+ var anonymous = function () {
+ console.log('anonymous function expression');
+ };
}
- ```
+```
- [14.3](#hoisting--named-expressions) Named function expressions hoist the variable name, not the function name or the function body.
- ```javascript
+```javascript
function example() {
- console.log(named); // => undefined
-
- named(); // => TypeError named is not a function
-
- superPower(); // => ReferenceError superPower is not defined
-
- var named = function superPower() {
- console.log('Flying');
- };
+ console.log(named); // => undefined
+
+ named(); // => TypeError named is not a function
+
+ superPower(); // => ReferenceError superPower is not defined
+
+ var named = function superPower() {
+ console.log('Flying');
+ };
}
// the same is true when the function name
// is the same as the variable name.
function example() {
- console.log(named); // => undefined
+ console.log(named); // => undefined
- named(); // => TypeError named is not a function
+ named(); // => TypeError named is not a function
- var named = function named() {
- console.log('named');
- };
+ var named = function named() {
+ console.log('named');
+ };
}
- ```
+```
- [14.4](#hoisting--declarations) Function declarations hoist their name and the function body.
- ```javascript
+```javascript
function example() {
- superPower(); // => Flying
+ superPower(); // => Flying
- function superPower() {
- console.log('Flying');
- }
+ function superPower() {
+ console.log('Flying');
+ }
}
- ```
+```
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
@@ -1970,17 +1859,17 @@ Other Style Guides
- **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**
- **Strings** evaluate to **false** if an empty string `''`, otherwise **true**
- ```javascript
+```javascript
if ([0] && []) {
// true
// an array (even an empty one) is an object, objects will evaluate to true
}
- ```
+```
- [15.3](#comparison--shortcuts) Use shortcuts for booleans, but explicit comparisons for strings and numbers.
- ```javascript
+```javascript
// bad
if (isValid === true) {
// ...
@@ -2010,7 +1899,7 @@ Other Style Guides
if (collection.length > 0) {
// ...
}
- ```
+```
- [15.4](#comparison--moreinfo) For more information see [Truth Equality and JavaScript](https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
@@ -2020,19 +1909,19 @@ Other Style Guides
> Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing.
- ```javascript
+```javascript
// bad
switch (foo) {
case 1:
- let x = 1;
- break;
+ let x = 1;
+ break;
case 2:
- const y = 2;
- break;
+ const y = 2;
+ break;
case 3:
- function f() {
- // ...
- }
+ function f() {
+ // ...
+ }
break;
default:
class C {}
@@ -2041,12 +1930,12 @@ Other Style Guides
// good
switch (foo) {
case 1: {
- let x = 1;
- break;
+ let x = 1;
+ break;
}
case 2: {
- const y = 2;
- break;
+ const y = 2;
+ break;
}
case 3: {
function f() {
@@ -2061,12 +1950,12 @@ Other Style Guides
class C {}
}
}
- ```
+```
- [15.6](#comparison--nested-ternaries) Ternaries should not be nested and generally be single line expressions. eslint: [`no-nested-ternary`](https://eslint.org/docs/rules/no-nested-ternary.html)
- ```javascript
+```javascript
// bad
const foo = maybe1 > maybe2
? "bar"
@@ -2082,12 +1971,12 @@ Other Style Guides
// best
const foo = maybe1 > maybe2 ? 'bar' : maybeNull;
- ```
+```
- [15.7](#comparison--unneeded-ternary) Avoid unneeded ternary statements. eslint: [`no-unneeded-ternary`](https://eslint.org/docs/rules/no-unneeded-ternary.html)
- ```javascript
+```javascript
// bad
const foo = a ? a : b;
const bar = c ? true : false;
@@ -2097,7 +1986,7 @@ Other Style Guides
const foo = a || b;
const bar = !!c;
const baz = !c;
- ```
+```
- [15.8](#comparison--no-mixed-operators) When mixing operators, enclose them in parentheses. The only exception is the standard arithmetic operators: `+`, `-`, and `**` since their precedence is broadly understood. We recommend enclosing `/` and `*` in parentheses because their precedence can be ambiguous when they are mixed.
@@ -2105,7 +1994,7 @@ Other Style Guides
> Why? This improves readability and clarifies the developer’s intention.
- ```javascript
+```javascript
// bad
const foo = a && b < 0 || c > 0 || d + 1 === 0;
@@ -2134,7 +2023,7 @@ Other Style Guides
// good
const bar = a + (b / c) * d;
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -2143,7 +2032,7 @@ Other Style Guides
- [16.1](#blocks--braces) Use braces with all multiline blocks. eslint: [`nonblock-statement-body-position`](https://eslint.org/docs/rules/nonblock-statement-body-position)
- ```javascript
+```javascript
// bad
if (test)
return false;
@@ -2163,61 +2052,61 @@ Other Style Guides
function bar() {
return false;
}
- ```
+```
- [16.2](#blocks--cuddled-elses) If you’re using multiline blocks with `if` and `else`, put `else` on the same line as your `if` block’s closing brace. eslint: [`brace-style`](https://eslint.org/docs/rules/brace-style.html)
- ```javascript
+```javascript
// bad
if (test) {
- thing1();
- thing2();
+ thing1();
+ thing2();
}
else {
- thing3();
+ thing3();
}
// good
if (test) {
- thing1();
- thing2();
+ thing1();
+ thing2();
} else {
- thing3();
+ thing3();
}
- ```
+```
- [16.3](#blocks--no-else-return) If an `if` block always executes a `return` statement, the subsequent `else` block is unnecessary. A `return` in an `else if` block following an `if` block that contains a `return` can be separated into multiple `if` blocks. eslint: [`no-else-return`](https://eslint.org/docs/rules/no-else-return)
- ```javascript
+```javascript
// bad
function foo() {
- if (x) {
- return x;
- } else {
- return y;
- }
+ if (x) {
+ return x;
+ } else {
+ return y;
+ }
}
// bad
function cats() {
- if (x) {
- return x;
- } else if (y) {
- return y;
- }
+ if (x) {
+ return x;
+ } else if (y) {
+ return y;
+ }
}
// bad
function dogs() {
- if (x) {
- return x;
- } else {
- if (y) {
- return y;
+ if (x) {
+ return x;
+ } else {
+ if (y) {
+ return y;
+ }
}
- }
}
// good
@@ -2231,26 +2120,26 @@ Other Style Guides
// good
function cats() {
- if (x) {
- return x;
- }
-
- if (y) {
- return y;
- }
+ if (x) {
+ return x;
+ }
+
+ if (y) {
+ return y;
+ }
}
-
+
// good
function dogs(x) {
- if (x) {
- if (z) {
- return y;
+ if (x) {
+ if (z) {
+ return y;
+ }
+ } else {
+ return z;
}
- } else {
- return z;
- }
}
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -2261,22 +2150,22 @@ Other Style Guides
> Why? Requiring operators at the beginning of the line keeps the operators aligned and follows a pattern similar to method chaining. This also improves readability by making it easier to visually follow complex logic.
- ```javascript
+```javascript
// bad
if ((foo === 123 || bar === 'abc') && doesItLookGoodWhenItBecomesThatLong() && isThisReallyHappening()) {
- thing1();
+ thing1();
}
// bad
if (foo === 123 &&
bar === 'abc') {
- thing1();
+ thing1();
}
// bad
if (foo === 123
&& bar === 'abc') {
- thing1();
+ thing1();
}
// bad
@@ -2284,15 +2173,15 @@ Other Style Guides
foo === 123 &&
bar === 'abc'
) {
- thing1();
+ thing1();
}
- // good
+ // ok
if (
foo === 123
&& bar === 'abc'
) {
- thing1();
+ thing1();
}
// good
@@ -2301,36 +2190,37 @@ Other Style Guides
&& doesItLookGoodWhenItBecomesThatLong()
&& isThisReallyHappening()
) {
- thing1();
+ thing1();
}
// good
if (foo === 123 && bar === 'abc') {
- thing1();
+ thing1();
}
- ```
+```
- [17.2](#control-statements--value-selection) Don't use selection operators in place of control statements.
- ```javascript
+```javascript
// bad
!isRunning && startRunning();
// good
if (!isRunning) {
- startRunning();
+ startRunning();
}
- ```
+```
**[⬆ back to top](#table-of-contents)**
## Comments
+ Comments are optional. The code should be self-documenting. If the code is confusing and needs comments to be understood, then Try refactoring the code before adding comments.
- [18.1](#comments--multiline) Use `/** ... */` for multiline comments.
- ```javascript
+```javascript
// bad
// make() returns a new element
// based on the passed in tag name
@@ -2355,12 +2245,12 @@ Other Style Guides
return element;
}
- ```
+```
- [18.2](#comments--singleline) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it’s on the first line of a block.
- ```javascript
+```javascript
// bad
const active = true; // is current tab
@@ -2370,36 +2260,36 @@ Other Style Guides
// bad
function getType() {
- console.log('fetching type...');
+ console.log('fetching type...');
// set the default type to 'no type'
- const type = this.type || 'no type';
+ const type = this.type || 'no type';
- return type;
+ return type;
}
// good
function getType() {
- console.log('fetching type...');
+ console.log('fetching type...');
- // set the default type to 'no type'
- const type = this.type || 'no type';
+ // set the default type to 'no type'
+ const type = this.type || 'no type';
- return type;
+ return type;
}
// also good
function getType() {
- // set the default type to 'no type'
- const type = this.type || 'no type';
+ // set the default type to 'no type'
+ const type = this.type || 'no type';
- return type;
+ return type;
}
- ```
+```
- [18.3](#comments--spaces) Start all comments with a space to make it easier to read. eslint: [`spaced-comment`](https://eslint.org/docs/rules/spaced-comment)
- ```javascript
+```javascript
// bad
//is current tab
const active = true;
@@ -2417,7 +2307,7 @@ Other Style Guides
// ...
- return element;
+ return element;
}
// good
@@ -2429,9 +2319,9 @@ Other Style Guides
// ...
- return element;
+ return element;
}
- ```
+```
- [18.4](#comments--actionitems) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you’re pointing out a problem that needs to be revisited, or if you’re suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME: -- need to figure this out` or `TODO: -- need to implement`.
@@ -2439,40 +2329,40 @@ Other Style Guides
- [18.5](#comments--fixme) Use `// FIXME:` to annotate problems.
- ```javascript
+```javascript
class Calculator extends Abacus {
- constructor() {
- super();
-
- // FIXME: shouldn’t use a global here
- total = 0;
- }
+ constructor() {
+ super();
+
+ // FIXME: shouldn’t use a global here
+ total = 0;
+ }
}
- ```
+```
- [18.6](#comments--todo) Use `// TODO:` to annotate solutions to problems.
- ```javascript
+```javascript
class Calculator extends Abacus {
- constructor() {
- super();
-
- // TODO: total should be configurable by an options param
- this.total = 0;
- }
+ constructor() {
+ super();
+
+ // TODO: total should be configurable by an options param
+ this.total = 0;
+ }
}
- ```
+```
**[⬆ back to top](#table-of-contents)**
## Whitespace
- - [19.1](#whitespace--spaces) Use soft tabs (space character) set to 2 spaces. eslint: [`indent`](https://eslint.org/docs/rules/indent.html)
+ - [19.1](#whitespace--spaces) Use soft tabs (space character) set to 4 spaces. eslint: [`indent`](https://eslint.org/docs/rules/indent.html)
- ```javascript
- // bad
+```javascript
+ // good
function foo() {
∙∙∙∙let name;
}
@@ -2482,105 +2372,105 @@ Other Style Guides
∙let name;
}
- // good
+ // bad
function baz() {
∙∙let name;
}
- ```
+```
- [19.2](#whitespace--before-blocks) Place 1 space before the leading brace. eslint: [`space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks.html)
- ```javascript
+```javascript
// bad
function test(){
- console.log('test');
+ console.log('test');
}
// good
function test() {
- console.log('test');
+ console.log('test');
}
// bad
dog.set('attr',{
- age: '1 year',
- breed: 'Bernese Mountain Dog',
+ age: '1 year',
+ breed: 'Bernese Mountain Dog',
});
// good
dog.set('attr', {
- age: '1 year',
- breed: 'Bernese Mountain Dog',
+ age: '1 year',
+ breed: 'Bernese Mountain Dog',
});
- ```
+```
- [19.3](#whitespace--around-keywords) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing.html)
- ```javascript
+```javascript
// bad
if(isJedi) {
- fight ();
+ fight ();
}
// good
if (isJedi) {
- fight();
+ fight();
}
// bad
function fight () {
- console.log ('Swooosh!');
+ console.log ('Swooosh!');
}
// good
function fight() {
- console.log('Swooosh!');
+ console.log('Swooosh!');
}
- ```
+```
- [19.4](#whitespace--infix-ops) Set off operators with spaces. eslint: [`space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops.html)
- ```javascript
+```javascript
// bad
const x=y+5;
// good
const x = y + 5;
- ```
+```
- [19.5](#whitespace--newline-at-end) End files with a single newline character. eslint: [`eol-last`](https://github.com/eslint/eslint/blob/master/docs/rules/eol-last.md)
- ```javascript
+```javascript
// bad
import { es6 } from './AirbnbStyleGuide';
// ...
export default es6;
- ```
+```
- ```javascript
+```javascript
// bad
import { es6 } from './AirbnbStyleGuide';
// ...
export default es6;↵
↵
- ```
+```
- ```javascript
+```javascript
// good
import { es6 } from './AirbnbStyleGuide';
// ...
export default es6;↵
- ```
+```
- [19.6](#whitespace--chains) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which
emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](https://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](https://eslint.org/docs/rules/no-whitespace-before-property)
- ```javascript
+```javascript
// bad
$('#items').find('.selected').highlight().end().find('.open').updateCount();
@@ -2618,21 +2508,21 @@ Other Style Guides
// good
const leds = stage.selectAll('.led').data(data);
- ```
+```
- [19.7](#whitespace--after-blocks) Leave a blank line after blocks and before the next statement.
- ```javascript
+```javascript
// bad
if (foo) {
- return bar;
+ return bar;
}
return baz;
// good
if (foo) {
- return bar;
+ return bar;
}
return baz;
@@ -2676,12 +2566,12 @@ Other Style Guides
];
return arr;
- ```
+```
- [19.8](#whitespace--padded-blocks) Do not pad your blocks with blank lines. eslint: [`padded-blocks`](https://eslint.org/docs/rules/padded-blocks.html)
- ```javascript
+```javascript
// bad
function bar() {
@@ -2702,49 +2592,49 @@ Other Style Guides
class Foo {
constructor(bar) {
- this.bar = bar;
+ this.bar = bar;
}
}
// good
function bar() {
- console.log(foo);
+ console.log(foo);
}
// good
if (baz) {
- console.log(qux);
+ console.log(qux);
} else {
- console.log(foo);
+ console.log(foo);
}
- ```
+```
- [19.9](#whitespace--no-multiple-blanks) Do not use multiple blank lines to pad your code. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines)
- ```javascript
+```javascript
// bad
class Person {
constructor(fullName, email, birthday) {
- this.fullName = fullName;
+ this.fullName = fullName;
- this.email = email;
+ this.email = email;
- this.setAge(birthday);
+ this.setAge(birthday);
}
setAge(birthday) {
- const today = new Date();
-
-
- const age = this.getAge(today, birthday);
-
-
- this.age = age;
+ const today = new Date();
+
+
+ const age = this.getAge(today, birthday);
+
+
+ this.age = age;
}
@@ -2755,53 +2645,53 @@ Other Style Guides
// good
class Person {
- constructor(fullName, email, birthday) {
- this.fullName = fullName;
- this.email = email;
- this.setAge(birthday);
- }
-
- setAge(birthday) {
- const today = new Date();
- const age = getAge(today, birthday);
- this.age = age;
- }
-
- getAge(today, birthday) {
- // ..
- }
+ constructor(fullName, email, birthday) {
+ this.fullName = fullName;
+ this.email = email;
+ this.setAge(birthday);
+ }
+
+ setAge(birthday) {
+ const today = new Date();
+ const age = getAge(today, birthday);
+ this.age = age;
+ }
+
+ getAge(today, birthday) {
+ // ..
+ }
}
- ```
+```
- [19.10](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](https://eslint.org/docs/rules/space-in-parens.html)
- ```javascript
+```javascript
// bad
function bar( foo ) {
- return foo;
+ return foo;
}
// good
function bar(foo) {
- return foo;
+ return foo;
}
// bad
if ( foo ) {
- console.log(foo);
+ console.log(foo);
}
// good
if (foo) {
- console.log(foo);
+ console.log(foo);
}
- ```
+```
- [19.11](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](https://eslint.org/docs/rules/array-bracket-spacing.html)
- ```javascript
+```javascript
// bad
const foo = [ 1, 2, 3 ];
console.log(foo[ 0 ]);
@@ -2809,25 +2699,25 @@ Other Style Guides
// good
const foo = [1, 2, 3];
console.log(foo[0]);
- ```
+```
- [19.12](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing.html)
- ```javascript
+```javascript
// bad
const foo = {clark: 'kent'};
// good
const foo = { clark: 'kent' };
- ```
+```
- [19.13](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html)
> Why? This ensures readability and maintainability.
- ```javascript
+```javascript
// bad
const foo = jsonData && jsonData.foo && jsonData.foo.bar && jsonData.foo.bar.baz && jsonData.foo.bar.baz.quux && jsonData.foo.bar.baz.quux.xyzzy;
@@ -2850,12 +2740,12 @@ Other Style Guides
})
.done(() => console.log('Congratulations!'))
.fail(() => console.log('You have failed this city.'));
- ```
+```
- [19.14](#whitespace--block-spacing) Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [`block-spacing`](https://eslint.org/docs/rules/block-spacing)
- ```javascript
+```javascript
// bad
function foo() {return true;}
if (foo) { bar = 0;}
@@ -2863,12 +2753,12 @@ Other Style Guides
// good
function foo() { return true; }
if (foo) { bar = 0; }
- ```
+```
- [19.15](#whitespace--comma-spacing) Avoid spaces before commas and require a space after commas. eslint: [`comma-spacing`](https://eslint.org/docs/rules/comma-spacing)
- ```javascript
+```javascript
// bad
var foo = 1,bar = 2;
var arr = [1 , 2];
@@ -2876,12 +2766,12 @@ Other Style Guides
// good
var foo = 1, bar = 2;
var arr = [1, 2];
- ```
+```
- [19.16](#whitespace--computed-property-spacing) Enforce spacing inside of computed property brackets. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing)
- ```javascript
+```javascript
// bad
obj[foo ]
obj[ 'foo']
@@ -2893,12 +2783,12 @@ Other Style Guides
obj['foo']
var x = { [b]: a }
obj[foo[bar]]
- ```
+```
- [19.17](#whitespace--func-call-spacing) Avoid spaces between functions and their invocations. eslint: [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing)
- ```javascript
+```javascript
// bad
func ();
@@ -2907,19 +2797,19 @@ Other Style Guides
// good
func();
- ```
+```
- [19.18](#whitespace--key-spacing) Enforce spacing between keys and values in object literal properties. eslint: [`key-spacing`](https://eslint.org/docs/rules/key-spacing)
- ```javascript
+```javascript
// bad
var obj = { foo : 42 };
var obj2 = { foo:42 };
// good
var obj = { foo: 42 };
- ```
+```
- [19.19](#whitespace--no-trailing-spaces) Avoid trailing spaces at the end of lines. eslint: [`no-trailing-spaces`](https://eslint.org/docs/rules/no-trailing-spaces)
@@ -2928,7 +2818,7 @@ Other Style Guides
- [19.20](#whitespace--no-multiple-empty-lines) Avoid multiple empty lines, only allow one newline at the end of files, and avoid a newline at the beginning of files. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines)
- ```javascript
+```javascript
// bad - multiple empty lines
var x = 1;
@@ -2949,7 +2839,7 @@ Other Style Guides
var x = 1;
var y = 2;
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -2959,7 +2849,7 @@ Other Style Guides
- [20.1](#commas--leading-trailing) Leading commas: **Nope.** eslint: [`comma-style`](https://eslint.org/docs/rules/comma-style.html)
- ```javascript
+```javascript
// bad
const story = [
once
@@ -2987,56 +2877,37 @@ Other Style Guides
firstName: 'Ada',
lastName: 'Lovelace',
birthYear: 1815,
- superPower: 'computers',
+ superPower: 'computers'
};
- ```
+```
- - [20.2](#commas--dangling) Additional trailing comma: **Yup.** eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html)
-
- > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don’t have to worry about the [trailing comma problem](https://github.com/airbnb/javascript/blob/es5-deprecated/es5/README.md#commas) in legacy browsers.
-
- ```diff
- // bad - git diff without trailing comma
- const hero = {
- firstName: 'Florence',
- - lastName: 'Nightingale'
- + lastName: 'Nightingale',
- + inventorOf: ['coxcomb chart', 'modern nursing']
- };
-
- // good - git diff with trailing comma
- const hero = {
- firstName: 'Florence',
- lastName: 'Nightingale',
- + inventorOf: ['coxcomb chart', 'modern nursing'],
- };
- ```
+ - [20.2](#commas--dangling) Never add additional trailing comma: No eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html)
- ```javascript
- // bad
+```javascript
+ // good
const hero = {
- firstName: 'Dana',
- lastName: 'Scully'
+ firstName: 'Dana',
+ lastName: 'Scully'
};
const heroes = [
- 'Batman',
- 'Superman'
+ 'Batman',
+ 'Superman'
];
- // good
+ // bad
const hero = {
- firstName: 'Dana',
- lastName: 'Scully',
+ firstName: 'Dana',
+ lastName: 'Scully',
};
const heroes = [
- 'Batman',
- 'Superman',
+ 'Batman',
+ 'Superman',
];
- // bad
+ // good
function createHero(
firstName,
lastName,
@@ -3045,47 +2916,47 @@ Other Style Guides
// does nothing
}
- // good
+ // bad
function createHero(
- firstName,
- lastName,
- inventorOf,
+ firstName,
+ lastName,
+ inventorOf,
) {
// does nothing
}
// good (note that a comma must not appear after a "rest" element)
function createHero(
- firstName,
- lastName,
- inventorOf,
- ...heroArgs
+ firstName,
+ lastName,
+ inventorOf,
+ ...heroArgs
) {
// does nothing
}
// bad
createHero(
- firstName,
- lastName,
- inventorOf
+ firstName,
+ lastName,
+ inventorOf
);
- // good
+ // bad
createHero(
- firstName,
- lastName,
- inventorOf,
+ firstName,
+ lastName,
+ inventorOf,
);
// good (note that a comma must not appear after a "rest" element)
createHero(
- firstName,
- lastName,
- inventorOf,
- ...heroArgs
+ firstName,
+ lastName,
+ inventorOf,
+ ...heroArgs
);
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -3096,7 +2967,7 @@ Other Style Guides
> Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called [Automatic Semicolon Insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) to determine whether or not it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues.
- ```javascript
+```javascript
// bad - raises exception
const luke = {}
const leia = {}
@@ -3133,7 +3004,7 @@ Other Style Guides
function foo() {
return 'search your feelings, you know it to be foo';
}
- ```
+```
[Read more](https://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214#7365214).
@@ -3147,7 +3018,7 @@ Other Style Guides
- [22.2](#coercion--strings) Strings: eslint: [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
- ```javascript
+```javascript
// => this.reviewScore = 9;
// bad
@@ -3161,12 +3032,12 @@ Other Style Guides
// good
const totalScore = String(this.reviewScore);
- ```
+```
- [22.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](https://eslint.org/docs/rules/radix) [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
- ```javascript
+```javascript
const inputValue = '4';
// bad
@@ -3186,12 +3057,12 @@ Other Style Guides
// good
const val = parseInt(inputValue, 10);
- ```
+```
- [22.4](#coercion--comment-deviations) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](https://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you’re doing.
- ```javascript
+```javascript
// good
/**
* parseInt was the reason my code was slow.
@@ -3199,21 +3070,21 @@ Other Style Guides
* Number made it a lot faster.
*/
const val = inputValue >> 0;
- ```
+```
- [22.5](#coercion--bitwise) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](https://es5.github.io/#x4.3.19), but bitshift operations always return a 32-bit integer ([source](https://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:
- ```javascript
+```javascript
2147483647 >> 0; // => 2147483647
2147483648 >> 0; // => -2147483648
2147483649 >> 0; // => -2147483647
- ```
+```
- [22.6](#coercion--booleans) Booleans: eslint: [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
- ```javascript
+```javascript
const age = 0;
// bad
@@ -3224,7 +3095,7 @@ Other Style Guides
// best
const hasAge = !!age;
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -3233,7 +3104,7 @@ Other Style Guides
- [23.1](#naming--descriptive) Avoid single letter names. Be descriptive with your naming. eslint: [`id-length`](https://eslint.org/docs/rules/id-length)
- ```javascript
+```javascript
// bad
function q() {
// ...
@@ -3243,12 +3114,12 @@ Other Style Guides
function query() {
// ...
}
- ```
+```
- [23.2](#naming--camelCase) Use camelCase when naming objects, functions, and instances. eslint: [`camelcase`](https://eslint.org/docs/rules/camelcase.html)
- ```javascript
+```javascript
// bad
const OBJEcttsssss = {};
const this_is_my_object = {};
@@ -3257,85 +3128,79 @@ Other Style Guides
// good
const thisIsMyObject = {};
function thisIsMyFunction() {}
- ```
+```
- [23.3](#naming--PascalCase) Use PascalCase only when naming constructors or classes. eslint: [`new-cap`](https://eslint.org/docs/rules/new-cap.html)
- ```javascript
+```javascript
// bad
function user(options) {
- this.name = options.name;
+ this.name = options.name;
}
const bad = new user({
- name: 'nope',
+ name: 'nope',
});
// good
class User {
- constructor(options) {
- this.name = options.name;
- }
+ constructor(options) {
+ this.name = options.name;
+ }
}
const good = new User({
- name: 'yup',
+ name: 'yup',
});
- ```
+```
- - [23.4](#naming--leading-underscore) Do not use trailing or leading underscores. eslint: [`no-underscore-dangle`](https://eslint.org/docs/rules/no-underscore-dangle.html)
+ - [23.4](#naming--leading-underscore)
+ leading _ on names.
- > Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won’t count as breaking, or that tests aren’t needed. tl;dr: if you want something to be “private”, it must not be observably present.
+```javascript
+ // Ok, but know this is not actually private.
+ function _iAmPrivate() {
- ```javascript
- // bad
- this.__firstName__ = 'Panda';
- this.firstName_ = 'Panda';
- this._firstName = 'Panda';
-
- // good
- this.firstName = 'Panda';
+ }
+ // OK
+ this._private
- // good, in environments where WeakMaps are available
- // see https://kangax.github.io/compat-table/es6/#test-WeakMap
- const firstNames = new WeakMap();
- firstNames.set(this, 'Panda');
- ```
+```
- [23.5](#naming--self-this) Don’t save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
- ```javascript
+```javascript
// bad
function foo() {
- const self = this;
- return function () {
- console.log(self);
- };
+ const self = this;
+ return function () {
+ console.log(self);
+ };
}
// bad
function foo() {
- const that = this;
- return function () {
- console.log(that);
- };
+ const that = this;
+ return function () {
+ console.log(that);
+ };
}
// good
function foo() {
- return () => {
- console.log(this);
- };
+ return () => {
+ console.log(this);
+ };
}
- ```
+```
- [23.6](#naming--filename-matches-export) A base filename should exactly match the name of its default export.
- ```javascript
+```javascript
// file 1 contents
class CheckBox {
// ...
@@ -3366,37 +3231,37 @@ Other Style Guides
import fortyTwo from './fortyTwo'; // camelCase export/import/filename
import insideDirectory from './insideDirectory'; // camelCase export/import/directory name/implicit "index"
// ^ supports both insideDirectory.js and insideDirectory/index.js
- ```
+```
- [23.7](#naming--camelCase-default-export) Use camelCase when you export-default a function. Your filename should be identical to your function’s name.
- ```javascript
+```javascript
function makeStyleGuide() {
// ...
}
export default makeStyleGuide;
- ```
+```
- [23.8](#naming--PascalCase-singleton) Use PascalCase when you export a constructor / class / singleton / function library / bare object.
- ```javascript
- const AirbnbStyleGuide = {
- es6: {
- },
+```javascript
+ const UnearthStyleGuide = {
+ es6: {
+ },
};
- export default AirbnbStyleGuide;
- ```
+ export default UnearthStyleGuide;
+```
- [23.9](#naming--Acronyms-and-Initialisms) Acronyms and initialisms should always be all uppercased, or all lowercased.
> Why? Names are for readability, not to appease a computer algorithm.
- ```javascript
+```javascript
// bad
import SmsContainer from './containers/SmsContainer';
@@ -3425,7 +3290,7 @@ Other Style Guides
const requests = [
// ...
];
- ```
+```
- [23.10](#naming--uppercase) You may optionally uppercase a constant only if it (1) is exported, (2) is a `const` (it can not be reassigned), and (3) the programmer can trust it (and its nested properties) to never change.
@@ -3434,7 +3299,7 @@ Other Style Guides
- What about all `const` variables? - This is unnecessary, so uppercasing should not be used for constants within a file. It should be used for exported constants however.
- What about exported objects? - Uppercase at the top level of export (e.g. `EXPORTED_OBJECT.key`) and maintain that all nested properties do not change.
- ```javascript
+```javascript
// bad
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';
@@ -3463,7 +3328,7 @@ Other Style Guides
export const MAPPING = {
key: 'value'
};
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -3475,64 +3340,64 @@ Other Style Guides
- [24.2](#accessors--no-getters-setters) Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use `getVal()` and `setVal('hello')`.
- ```javascript
+```javascript
// bad
class Dragon {
- get age() {
- // ...
- }
-
- set age(value) {
- // ...
- }
+ get age() {
+ // ...
+ }
+
+ set age(value) {
+ // ...
+ }
}
// good
class Dragon {
- getAge() {
- // ...
- }
-
- setAge(value) {
- // ...
- }
+ getAge() {
+ // ...
+ }
+
+ setAge(value) {
+ // ...
+ }
}
- ```
+```
- [24.3](#accessors--boolean-prefix) If the property/method is a `boolean`, use `isVal()` or `hasVal()`.
- ```javascript
+```javascript
// bad
if (!dragon.age()) {
- return false;
+ return false;
}
-
+
// good
if (!dragon.hasAge()) {
- return false;
+ return false;
}
- ```
+```
- [24.4](#accessors--consistent) It’s okay to create `get()` and `set()` functions, but be consistent.
- ```javascript
+```javascript
class Jedi {
- constructor(options = {}) {
- const lightsaber = options.lightsaber || 'blue';
- this.set('lightsaber', lightsaber);
- }
-
- set(key, val) {
- this[key] = val;
- }
-
- get(key) {
- return this[key];
- }
+ constructor(options = {}) {
+ const lightsaber = options.lightsaber || 'blue';
+ this.set('lightsaber', lightsaber);
+ }
+
+ set(key, val) {
+ this[key] = val;
+ }
+
+ get(key) {
+ return this[key];
+ }
}
- ```
+```
**[⬆ back to top](#table-of-contents)**
@@ -3541,7 +3406,7 @@ Other Style Guides
- [25.1](#events--hash) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass an object literal (also known as a "hash") instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:
- ```javascript
+```javascript
// bad
$(this).trigger('listingUpdated', listing.id);
@@ -3550,11 +3415,11 @@ Other Style Guides
$(this).on('listingUpdated', (e, listingID) => {
// do something with listingID
});
- ```
+```
prefer:
- ```javascript
+```javascript
// good
$(this).trigger('listingUpdated', { listingID: listing.id });
@@ -3563,111 +3428,12 @@ Other Style Guides
$(this).on('listingUpdated', (e, data) => {
// do something with data.listingID
});
- ```
+```
**[⬆ back to top](#table-of-contents)**
## jQuery
-
-
- - [26.1](#jquery--dollar-prefix) Prefix jQuery object variables with a `$`.
-
- ```javascript
- // bad
- const sidebar = $('.sidebar');
-
- // good
- const $sidebar = $('.sidebar');
-
- // good
- const $sidebarBtn = $('.sidebar-btn');
- ```
-
-
- - [26.2](#jquery--cache) Cache jQuery lookups.
-
- ```javascript
- // bad
- function setSidebar() {
- $('.sidebar').hide();
-
- // ...
-
- $('.sidebar').css({
- 'background-color': 'pink',
- });
- }
-
- // good
- function setSidebar() {
- const $sidebar = $('.sidebar');
- $sidebar.hide();
-
- // ...
-
- $sidebar.css({
- 'background-color': 'pink',
- });
- }
- ```
-
-
- - [26.3](#jquery--queries) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
-
-
- - [26.4](#jquery--find) Use `find` with scoped jQuery object queries.
-
- ```javascript
- // bad
- $('ul', '.sidebar').hide();
-
- // bad
- $('.sidebar').find('ul').hide();
-
- // good
- $('.sidebar ul').hide();
-
- // good
- $('.sidebar > ul').hide();
-
- // good
- $sidebar.find('ul').hide();
- ```
-
-**[⬆ back to top](#table-of-contents)**
-
-## ECMAScript 5 Compatibility
-
-
- - [27.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)’s ES5 [compatibility table](https://kangax.github.io/es5-compat-table/).
-
-**[⬆ back to top](#table-of-contents)**
-
-
-## ECMAScript 6+ (ES 2015+) Styles
-
-
- - [28.1](#es6-styles) This is a collection of links to the various ES6+ features.
-
-1. [Arrow Functions](#arrow-functions)
-1. [Classes](#classes--constructors)
-1. [Object Shorthand](#es6-object-shorthand)
-1. [Object Concise](#es6-object-concise)
-1. [Object Computed Properties](#es6-computed-properties)
-1. [Template Strings](#es6-template-literals)
-1. [Destructuring](#destructuring)
-1. [Default Parameters](#es6-default-parameters)
-1. [Rest](#es6-rest)
-1. [Array Spreads](#es6-array-spreads)
-1. [Let and Const](#references)
-1. [Exponentiation Operator](#es2016-properties--exponentiation-operator)
-1. [Iterators and Generators](#iterators-and-generators)
-1. [Modules](#modules)
-
-
- - [28.2](#tc39-proposals) Do not use [TC39 proposals](https://github.com/tc39/proposals) that have not reached stage 3.
-
- > Why? [They are not finalized](https://tc39.github.io/process-document/), and they are subject to change or to be withdrawn entirely. We want to use JavaScript, and proposals are not JavaScript yet.
+### Prefer VanillaJS
**[⬆ back to top](#table-of-contents)**
@@ -3683,7 +3449,7 @@ Other Style Guides
> Why? The global `isNaN` coerces non-numbers to numbers, returning true for anything that coerces to NaN.
> If this behavior is desired, make it explicit.
- ```javascript
+```javascript
// bad
isNaN('1.2'); // false
isNaN('1.2.3'); // true
@@ -3691,7 +3457,7 @@ Other Style Guides
// good
Number.isNaN('1.2.3'); // false
Number.isNaN(Number('1.2.3')); // true
- ```
+```
- [29.2](#standard-library--isfinite) Use `Number.isFinite` instead of global `isFinite`.
@@ -3700,36 +3466,23 @@ Other Style Guides
> Why? The global `isFinite` coerces non-numbers to numbers, returning true for anything that coerces to a finite number.
> If this behavior is desired, make it explicit.
- ```javascript
+```javascript
// bad
isFinite('2e3'); // true
// good
Number.isFinite('2e3'); // false
Number.isFinite(parseInt('2e3', 10)); // true
- ```
+```
**[⬆ back to top](#table-of-contents)**
## Testing
- - [30.1](#testing--yup) **Yup.**
-
- ```javascript
- function foo() {
- return true;
- }
- ```
+ - [30.1](#testing--yup)
-
- - [30.2](#testing--for-real) **No, but seriously**:
- - Whichever testing framework you use, you should be writing tests!
- - Strive to write many small pure functions, and minimize where mutations occur.
- - Be cautious about stubs and mocks - they can make your tests more brittle.
- - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) and [`jest`](https://www.npmjs.com/package/jest) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.
- - 100% test coverage is a good goal to strive for, even if it’s not always practical to reach it.
- - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.
+ [TODO] Mike i'd like your thoughts on best practices here.
**[⬆ back to top](#table-of-contents)**
@@ -3828,144 +3581,6 @@ Other Style Guides
**[⬆ back to top](#table-of-contents)**
-## In the Wild
-
- This is a list of organizations that are using this style guide. Send us a pull request and we'll add you to the list.
-
- - **123erfasst**: [123erfasst/javascript](https://github.com/123erfasst/javascript)
- - **3blades**: [3Blades](https://github.com/3blades)
- - **4Catalyzer**: [4Catalyzer/javascript](https://github.com/4Catalyzer/javascript)
- - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
- - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript)
- - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
- - **AltSchool**: [AltSchool/javascript](https://github.com/AltSchool/javascript)
- - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)
- - **Ascribe**: [ascribe/javascript](https://github.com/ascribe/javascript)
- - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)
- - **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript)
- - **Axept**: [axept/javascript](https://github.com/axept/javascript)
- - **BashPros**: [BashPros/javascript](https://github.com/BashPros/javascript)
- - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
- - **Bisk**: [bisk](https://github.com/Bisk/)
- - **Bonhomme**: [bonhommeparis/javascript](https://github.com/bonhommeparis/javascript)
- - **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript)
- - **CaseNine**: [CaseNine/javascript](https://github.com/CaseNine/javascript)
- - **Cerner**: [Cerner](https://github.com/cerner/)
- - **Chartboost**: [ChartBoost/javascript-style-guide](https://github.com/ChartBoost/javascript-style-guide)
- - **Coeur d'Alene Tribe**: [www.cdatribe-nsn.gov](https://www.cdatribe-nsn.gov)
- - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)
- - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
- - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)
- - **DoSomething**: [DoSomething/eslint-config](https://github.com/DoSomething/eslint-config)
- - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)
- - **Drupal**: [www.drupal.org](https://www.drupal.org/project/drupal)
- - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript)
- - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide)
- - **Evolution Gaming**: [evolution-gaming/javascript](https://github.com/evolution-gaming/javascript)
- - **EvozonJs**: [evozonjs/javascript](https://github.com/evozonjs/javascript)
- - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
- - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md)
- - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide)
- - **Gawker Media**: [gawkermedia](https://github.com/gawkermedia/)
- - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
- - **Generation Tux**: [GenerationTux/javascript](https://github.com/generationtux/styleguide)
- - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
- - **GreenChef**: [greenchef/javascript](https://github.com/greenchef/javascript)
- - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
- - **Grupo-Abraxas**: [Grupo-Abraxas/javascript](https://github.com/Grupo-Abraxas/javascript)
- - **Happeo**: [happeo/javascript](https://github.com/happeo/javascript)
- - **Honey**: [honeyscience/javascript](https://github.com/honeyscience/javascript)
- - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)
- - **Huballin**: [huballin](https://github.com/huballin/)
- - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)
- - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)
- - **InterCity Group**: [intercitygroup/javascript-style-guide](https://github.com/intercitygroup/javascript-style-guide)
- - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)
- - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md)
- - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
- - **Kaplan Komputing**: [kaplankomputing/javascript](https://github.com/kaplankomputing/javascript)
- - **KickorStick**: [kickorstick](https://github.com/kickorstick/)
- - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)
- - **LEINWAND**: [LEINWAND/javascript](https://github.com/LEINWAND/javascript)
- - **Lonely Planet**: [lonelyplanet/javascript](https://github.com/lonelyplanet/javascript)
- - **M2GEN**: [M2GEN/javascript](https://github.com/M2GEN/javascript)
- - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
- - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
- - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)
- - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
- - **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript)
- - **Muber**: [muber](https://github.com/muber/)
- - **National Geographic**: [natgeo](https://github.com/natgeo/)
- - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)
- - **NullDev**: [NullDevCo/JavaScript-Styleguide](https://github.com/NullDevCo/JavaScript-Styleguide)
- - **Nulogy**: [nulogy/javascript](https://github.com/nulogy/javascript)
- - **Orange Hill Development**: [orangehill/javascript](https://github.com/orangehill/javascript)
- - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript)
- - **OutBoxSoft**: [OutBoxSoft/javascript](https://github.com/OutBoxSoft/javascript)
- - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)
- - **Pier 1**: [Pier1/javascript](https://github.com/pier1/javascript)
- - **Qotto**: [Qotto/javascript-style-guide](https://github.com/Qotto/javascript-style-guide)
- - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
- - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)
- - **React**: [facebook.github.io/react/contributing/how-to-contribute.html#style-guide](https://facebook.github.io/react/contributing/how-to-contribute.html#style-guide)
- - **REI**: [reidev/js-style-guide](https://github.com/rei/code-style-guides/)
- - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)
- - **Sainsbury’s Supermarkets**: [jsainsburyplc](https://github.com/jsainsburyplc)
- - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
- - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
- - **Sourcetoad**: [sourcetoad/javascript](https://github.com/sourcetoad/javascript)
- - **Springload**: [springload](https://github.com/springload/)
- - **StratoDem Analytics**: [stratodem/javascript](https://github.com/stratodem/javascript)
- - **SteelKiwi Development**: [steelkiwi/javascript](https://github.com/steelkiwi/javascript)
- - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)
- - **SwoopApp**: [swoopapp/javascript](https://github.com/swoopapp/javascript)
- - **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide)
- - **Syzygy Warsaw**: [syzygypl/javascript](https://github.com/syzygypl/javascript)
- - **Target**: [target/javascript](https://github.com/target/javascript)
- - **Terra**: [terra](https://github.com/cerner?utf8=%E2%9C%93&q=terra&type=&language=)
- - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)
- - **The Nerdery**: [thenerdery/javascript-standards](https://github.com/thenerdery/javascript-standards)
- - **Tomify**: [tomprats](https://github.com/tomprats)
- - **Traitify**: [traitify/eslint-config-traitify](https://github.com/traitify/eslint-config-traitify)
- - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)
- - **UrbanSim**: [urbansim](https://github.com/urbansim/)
- - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide)
- - **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript)
- - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript)
- - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
- - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)
-
-**[⬆ back to top](#table-of-contents)**
-
-## Translation
-
- This style guide is also available in other languages:
-
- -  **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
- -  **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript)
- -  **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide)
- -  **Chinese (Simplified)**: [lin-123/javascript](https://github.com/lin-123/javascript)
- -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript)
- -  **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)
- -  **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
- -  **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide)
- -  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide)
- -  **Korean**: [ParkSB/javascript-style-guide](https://github.com/ParkSB/javascript-style-guide)
- -  **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb)
- -  **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
- -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide)
- -  **Turkish**: [eraycetinay/javascript](https://github.com/eraycetinay/javascript)
- -  **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript)
- -  **Vietnam**: [dangkyokhoang/javascript-style-guide](https://github.com/dangkyokhoang/javascript-style-guide)
-
-## The JavaScript Style Guide Guide
-
- - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)
-
-## Chat With Us About JavaScript
-
- - Find us on [gitter](https://gitter.im/airbnb/javascript).
-
## Contributors
- [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)
diff --git a/mithril/README.md b/mithril/README.md
new file mode 100644
index 0000000000..67aadc1f23
--- /dev/null
+++ b/mithril/README.md
@@ -0,0 +1,53 @@
+# Unearth Mithril.js guide
+
+*A mostly reasonable approach to Mithril and JSX*
+
+## Table of Contents
+
+ 1. [Basic Rules](#basic-rules)
+ 1. [Models](#models)
+
+
+## Basic Rules
+ - Split code by view and model.
+ - Only one model per file.
+ - Multiple components are allowed in a single file. (Don't abuse this)
+
+## Models
+ [2.1](models) General
+
+ The model is tied to a view or views. The Model is used to execute logic and hold state for the view it is tied to.
+
+ **[⬆ back to top](#table-of-contents)**
+ [2.2](models) Use classes.
+ > Why? It is easier to refactor the model to support multiple instances if the model is already a class.
+```javascript
+ // bad
+ const model = {
+ init() {
+ // do init
+ }
+ }
+
+ export default model;
+
+ // good
+ class Model {
+ init() {
+
+ }
+ }
+
+ export default new Model();
+
+ // good
+ class Model {
+ init() {
+
+ }
+ }
+
+ export default Model;
+```
+
+**[⬆ back to top](#table-of-contents)**
diff --git a/package.json b/package.json
index 36b4e19fab..3c468b4708 100644
--- a/package.json
+++ b/package.json
@@ -1,25 +1,13 @@
{
- "name": "airbnb-style",
+ "name": "unearth-style",
"version": "2.0.0",
- "description": "A mostly reasonable approach to JavaScript.",
+ "description": "Unearth's version of a mostly reasonable approach to JavaScript.",
"scripts": {
- "preinstall": "npm run install:config && npm run install:config:base",
- "postinstall": "rm -rf node_modules/markdownlint-cli/node_modules/markdownlint",
- "install:config": "cd packages/eslint-config-airbnb && npm prune && npm install",
- "install:config:base": "cd packages/eslint-config-airbnb-base && npm prune && npm install",
- "lint": "markdownlint --config linters/.markdownlint.json README.md */README.md",
- "pretest": "npm run --silent lint",
- "test": "npm run --silent test:config && npm run --silent test:config:base",
- "test:config": "cd packages/eslint-config-airbnb; npm test",
- "test:config:base": "cd packages/eslint-config-airbnb-base; npm test",
- "pretravis": "npm run --silent lint",
- "travis": "npm run --silent travis:config && npm run --silent travis:config:base",
- "travis:config": "cd packages/eslint-config-airbnb; npm run travis",
- "travis:config:base": "cd packages/eslint-config-airbnb-base; npm run travis"
+
},
"repository": {
"type": "git",
- "url": "https://github.com/airbnb/javascript.git"
+ "url": "https://github.com/unearth-inc/javascript.git"
},
"keywords": [
"style guide",
@@ -34,11 +22,11 @@
"jsx"
],
"author": "Harrison Shoff (https://twitter.com/hshoff)",
+ "contributors": [
+ "Jordan Koszarek "
+ ],
"license": "MIT",
- "bugs": {
- "url": "https://github.com/airbnb/javascript/issues"
- },
- "homepage": "https://github.com/airbnb/javascript",
+ "homepage": "https://github.com/unearth-inc/javascript",
"devDependencies": {
"markdownlint": "^0.19.0",
"markdownlint-cli": "^0.21.0"
diff --git a/react/README.md b/react/README.md
deleted file mode 100644
index 99518e5a75..0000000000
--- a/react/README.md
+++ /dev/null
@@ -1,734 +0,0 @@
-# Airbnb React/JSX Style Guide
-
-*A mostly reasonable approach to React and JSX*
-
-This style guide is mostly based on the standards that are currently prevalent in JavaScript, although some conventions (i.e async/await or static class fields) may still be included or prohibited on a case-by-case basis. Currently, anything prior to stage 3 is not included nor recommended in this guide.
-
-## Table of Contents
-
- 1. [Basic Rules](#basic-rules)
- 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless)
- 1. [Mixins](#mixins)
- 1. [Naming](#naming)
- 1. [Declaration](#declaration)
- 1. [Alignment](#alignment)
- 1. [Quotes](#quotes)
- 1. [Spacing](#spacing)
- 1. [Props](#props)
- 1. [Refs](#refs)
- 1. [Parentheses](#parentheses)
- 1. [Tags](#tags)
- 1. [Methods](#methods)
- 1. [Ordering](#ordering)
- 1. [`isMounted`](#ismounted)
-
-## Basic Rules
-
- - Only include one React component per file.
- - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless).
- - Always use JSX syntax.
- - Do not use `React.createElement` unless you’re initializing the app from a file that is not JSX.
- - [`react/forbid-prop-types`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md) will allow `arrays` and `objects` only if it is explicitly noted what `array` and `object` contains, using `arrayOf`, `objectOf`, or `shape`.
-
-## Class vs `React.createClass` vs stateless
-
- - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass`. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
-
- ```jsx
- // bad
- const Listing = React.createClass({
- // ...
- render() {
- return
;
- }
- }
- ```
-
- And if you don’t have state or refs, prefer normal functions (not arrow functions) over classes:
-
- ```jsx
- // bad
- class Listing extends React.Component {
- render() {
- return
{this.props.hello}
;
- }
- }
-
- // bad (relying on function name inference is discouraged)
- const Listing = ({ hello }) => (
-
{hello}
- );
-
- // good
- function Listing({ hello }) {
- return
{hello}
;
- }
- ```
-
-## Mixins
-
- - [Do not use mixins](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html).
-
- > Why? Mixins introduce implicit dependencies, cause name clashes, and cause snowballing complexity. Most use cases for mixins can be accomplished in better ways via components, higher-order components, or utility modules.
-
-## Naming
-
- - **Extensions**: Use `.jsx` extension for React components. eslint: [`react/jsx-filename-extension`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md)
- - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
- - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
-
- ```jsx
- // bad
- import reservationCard from './ReservationCard';
-
- // good
- import ReservationCard from './ReservationCard';
-
- // bad
- const ReservationItem = ;
-
- // good
- const reservationItem = ;
- ```
-
- - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name:
-
- ```jsx
- // bad
- import Footer from './Footer/Footer';
-
- // bad
- import Footer from './Footer/index';
-
- // good
- import Footer from './Footer';
- ```
-
- - **Higher-order Component Naming**: Use a composite of the higher-order component’s name and the passed-in component’s name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`.
-
- > Why? A component’s `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening.
-
- ```jsx
- // bad
- export default function withFoo(WrappedComponent) {
- return function WithFoo(props) {
- return ;
- }
- }
-
- // good
- export default function withFoo(WrappedComponent) {
- function WithFoo(props) {
- return ;
- }
-
- const wrappedComponentName = WrappedComponent.displayName
- || WrappedComponent.name
- || 'Component';
-
- WithFoo.displayName = `withFoo(${wrappedComponentName})`;
- return WithFoo;
- }
- ```
-
- - **Props Naming**: Avoid using DOM component prop names for different purposes.
-
- > Why? People expect props like `style` and `className` to mean one specific thing. Varying this API for a subset of your app makes the code less readable and less maintainable, and may cause bugs.
-
- ```jsx
- // bad
-
-
- // bad
-
-
- // good
-
- ```
-
-## Declaration
-
- - Do not use `displayName` for naming components. Instead, name the component by reference.
-
- ```jsx
- // bad
- export default React.createClass({
- displayName: 'ReservationCard',
- // stuff goes here
- });
-
- // good
- export default class ReservationCard extends React.Component {
- }
- ```
-
-## Alignment
-
- - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) [`react/jsx-closing-tag-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md)
-
- ```jsx
- // bad
-
-
- // good
-
-
- // if props fit in one line then keep it on the same line
-
-
- // children get indented normally
-
-
-
-
- // bad
- {showButton &&
-
- }
-
- // bad
- {
- showButton &&
-
- }
-
- // good
- {showButton && (
-
- )}
-
- // good
- {showButton && }
- ```
-
-## Quotes
-
- - Always use double quotes (`"`) for JSX attributes, but single quotes (`'`) for all other JS. eslint: [`jsx-quotes`](https://eslint.org/docs/rules/jsx-quotes)
-
- > Why? Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.
-
- ```jsx
- // bad
-
-
- // good
-
-
- // bad
-
-
- // good
-
- ```
-
-## Spacing
-
- - Always include a single space in your self-closing tag. eslint: [`no-multi-spaces`](https://eslint.org/docs/rules/no-multi-spaces), [`react/jsx-tag-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md)
-
- ```jsx
- // bad
-
-
- // very bad
-
-
- // bad
-
-
- // good
-
- ```
-
- - Do not pad JSX curly braces with spaces. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md)
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
-## Props
-
- - Always use camelCase for prop names.
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
- - Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
-
- ```jsx
- // bad
-
-
- // good
-
-
- // good
-
- ```
-
- - Always include an `alt` prop on `` tags. If the image is presentational, `alt` can be an empty string or the `` must have `role="presentation"`. eslint: [`jsx-a11y/alt-text`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md)
-
- ```jsx
- // bad
-
-
- // good
-
-
- // good
-
-
- // good
-
- ```
-
- - Do not use words like "image", "photo", or "picture" in `` `alt` props. eslint: [`jsx-a11y/img-redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md)
-
- > Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text.
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
- - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/#usage_intro). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md)
-
- ```jsx
- // bad - not an ARIA role
-
-
- // bad - abstract ARIA role
-
-
- // good
-
- ```
-
- - Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md)
-
- > Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility.
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
- - Avoid using an array index as `key` prop, prefer a stable ID. eslint: [`react/no-array-index-key`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md)
-
-> Why? Not using a stable ID [is an anti-pattern](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) because it can negatively impact performance and cause issues with component state.
-
-We don’t recommend using indexes for keys if the order of items may change.
-
- ```jsx
- // bad
- {todos.map((todo, index) =>
-
- )}
-
- // good
- {todos.map(todo => (
-
- ))}
- ```
-
- - Always define explicit defaultProps for all non-required props.
-
- > Why? propTypes are a form of documentation, and providing defaultProps means the reader of your code doesn’t have to assume as much. In addition, it can mean that your code can omit certain type checks.
-
- ```jsx
- // bad
- function SFC({ foo, bar, children }) {
- return
{foo}{bar}{children}
;
- }
- SFC.propTypes = {
- foo: PropTypes.number.isRequired,
- bar: PropTypes.string,
- children: PropTypes.node,
- };
-
- // good
- function SFC({ foo, bar, children }) {
- return
{foo}{bar}{children}
;
- }
- SFC.propTypes = {
- foo: PropTypes.number.isRequired,
- bar: PropTypes.string,
- children: PropTypes.node,
- };
- SFC.defaultProps = {
- bar: '',
- children: null,
- };
- ```
-
- - Use spread props sparingly.
- > Why? Otherwise you’re more likely to pass unnecessary props down to components. And for React v15.6.1 and older, you could [pass invalid HTML attributes to the DOM](https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html).
-
- Exceptions:
-
- - HOCs that proxy down props and hoist propTypes
-
- ```jsx
- function HOC(WrappedComponent) {
- return class Proxy extends React.Component {
- Proxy.propTypes = {
- text: PropTypes.string,
- isLoading: PropTypes.bool
- };
-
- render() {
- return
- }
- }
- }
- ```
-
- - Spreading objects with known, explicit props. This can be particularly useful when testing React components with Mocha’s beforeEach construct.
-
- ```jsx
- export default function Foo {
- const props = {
- text: '',
- isPublished: false
- }
-
- return ();
- }
- ```
-
- Notes for use:
- Filter out unnecessary props when possible. Also, use [prop-types-exact](https://www.npmjs.com/package/prop-types-exact) to help prevent bugs.
-
- ```jsx
- // bad
- render() {
- const { irrelevantProp, ...relevantProps } = this.props;
- return
- }
-
- // good
- render() {
- const { irrelevantProp, ...relevantProps } = this.props;
- return
- }
- ```
-
-## Refs
-
- - Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
-
- ```jsx
- // bad
-
-
- // good
- { this.myRef = ref; }}
- />
- ```
-
-## Parentheses
-
- - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/jsx-wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md)
-
- ```jsx
- // bad
- render() {
- return
-
- ;
- }
-
- // good
- render() {
- return (
-
-
-
- );
- }
-
- // good, when single line
- render() {
- const body =
hello
;
- return {body};
- }
- ```
-
-## Tags
-
- - Always self-close tags that have no children. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
- - If your component has multiline properties, close its tag on a new line. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
-
- ```jsx
- // bad
-
-
- // good
-
- ```
-
-## Methods
-
- - Use arrow functions to close over local variables. It is handy when you need to pass additional data to an event handler. Although, make sure they [do not massively hurt performance](https://www.bignerdranch.com/blog/choosing-the-best-approach-for-react-event-handlers/), in particular when passed to custom components that might be PureComponents, because they will trigger a possibly needless rerender every time.
-
- ```jsx
- function ItemList(props) {
- return (
-
- );
- }
- ```
-
- - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md)
-
- > Why? A bind call in the render path creates a brand new function on every single render. Do not use arrow functions in class fields, because it makes them [challenging to test and debug, and can negatively impact performance](https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1), and because conceptually, class fields are for data, not logic.
-
- ```jsx
- // bad
- class extends React.Component {
- onClickDiv() {
- // do stuff
- }
-
- render() {
- return ;
- }
- }
-
- // very bad
- class extends React.Component {
- onClickDiv = () => {
- // do stuff
- }
-
- render() {
- return
- }
- }
-
- // good
- class extends React.Component {
- constructor(props) {
- super(props);
-
- this.onClickDiv = this.onClickDiv.bind(this);
- }
-
- onClickDiv() {
- // do stuff
- }
-
- render() {
- return ;
- }
- }
- ```
-
- - Do not use underscore prefix for internal methods of a React component.
- > Why? Underscore prefixes are sometimes used as a convention in other languages to denote privacy. But, unlike those languages, there is no native support for privacy in JavaScript, everything is public. Regardless of your intentions, adding underscore prefixes to your properties does not actually make them private, and any property (underscore-prefixed or not) should be treated as being public. See issues [#1024](https://github.com/airbnb/javascript/issues/1024), and [#490](https://github.com/airbnb/javascript/issues/490) for a more in-depth discussion.
-
- ```jsx
- // bad
- React.createClass({
- _onClickSubmit() {
- // do stuff
- },
-
- // other stuff
- });
-
- // good
- class extends React.Component {
- onClickSubmit() {
- // do stuff
- }
-
- // other stuff
- }
- ```
-
- - Be sure to return a value in your `render` methods. eslint: [`react/require-render-return`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md)
-
- ```jsx
- // bad
- render() {
- ();
- }
-
- // good
- render() {
- return ();
- }
- ```
-
-## Ordering
-
- - Ordering for `class extends React.Component`:
-
- 1. optional `static` methods
- 1. `constructor`
- 1. `getChildContext`
- 1. `componentWillMount`
- 1. `componentDidMount`
- 1. `componentWillReceiveProps`
- 1. `shouldComponentUpdate`
- 1. `componentWillUpdate`
- 1. `componentDidUpdate`
- 1. `componentWillUnmount`
- 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
- 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
- 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
- 1. `render`
-
- - How to define `propTypes`, `defaultProps`, `contextTypes`, etc...
-
- ```jsx
- import React from 'react';
- import PropTypes from 'prop-types';
-
- const propTypes = {
- id: PropTypes.number.isRequired,
- url: PropTypes.string.isRequired,
- text: PropTypes.string,
- };
-
- const defaultProps = {
- text: 'Hello World',
- };
-
- class Link extends React.Component {
- static methodsAreOk() {
- return true;
- }
-
- render() {
- return {this.props.text};
- }
- }
-
- Link.propTypes = propTypes;
- Link.defaultProps = defaultProps;
-
- export default Link;
- ```
-
- - Ordering for `React.createClass`: eslint: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md)
-
- 1. `displayName`
- 1. `propTypes`
- 1. `contextTypes`
- 1. `childContextTypes`
- 1. `mixins`
- 1. `statics`
- 1. `defaultProps`
- 1. `getDefaultProps`
- 1. `getInitialState`
- 1. `getChildContext`
- 1. `componentWillMount`
- 1. `componentDidMount`
- 1. `componentWillReceiveProps`
- 1. `shouldComponentUpdate`
- 1. `componentWillUpdate`
- 1. `componentDidUpdate`
- 1. `componentWillUnmount`
- 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
- 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
- 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
- 1. `render`
-
-## `isMounted`
-
- - Do not use `isMounted`. eslint: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md)
-
- > Why? [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated.
-
- [anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html
-
-## Translation
-
- This JSX/React style guide is also available in other languages:
-
- -  **Chinese (Simplified)**: [jhcccc/javascript](https://github.com/jhcccc/javascript/tree/master/react)
- -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript/tree/master/react)
- -  **Español**: [agrcrobles/javascript](https://github.com/agrcrobles/javascript/tree/master/react)
- -  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide/tree/master/react)
- -  **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
- -  **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
- -  **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
- -  **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb/tree/master/react)
- -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide/tree/master/react)
- -  **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide)
- -  **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react)
- -  **Vietnam**: [uetcodecamp/jsx-style-guide](https://github.com/UETCodeCamp/jsx-style-guide)
-
-**[⬆ back to top](#table-of-contents)**