For JavaScript, we use the popular eslint tool to ensure that our codebase looks uniform across the files. To use eslint, you will need the NodeJS runtime installed. We recommend using the current LTS release.
Linting Code
You can run eslint on your host system or on vagrant by navigating into the site/
directory and running:
npm run lint
To have eslint attempt to automatically fix any detected problems:
npm run lint:fix
If you wish to lint or fix a specific file, you will need to run the eslint executable directly, by doing:
node_modules/.bin/eslint [--fix] <file>
Style Rules
Below we enumerate all of the eslint rules that Submitty utilizes.
While most of the list should be relatively straight forward, we would like to specially point out
the no-unused-vars
rule. Because Submitty utilizes multiple unbundled JS files which are included
separately, eslint has no way to know when variables come from outside the file, or if a given variable
is used in another file. As such, for variables which come from outside the current file, you will need to
annotate the file with a /* global <variableName> */
directive in the file. For variables that are not
used in the current file, but used elsewhere, you’ll need to use the /* exported <variableName> */
directive. This includes functions and classes as well as regular variables.
- arrow-spacing
- block-spacing
- curly (enforces curly braces for “if”, “if-else”, “while”, and “for” blocks)
- for-direction
- getter-return
- no-async-promise-executor
- no-compare-neg-zero
- no-cond-assign
- no-constant-condition
- no-control-regex
- no-debugger
- no-dupe-args
- no-dupe-else-if
- no-dupe-keys
- no-duplicate-case
- no-empty
- no-empty-character-class
- no-ex-assign
- no-extra-boolean-cast
- no-extra-semi
- no-func-assign
- no-import-assign
- no-inner-declarations
- no-invalid-regexp
- no-irregular-whitespace
- no-misleading-character-class
- no-obj-calls
- no-prototype-builtins
- no-regex-spaces
- no-setter-return
- no-sparse-arrays
- no-unexpected-multiline
- no-unreachable
- no-unsafe-finally
- no-unsafe-negation
- use-isnan
- valid-typeof
- no-case-declarations
- no-empty-pattern
- no-fallthrough
- no-global-assign
- no-octal
- no-redeclare
- no-self-assign
- no-unused-labels
- no-useless-catch
- no-useless-escape
- no-with
- no-delete-var
- no-shadow-restricted-names
- no-undef
- no-unused-vars
- no-mixed-spaces-and-tabs
- constructor-super
- no-class-assign
- no-const-assign
- no-dupe-class-members
- no-new-symbol
- no-this-before-super
- require-yield
- brace-style (stroustrup style, like PHP)
- comma-dangle
- default-param-last
- eol-last
- indent (2 spaces for indentation)
- keyword-spacing
- linebreak-style (use
\n
to end lines) - no-trailing-spaces
- no-var
- prefer-arrow-callback
- prefer-const
- prefer-template
- quotes (prefer single quotes)
- semi (always have semi-colons)
- semi-style (semi-colons are at end of lines)
- template-curly-spacing (enforces no spaces between curly braces and variable in template literals)