Home

Awesome

NullDev JavaScript Styleguide

NullDev JavaScript StyleGuide

Now with the new ESLint Flat Config Format!

<p align="center"><img height="150" width="auto" src="https://i.imgur.com/eCmJFjH.png" /></p> <p align="center"><b>A <i>mostly</i> reasonable approach to JavaScript</b></p> <p align="center"><sub>Or... Mainly NodeJS...</sub></p> </p>

Setup :gear:

To integrate into your own project:

<sub>*) The rationale for using Babel-ESLint is that it supports the newest Stage-3 ECMAScript features.</sub>

Or use the NullDev Project Template ...

... with already preset config files and project structure

DOWNLOAD

$ npm i - and you're ready to go!


Table of Contents :bookmark_tabs:

  1. :clipboard: Types

    <details> <summary>View contents</summary> </details>
  2. :link: References

    <details> <summary>View contents</summary>
    • 2.1 Prefer const
    • 2.2 Disallow var
    • 2.3 Block scope
    </details>
  3. :package: Objects

    <details> <summary>View contents</summary>
    • 3.1 Literals
    • 3.2 Computed properties
    • 3.3 Object shorthand
    • 3.4 Object concise
    • 3.5 Grouped shorthand
    • 3.6 Quoted properties
    • 3.7 Prototype Builtins
    • 3.8 Rest spread
    </details>
  4. :bookmark_tabs: Arrays

    <details> <summary>View contents</summary>
    • 4.1 Literals
    • 4.2 Push
    • 4.3 Array spreads
    • 4.4 spread for iterable
    • 4.5 Array-like objects
    • 4.6 Mapping
    • 4.7 Callback return
    • 4.8 Linebreaks
    </details>
  5. :hammer: Destructuring

    <details> <summary>View contents</summary>
    • 5.1 Object destructuring
    • 5.2 Array destructuring
    • 5.3 Object over array
    </details>
  6. :page_facing_up: Strings

    <details> <summary>View contents</summary>
    • 6.1 Quotes
    • 6.2 Length
    • 6.3 Template literals
    • 6.4 Eval
    • 6.5 Escaping
    • 6.6 Regular Expressions (RegEx)
    </details>
  7. :pager: Functions

    <details> <summary>View contents</summary>
    • 7.1 Strict mode
    • 7.2 Declarations
    • 7.3 IIFE's
    • 7.4 Non-function blocks
    • 7.5 Blocks (Info)
    • 7.6 Arguments shadow
    • 7.7 Rest
    • 7.8 Default parameters
    • 7.9 Side effects
    • 7.10 Defaults last
    • 7.11 Function constructor
    • 7.12 Signature spacing
    • 7.13 Mutating parameters
    • 7.14 Reassigning parameters
    • 7.15 Spread
    • 7.16 Signature invocation indentation
    </details>
  8. :arrow_right: Arrow Functions

    <details> <summary>View contents</summary>
    • 8.1 Usage
    • 8.2 Implicit return
    • 8.3 Wrap
    • 8.4 Omitting parentheses
    • 8.5 Confusing functions
    • 8.6 Linebreaks
    </details>
  9. :triangular_ruler: Classes & Constructors

    <details> <summary>View contents</summary>
    • 9.1 Use class
    • 9.2 Inheritance
    • 9.3 Chaining
    • 9.4 toString methods
    • 9.5 No empty constructors
    • 9.6 No duplicate members
    • 9.7 this in Class-Methods
    </details>
  10. :postbox: Modules

    <details> <summary>View contents</summary>
    • 10.1 CommonJS
    • 10.2 Duplicate imports
    • 10.3 Mutable exports
    • 10.4 Imports first
    • 10.5 Imports extensions
    • 10.6 Multiline imports
    </details>
  11. :arrows_clockwise: Iterators and Generators

    <details> <summary>View contents</summary> </details>
  12. :bookmark_tabs: Properties

    <details> <summary>View contents</summary>
    • 12.1 Dot notation
    • 12.2 Bracket notation
    • 12.3 Exponentiation operator
    </details>
  13. :floppy_disk: Variables

    <details> <summary>View contents</summary>
    • 13.1 Global namespace
    • 13.2 Declaration per variable
    • 13.3 Grouping
    • 13.4 Placing
    • 13.5 Chain assignment
    • 13.6 Increment & decrement
    • 13.7 Linebreaks
    • 13.8 Unused variables
    • 13.9 Bitwise floor
    </details>
  14. :arrow_heading_up: Hoisting

    <details> <summary>View contents</summary>
    • 14.1 About
    • 14.2 Anonymous function expressions
    • 14.3 Named function expressions
    • 14.4 Function declarations
    </details>
  15. :left_right_arrow: Comparison Operators & Equality

    <details> <summary>View contents</summary>
    • 15.1 Strict comparison
    • 15.2 Conditional statements
    • 15.3 Shortcuts
    • 15.4 Truth Equality
    • 15.5 Switch blocks
    • 15.6 Nested ternaries
    • 15.7 Unneeded-ternaries
    • 15.8 Mixed operators
    </details>
  16. :black_square_button: Blocks

    <details> <summary>View contents</summary> </details>
  17. :wrench: Control Statements

    <details> <summary>View contents</summary> </details>
  18. :pencil: Comments

    <details> <summary>View contents</summary> </details>
  19. :white_circle: Whitespace

    <details> <summary>View contents</summary> </details>
  20. :small_red_triangle_down: Commas

    <details> <summary>View contents</summary>
    • 20.1 Leading commas
    • 20.2 Comma Dangling
    </details>
  21. :heavy_exclamation_mark: Semicolons

    <details> <summary>View contents</summary>
    • 21.1 Use semicolons
    </details>
  22. :twisted_rightwards_arrows: Type Casting & Coercion

    <details> <summary>View contents</summary> </details>
  23. :scroll: Naming Conventions

    <details> <summary>View contents</summary> </details>
  24. :arrow_down: Accessors

    <details> <summary>View contents</summary>
    • 24.1 Not required accessors
    • 24.2 Getters & Setters
    • 24.3 Boolean prefix
    • 24.4 Consistency
    </details>
  25. :high_brightness: Events

    <details> <summary>View contents</summary> </details>
  26. :book: Standard Library

    <details> <summary>View contents</summary> </details>
  27. :nut_and_bolt: jQuery

    <details> <summary>View contents</summary> </details>
  28. :arrows_counterclockwise: ECMAScript 5 Compatibility

    <details> <summary>View contents</summary>
    • 28.1 Compatibility table
    </details>
  29. :six: ECMAScript 6+ (ES 2015+) Styles

    <details> <summary>View contents</summary> </details>
  30. :electric_plug: Testing

    <details> <summary>View contents</summary> </details>
  31. :chart_with_upwards_trend: Performance

    <details> <summary>View contents</summary> </details>
  32. :books: Resources

    <details> <summary>View contents</summary> </details>
  33. :copyright: Copyright

    <details> <summary>View contents</summary> </details>
  34. :recycle: Amendments

    <details> <summary>View contents</summary> </details>

