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.