Version 1.2.0
YOU! - please contribute to these code guidelines! If you have any suggestions for improvement to these guidelines, create an issue to discuss it or create a pull request with your changes and discussion will occur on that PR.
- James Young @jamsyoung, github
- Matt Crutchfield @mtcrutch, github
We have included JSHint and JSCS RC files in this repository
to validate javascript code against these guidelines. When something is
questioned, these files will always win. When in doubt, run JSHint and JSCS
with the .jshintrc
and .jscsrc
files in place and see if they find any
problems. It is recommended that you find plugins for your editor of choice to
always validate your code against these files.
The JavaScript guidelines are based off of idiomatic.js.
For lots of code examples that show the style we want, see the airbnb guide.
The MTS Guidelines will be the same with the following additional rules applied.
We will be using:
- Mocha / Chai for unit tests
- Selenium (WebdriverJS) / Mocha / Chai for functional tests
- PhantomJS / CasperJS for functional tests
-
Whitespace
- 4-space soft indents are required. This means four spaces or four spaces representing a tab.
-
Beautiful Syntax
-
2.A - 2.C should not have
inner-space
. Refer to 2.D for a syntax withoutinner-space
. Here is an example.function foo(bar, baz) { var qux = bar + baz; for (i = 0; i < 10; i++) { console.log(qux); } if (bar === baz) { qux = bar * baz; } else { qux = bar / baz; } return qux; }
-
Single quotes must be used.
-
Object literals should look like this.
var objectLiteral; objectLiteral = { foo: 'bar', baz: 'qux' };
-
Milliseconds should be assigned in multiples of 1000, and always use explicit order of operations.
var oneSecond = 1000 * 1, oneMinute = 1000 * 60, fiveMinutes = (1000 * 60) * 5;
-
- Write clean semantic HTML5 markup.
- Use double quotes for attributes.
- Use proper indention.
- Selector Attributes
Never use an ID as a styling hook.
Prefix any JavaScript class hooks with
js-
. Example:class="js-foo foo"
- Closing
<li>
elements.<li>
elements should not be closed. Further reading on this inline-block issue.
- The CSS / Sass guidelines are based off of csswizardry/CSS-Guidelines.
- We use nomalize.css as our style reset.
- Declarations. Declarations should be in aplhabetical order (NOT by relevance).
- All lines that are not code blocks should wrap at or under 80 columns.
- Should allow trailing whitespace, since that is a valid Markdown syntax.
- Should have 2 blank lines above each H1 and H2 heading except for the heading at the top of the document. This is optinal for other headings.
- Should have 4 blank lines to separate the link reference at the bottom of the document.
- Should use
0.
for ordered lists - Should use
-
for unordered lists - Secondary bullets must be indented four spaces to render correctly on Bitbucket.
- Do not try to put code blocks as secondary bullets in a list. They will not render correctly on both GitHub and BitBucket. More details on this to come in the future.