Types

<a name="types--primitives"></a><a name="1.1"></a>

<a name="types--complex"></a><a name="1.2"></a>

⬆ back to top

References

<a name="references--prefer-const"></a><a name="2.1"></a>

<a name="references--disallow-var"></a><a name="2.2"></a>

<a name="references--block-scope"></a><a name="2.3"></a>

⬆ back to top

Objects

<a name="objects--no-new"></a><a name="3.1"></a>

<a name="es6-computed-properties"></a><a name="3.2"></a>

<a name="es6-object-shorthand"></a><a name="3.3"></a>

<a name="es6-object-concise"></a><a name="3.4"></a>

<a name="objects--grouped-shorthand"></a><a name="3.5"></a>

<a name="objects--quoted-props"></a><a name="3.6"></a>

<a name="objects--prototype-builtins"></a><a name="3.7"></a>

<a name="objects--rest-spread"></a><a name="3.8"></a>

⬆ back to top

Arrays

<a name="arrays--literals"></a><a name="4.1"></a>

<a name="arrays--push"></a><a name="4.2"></a>

<a name="es6-array-spreads"></a><a name="4.3"></a>

<a name="arrays--from"></a> <a name="arrays--from-iterable"></a><a name="4.4"></a>

<a name="arrays--from-array-like"></a><a name="4.5"></a>

