Code Style - IITC-CE/ingress-intel-total-conversion GitHub Wiki
Please follow the these guidelines. Some are just preference, others are good practice.
Typically, code editors support .editorconfig
, eslint.config.js
, and .prettierrc.json
files which are located in the repository and therefore automatically format your code to match the project style code.
-
Use modern JS (ECMAScript 2024 standard).
-
eqeqeq: use identity operators:
===
and!==
. Why do I want this? -
You can use jQuery, but you should favor vanilla JS whenever possible.
-
Indentation: 2 spaces.
-
enforce semicolon.
-
'one true brace-style' (see also curly):
- opening brace on the same line:
if (blub) {
- else clauses:
} else if (blub) {
or} else {
- opening brace on the same line:
-
keyword-spacing: there should be a space after
if
,for
, etc.E.g.
if (true) { doStuff(); } else { dontDoStuff(); }
-
spaced-comment:
// this is a comment
-
quotes: Use single-quotes for JavaScript and double-quotes for HTML content.
Example:
$('body').append('<div id="soup">Soup!</div>');
-
Line length: Soft limit of 160 characters (set in .prettierrc.json with "printWidth": 160), but try to keep them shorter where suitable.
-
no-trailing-spaces: ensure you remove all trailing whitespace before submitting your patch.
If you editor doesn’t detect those for you, try
grep -nE "[[:space:]]+$" «filename»