Skip to content

datavized/code-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Datavized Code Style

Our code style is based on Crockford's, with a few modifications.

The Basics

  • Indent with tabs, not spaces
  • Always end statements with semicolons
  • Conditionals and loops ("if", "while", "for") always use curly braces
  • Never use var. Use const wherever possible and let only if necessary.
  • Always use "strict equal" (=== and !==, not == or !=)
  • Define variables in scope, never global.

The Rules

Stylistic Issues

Rule Value Description
array-bracket-spacing enforce consistent spacing inside array brackets
brace-style enforce consistent brace style for blocks
camelcase enforce camelcase naming convention
comma-dangle require or disallow trailing commas
comma-spacing enforce consistent spacing before and after commas
comma-style enforce consistent comma style
indent tab enforce consistent indentation
key-spacing enforce consistent spacing between keys and values in object literal properties
keyword-spacing enforce consistent spacing before and after keywords
linebreak-style unix enforce consistent linebreak style
max-params 5 enforce a maximum number of parameters in function definitions
new-cap require constructor names to begin with a capital letter
no-array-constructor disallow Array constructors
no-bitwise disallow bitwise operators
no-continue disallow continue statements
no-mixed-spaces-and-tabs disallow mixed spaces and tabs for indentation
no-trailing-spaces disallow trailing whitespace at the end of lines
no-underscore-dangle disallow dangling underscores in identifiers
one-var never enforce variables to be declared either together or separately in functions
one-var-declaration-per-line require or disallow newlines around variable declarations
quote-props as-needed require quotes around object literal property names
quotes single enforce the consistent use of either backticks, double, or single quotes
semi require or disallow semicolons instead of ASI
semi-spacing enforce consistent spacing before and after semicolons
space-before-blocks enforce consistent spacing before blocks
space-before-function-paren enforce consistent spacing before function definition opening parenthesis
space-in-parens enforce consistent spacing inside parentheses
space-infix-ops require spacing around infix operators
space-unary-ops enforce consistent spacing before or after unary operators

Best Practices

Rule Value Description
babel/no-invalid-this disallow this keywords outside of classes or class-like objects
block-scoped-var enforce the use of variables within the scope they are defined
consistent-return require return statements to either always or never specify values
curly enforce consistent brace style for all control statements
dot-notation enforce dot notation whenever possible
eqeqeq require the use of === and !==
guard-for-in require for-in loops to include an if statement
no-caller disallow the use of arguments.caller or arguments.callee
no-case-declarations disallow lexical declarations in case clauses
no-empty-pattern disallow empty destructuring patterns
no-eval disallow the use of eval()
no-extend-native disallow extending native types
no-fallthrough disallow fallthrough of case statements
no-global-assign disallow assignments to native objects or read-only global variables
no-implicit-globals disallow declarations in the global scope
no-implied-eval disallow the use of eval()-like methods
no-iterator disallow the use of the __iterator__ property
no-loop-func disallow function declarations that contain unsafe references inside loop statements
no-multi-str disallow multiline strings
no-new disallow new operators outside of assignments or comparisons
no-new-func disallow new operators with the Function object
no-octal disallow octal literals
no-redeclare disallow variable redeclaration
no-self-assign disallow assignments where both sides are exactly the same
no-sequences disallow comma operators
no-unused-labels disallow unused labels
no-useless-catch disallow unnecessary catch clauses
no-useless-escape disallow unnecessary escape characters
no-with disallow with statements
radix enforce the consistent use of the radix argument when using parseInt()
require-await disallow async functions which have no await expression
vars-on-top require var declarations be placed at the top of their containing scope
wrap-iife any require parentheses around immediate function invocations

ECMAScript 6

Rule Value Description
constructor-super require super() calls in constructors
no-class-assign disallow reassigning class members
no-const-assign disallow reassigning const variables
no-dupe-class-members disallow duplicate class members
no-new-symbol disallow new operators with the Symbol object
no-this-before-super disallow this/super before calling super() in constructors
no-useless-computed-key disallow unnecessary computed property keys in objects and classes
no-var require let or const instead of var
prefer-const require const declarations for variables that are never reassigned after declared
require-yield require generator functions to contain yield

Possible Errors

Rule Value Description
for-direction enforce "for" loop update clause moving the counter in the right direction.
getter-return enforce return statements in getters
no-async-promise-executor disallow using an async function as a Promise executor
no-compare-neg-zero disallow comparing against -0
no-cond-assign disallow assignment operators in conditional expressions
no-constant-condition disallow constant expressions in conditions
no-control-regex disallow control characters in regular expressions
no-debugger disallow the use of debugger
no-dupe-args disallow duplicate arguments in function definitions
no-dupe-else-if disallow duplicate conditions in if-else-if chains
no-dupe-keys disallow duplicate keys in object literals
no-duplicate-case disallow duplicate case labels
no-empty disallow empty block statements
no-empty-character-class disallow empty character classes in regular expressions
no-ex-assign disallow reassigning exceptions in catch clauses
no-extra-boolean-cast disallow unnecessary boolean casts
no-extra-parens disallow unnecessary parentheses
no-extra-semi disallow unnecessary semicolons
no-func-assign disallow reassigning function declarations
no-import-assign disallow assigning to imported bindings
no-inner-declarations disallow variable or function declarations in nested blocks
no-invalid-regexp disallow invalid regular expression strings in RegExp constructors
no-irregular-whitespace disallow irregular whitespace
no-misleading-character-class disallow characters which are made with multiple code points in character class syntax
no-obj-calls disallow calling global object properties as functions
no-prototype-builtins disallow calling some Object.prototype methods directly on objects
no-regex-spaces disallow multiple spaces in regular expressions
no-setter-return disallow returning values from setters
no-sparse-arrays disallow sparse arrays
no-unexpected-multiline disallow confusing multiline expressions
no-unreachable disallow unreachable code after return, throw, continue, and break statements
no-unsafe-finally disallow control flow statements in finally blocks
no-unsafe-negation disallow negating the left operand of relational operators
require-atomic-updates disallow assignments that can lead to race conditions due to usage of await or yield
use-isnan require calls to isNaN() when checking for NaN
valid-typeof enforce comparing typeof expressions against valid strings

Variables

Rule Value Description
no-delete-var disallow deleting variables
no-restricted-globals event disallow specified global variables
no-shadow-restricted-names disallow identifiers from shadowing restricted names
no-undef disallow the use of undeclared variables unless mentioned in /*global */ comments
no-unused-vars disallow unused variables
no-use-before-define disallow the use of variables before they are defined

Strict Mode

Rule Value Description
strict require or disallow strict mode directives

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published