<a name="arrays--mapping"></a><a name="4.6"></a>

<a name="arrays--callback-return"></a><a name="4.7"></a>

<a name="arrays--bracket-newline"></a><a name="4.8"></a>

⬆ back to top

Destructuring

<a name="destructuring--object"></a><a name="5.1"></a>

<a name="destructuring--array"></a><a name="5.2"></a>

<a name="destructuring--object-over-array"></a><a name="5.3"></a>

⬆ back to top

Strings

<a name="strings--quotes"></a><a name="6.1"></a>

<a name="strings--line-length"></a><a name="6.2"></a>

<a name="es6-template-literals"></a><a name="6.3"></a>

<a name="strings--eval"></a><a name="6.4"></a>

<a name="strings--escaping"></a><a name="6.5"></a>

<a name="strings--regex"></a><a name="6.6"></a>

⬆ back to top

Functions

<a name="functions--use-strict"></a><a name="7.1"></a>

<a name="functions--declarations"></a><a name="7.2"></a>

<a name="functions--iife"></a><a name="7.3"></a>

<a name="functions--in-blocks"></a><a name="7.4"></a>

<a name="functions--note-on-blocks"></a><a name="7.5"></a>

<a name="functions--arguments-shadow"></a><a name="7.6"></a>

<a name="es6-rest"></a><a name="7.7"></a>

<a name="es6-default-parameters"></a><a name="7.8"></a>

<a name="functions--default-side-effects"></a><a name="7.9"></a>

<a name="functions--defaults-last"></a><a name="7.10"></a>

<a name="functions--constructor"></a><a name="7.11"></a>

<a name="functions--signature-spacing"></a><a name="7.12"></a>

<a name="functions--mutate-params"></a><a name="7.13"></a>

<a name="functions--reassign-params"></a><a name="7.14"></a>

<a name="functions--spread-vs-apply"></a><a name="7.15"></a>

<a name="functions--signature-invocation-indentation"></a><a name="7.16"></a>

⬆ back to top

Arrow Functions

<a name="arrows--use-them"></a><a name="8.1"></a>

<a name="arrows--implicit-return"></a><a name="8.2"></a>

<a name="arrows--paren-wrap"></a><a name="8.3"></a>

<a name="arrows--one-arg-parens"></a><a name="8.4"></a>

<a name="arrows--confusing"></a><a name="8.5"></a>

<a name="whitespace--implicit-arrow-linebreak"></a><a name="8.6"></a>

⬆ back to top

Classes & Constructors

<a name="constructors--use-class"></a><a name="9.1"></a>

<a name="constructors--extends"></a><a name="9.2"></a>

<a name="constructors--chaining"></a><a name="9.3"></a>

<a name="constructors--tostring"></a><a name="9.4"></a>

<a name="constructors--no-useless"></a><a name="9.5"></a>

<a name="classes--no-duplicate-members"></a><a name="9.6"></a>

<a name="classes--methods-use-this"></a><a name="9.7"></a>

⬆ back to top

Modules

<a name="modules--use-them"></a><a name="10.1"></a>

<a name="modules--no-duplicate-imports"></a><a name="10.2"></a>

<a name="modules--no-mutable-exports"></a><a name="10.3"></a>

<a name="modules--imports-first"></a><a name="10.4"></a>

<a name="modules--import-extensions"></a><a name="10.5"></a>

<a name="modules--multiline-imports-over-newlines"></a><a name="10.6"></a>

Iterators and Generators

<a name="iterators--nope"></a><a name="11.1"></a>

<a name="generators--nope"></a><a name="11.2"></a>

<a name="generators--spacing"></a>

⬆ back to top

Properties

<a name="properties--dot"></a><a name="12.1"></a>

<a name="properties--bracket"></a><a name="12.2"></a>

<a name="es2016-properties--exponentiation-operator"></a><a name="12.3"></a>

⬆ back to top

Variables

<a name="variables--const"></a><a name="13.1"></a>

<a name="variables--one-const"></a><a name="13.2"></a>

<a name="variables--const-let-group"></a><a name="13.3"></a>

<a name="variables--define-where-used"></a><a name="13.4"></a>

