- airbnb JS guide + SublimeLinter settings. If using SublimeText(2) and the SublimeLinter plugin, you can download the settings file to enforce this style guide.
- Google's JavaScript Style Guide
-
Strict mode: !NEVER globally apply strict mode!
Always add
'use strict';
either a) at the top of your functions, or b) at the top of your non-global IIFE. This way you can be sure that your code is as compliant as possible, without buggering up libraries and other chunks of code you don't have control over. More info on strict mode. -
Use JSDoc syntax for all documentation
- Variables: If assigning a value, can also use one var per line. But declare all unassigned variables with a single var.
var $divs = $('div');
var myString = "This is my string";
var i, newString;
Google's CSS & HTML Style Guide
None
- Entity References: always use &entity; or other encoding for special characters
- ? Optional tags: Please close all non-self terminating tags (self-terminating tags:
<br>, <hr>, <img>
, etc) - CSS Hacks: !AVOID HACKS! Use the conditional
<head>
tag from h5bp,but increase the scope to include up to IE10. Use Modernizr for feature detection instead.
Use the same whitespace conventions as vanilla CSS.
Nesting allows simple namespacing & greatly improved readability. Use nesting. As much as possible, avoid nesting more than 3-4 levels deep.
Use the same naming conventions as JavaScript.
- Use the same naming convention as classes & IDs from CSS.
- Declare all required/configurable variables with !default suffix at the top of the mixin. Arguments should be given a default value wherever possible.
@mixin roundCorners() {
$borderRadius: 4px !default;
@include border-radius( $borderRadius );
}
- For reusable (@extend-able) classes, consider using
%placeholder
selectors instead. More on Placeholder Selectors.
- Separate logical blocks of code into files. Examples:
_variables.scss
,_utility-classes.scss
,_mixins.scss
,_typography.scss
,_tables.scss,
etc. - Use Sprockets when in a Middleman project to
//= require
files. However, use @import for files that do not generate any output (@mixins, %classes, $variables
)
Use KSS or cssdoc syntax for documentation comments, otherwise use the same comment conventions as vanilla CSS.
- More info & rough style guide here
- Use of
_base.scss
from Compass' Best practices document.
- Google's JavaScript Style Guide
- Google's CSS & HTML Style Guide
- Code Guide
- Airbnb JS guide
- EditorConfig helps unify and enforce styles in popular editors
- JS Hint rc