<a name="variables--no-chain-assignment"></a><a name="13.5"></a>

<a name="variables--unary-increment-decrement"></a><a name="13.6"></a>

<a name="variables--linebreak"></a><a name="13.7"></a>

<a name="variables--no-unused-vars"></a><a name="13.8"></a>

<a name="variables--bitwise-floor"></a><a name="13.9"></a>

⬆ back to top

Hoisting

<a name="hoisting--about"></a><a name="14.1"></a>

<a name="hoisting--anon-expressions"></a><a name="14.2"></a>

<a name="hoisting--named-expresions"></a><a name="hoisting--named-expressions"></a><a name="14.3"></a>

<a name="hoisting--declarations"></a><a name="14.4"></a>

⬆ back to top

Comparison Operators & Equality

<a name="comparison--eqeqeq"></a><a name="15.1"></a>

<a name="comparison--if"></a><a name="15.2"></a>

<a name="comparison--shortcuts"></a><a name="15.3"></a>

<a name="comparison--moreinfo"></a><a name="15.4"></a>

<a name="comparison--switch-blocks"></a><a name="15.5"></a>

<a name="comparison--nested-ternaries"></a><a name="15.6"></a>

<a name="comparison--unneeded-ternary"></a><a name="15.7"></a>

<a name="comparison--no-mixed-operators"></a><a name="15.8"></a>

⬆ back to top

Blocks

<a name="blocks--braces"></a><a name="16.1"></a>

<a name="blocks--cuddled-elses"></a><a name="16.2"></a>

<a name="blocks--no-else-return"></a><a name="16.3"></a>

⬆ back to top

Control Statements

<a name="control-statements"></a><a name="17.1"></a>

<a name="control-statements--value-selection"></a><a name="17.2"></a>

⬆ back to top

Comments

<a name="comments--language"></a><a name="18.1"></a>

<a name="comments--multiline"></a><a name="18.2"></a>

<a name="comments--singleline"></a><a name="18.3"></a>

<a name="comments--spaces"></a><a name="18.4"></a>

<a name="comments--actionitems"></a><a name="18.5"></a>

<a name="comments--fixme"></a><a name="18.6"></a>

<a name="comments--todo"></a><a name="18.7"></a>

⬆ back to top

Whitespace

<a name="whitespace--spaces"></a><a name="19.1"></a>

<a name="whitespace--before-blocks"></a><a name="19.2"></a>

<a name="whitespace--around-keywords"></a><a name="19.3"></a>

<a name="whitespace--infix-ops"></a><a name="19.4"></a>

<a name="whitespace--lf-linebreaks"></a><a name="19.5"></a>

<a name="whitespace--newline-at-end"></a><a name="19.6"></a>

<a name="whitespace--chains"></a><a name="19.7"></a>

<a name="whitespace--after-blocks"></a><a name="19.8"></a>

<a name="whitespace--padded-blocks"></a><a name="19.9"></a>

<a name="whitespace--in-parens"></a><a name="19.10"></a>

<a name="whitespace--in-brackets"></a><a name="19.11"></a>

<a name="whitespace--in-braces"></a><a name="19.12"></a>

<a name="whitespace--max-len"></a><a name="19.13"></a>

<a name="whitespace--block-spacing"></a><a name="19.14"></a>

<a name="whitespace--comma-spacing"></a><a name="19.15"></a>

<a name="whitespace--computed-property-spacing"></a><a name="19.16"></a>

<a name="whitespace--func-call-spacing"></a><a name="19.17"></a>

<a name="whitespace--key-spacing"></a><a name="19.18"></a>

<a name="whitespace--no-trailing-spaces"></a><a name="19.19"></a>

<a name="whitespace--no-multiple-empty-lines"></a><a name="19.20"></a>

⬆ back to top

Commas

<a name="commas--leading-trailing"></a><a name="20.1"></a>

<a name="commas--dangling"></a><a name="20.2"></a>

⬆ back to top

Semicolons

<a name="semicolons--required"></a><a name="21.1"></a>

⬆ back to top

Type Casting & Coercion

<a name="coercion--explicit"></a><a name="22.1"></a>

<a name="coercion--strings"></a><a name="22.2"></a>

<a name="coercion--numbers"></a><a name="22.3"></a>

<a name="coercion--comment-deviations"></a><a name="22.4"></a>

<a name="coercion--bitwise"></a><a name="22.5"></a>

<a name="coercion--booleans"></a><a name="22.6"></a>

<a name="coercion--valid-typeof"></a><a name="22.6"></a>

⬆ back to top

Naming Conventions

<a name="naming--language"></a><a name="23.0"></a>

<a name="naming--descriptive"></a><a name="23.1"></a>

<a name="naming--camelCase"></a><a name="23.2"></a>

<a name="naming--PascalCase"></a><a name="23.3"></a>

<a name="naming--leading-underscore"></a><a name="23.4"></a>

<a name="naming--self-this"></a><a name="23.5"></a>

<a name="naming--filename-matches-export"></a><a name="23.6"></a>

<a name="naming--camelCase-default-export"></a><a name="23.7"></a>

<a name="naming--PascalCase-singleton"></a><a name="23.8"></a>

<a name="naming--Acronyms-and-Initialisms"></a><a name="23.9"></a>

<a name="naming--uppercase"></a><a name="23.10"></a>

<a name="naming--state-booleans"></a><a name="23.11"></a>

⬆ back to top

Accessors

<a name="accessors--not-required"></a><a name="24.1"></a>

<a name="accessors--no-getters-setters"></a><a name="24.2"></a>

<a name="accessors--boolean-prefix"></a><a name="24.3"></a>

<a name="accessors--consistent"></a><a name="24.4"></a>

⬆ back to top

Events

<a name="events--hash"></a><a name="25.1"></a>

⬆ back to top

Standard Library

The Standard Library contains utilities that are functionally broken but remain for legacy reasons.

<a name="standard-library--isnan"></a><a name="26.1"></a>

<a name="standard-library--isfinite"></a><a name="26.2"></a>

⬆ back to top

jQuery

<a name="jquery--dollar-prefix"></a><a name="27.1"></a>

<a name="jquery--cache"></a><a name="27.2"></a>

<a name="jquery--queries"></a><a name="27.3"></a>

<a name="jquery--find"></a><a name="27.4"></a>

<a name="jquery--find"></a><a name="27.5"></a>

<a name="jquery--ready"></a><a name="27.6"></a>

⬆ back to top

ECMAScript 5 Compatibility

<a name="es5-compat--kangax"></a><a name="28.1"></a>

⬆ back to top

<a name="ecmascript-6-styles"></a>

ECMAScript 6+ (ES 2015+) Styles

<a name="es6-styles"></a><a name="29.1"></a>

  1. Arrow Functions
  2. Classes
  3. Object Shorthand
  4. Object Concise
  5. Object Computed Properties
  6. Template Strings
  7. Destructuring
  8. Default Parameters
  9. Rest
  10. Array Spreads
  11. Let and Const
  12. Exponentiation Operator
  13. Iterators and Generators
  14. Modules

<a name="tc39-proposals"></a><a name="29.2"></a>

⬆ back to top

Testing

<a name="testing--tests"></a><a name="30.1"></a>

⬆ back to top

Performance

<a name="performance--performance"></a><a name="31.1"></a>

⬆ back to top

Resources

<a name="resources--learning-es6"></a><a name="32.1"></a>

<a name="resources--read-this"></a><a name="32.2"></a>

<a name="resources--tools"></a><a name="32.3"></a>

<a name="resources--further-reading"></a><a name="32.4"></a>

<a name="resources--books"></a><a name="32.5"></a>

<a name="resources--blogs"></a><a name="32.6"></a>

<a name="resources--podcasts"></a><a name="32.7"></a>

⬆ back to top

Copyright

<a name="copyright--base"></a><a name="33.1"></a>

<a name="copyright--license"></a><a name="33.2"></a>

⬆ back to top

Amendments

<a name="amendments--forking"></a><a name="34.1"></a>

⬆ back to top

<br><br><br>

<p align="center"> <a href="https://github.com/NullDev/JavaScript-Styleguide/blob/master/LICENSE"> <img src="https://img.shields.io/badge/License-MIT-F8E301.svg?style=flat-square"/> </a> </p>

NullDev JavaScript Styleguide