Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 8971738

Browse files
committed
Merge branch 'master' into indexify-css-documentation
Conflicts: css/Readme.md
2 parents df99e98 + b06ed19 commit 8971738

10 files changed

Lines changed: 110 additions & 32 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A repo to document code standards for different languages and provide tools for
66

77
## JavaScript
88

9-
Typically we lint our javascript files using [Grunt](http://gruntjs.com/). We have two javascript linters with different features. [jshint](https://github.com/gruntjs/grunt-contrib-jshint) and [jscs](https://github.com/gustavohenke/grunt-jscs-checker).
9+
Typically we lint our javascript files using [Grunt](http://gruntjs.com/). We have two javascript linters with different features. [jshint](https://github.com/gruntjs/grunt-contrib-jshint) and [jscs](https://github.com/gustavohenke/grunt-jscs).
1010

1111
To add javascript linting to your project:
1212

css/.scss-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ linters:
1212

1313
# Should selectors be all lowercase?
1414
CapitalizationInSelector:
15-
enabled: true
15+
enabled: false
1616

1717
# Prefer hexadecimal color codes over color keywords?
1818
ColorKeyword:
@@ -100,7 +100,7 @@ linters:
100100
# (http://bem.info/method/definitions/).
101101
NameFormat:
102102
enabled: true
103-
convention: hyphenated_lowercase
103+
convention: BEM
104104

105105
# Report @extend unless extending a placeholder?
106106
PlaceholderInExtend:
@@ -199,14 +199,14 @@ linters:
199199
"bottom",
200200
"left",
201201
"z-index",
202+
"float",
202203

203204
# Display, layout modes & box model
204205
"display",
205206
"overflow",
206207
"overflow-x",
207208
"overflow-y",
208209
"clip",
209-
"float",
210210
"clear",
211211
"table-layout",
212212
"empty-cells",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<snippet>
2+
<content><![CDATA[
3+
// ${1:File Name}
4+
// ===
5+
//
6+
// ${2:Description}
7+
8+
]]></content>
9+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
10+
<tabTrigger>//#</tabTrigger>
11+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
12+
<scope>source.scss</scope>
13+
</snippet>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<snippet>
2+
<content><![CDATA[
3+
// ${1:Section Name}
4+
// ---
5+
//
6+
// ${2:Description}
7+
8+
]]></content>
9+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
10+
<tabTrigger>//##</tabTrigger>
11+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
12+
<scope>source.scss</scope>
13+
</snippet>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<snippet>
2+
<content><![CDATA[
3+
// ${1:Function name}
4+
// ===
5+
//
6+
// ${2:Function Description}
7+
//
8+
// @param \$${3:param-name} [${4:data type}] : ${5:Description}
9+
// @return [${6:Data Type}]
10+
11+
]]></content>
12+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
13+
<tabTrigger>//fn</tabTrigger>
14+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
15+
<scope>source.scss</scope>
16+
</snippet>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<snippet>
2+
<content><![CDATA[
3+
// ${1:Mixin name}
4+
// ===
5+
//
6+
// ${2:Mixin Description}
7+
//
8+
// @param \$${3:param-name} [${4:data type}] : ${5:Description}
9+
10+
]]></content>
11+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
12+
<tabTrigger>//mx</tabTrigger>
13+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
14+
<scope>source.scss</scope>
15+
</snippet>

javascript/.jscsrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
22
"disallowEmptyBlocks": true,
33
"disallowKeywords": ["with"],
4-
"disallowLeftStickedOperators": ["?", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
54
"disallowMixedSpacesAndTabs": true,
65
"disallowMultipleLineStrings": true,
7-
"disallowRightStickedOperators": ["?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
86
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
97
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
108
"disallowTrailingWhitespace": true,
119
"requireCamelCaseOrUpperCaseIdentifiers": true,
12-
"requireLeftStickedOperators": [","],
10+
"disallowSpaceBeforeBinaryOperators": [","],
1311
"requireLineFeedAtFileEnd": true,
14-
"requireRightStickedOperators": ["!"],
1512
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
1613
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
1714
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="],
15+
"requireSpacesInConditionalExpression": true,
1816
"requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
1917
"validateIndentation": 4,
2018
"validateLineBreaks": "LF",

javascript/README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# General
2-
## Comments
2+
##Comments
33

44
Please comment code extensively. More comments are always better than fewer comments. Comments should describe the why of your code - not what the code is doing:
55

@@ -39,7 +39,7 @@ Don't commit commented out sections of code back into the repository. Just delet
3939
If a piece of code is very temporarily being removed, and will be reinserted shortly, you might decide to do this anyway. Please leave a detailed comment explaining exactly why. Sorta like those post-its we leave on boxes in the fridge with our name and date so that we know when to chuck 'em out!
4040

4141

42-
Use single quotes
42+
##Use single quotes
4343

4444
````javascript
4545
// good
@@ -49,7 +49,7 @@ $('.footer')
4949
$(".footer")
5050
````
5151

52-
Don't use magic numbers
52+
##Don't use magic numbers
5353

5454
````javascript
5555
// bad: what was 3 again? Text node? Comment?
@@ -66,7 +66,8 @@ if (el.nodeType === Node.TEXT_NODE) { ... }
6666
if ($('.blah').length === defaultRoomCount) { ... }
6767
````
6868

69-
Declare variables with var
69+
##Declare variables with var
70+
7071
Separate declarations with a semicolon and a line break.
7172

7273
````javascript
@@ -87,20 +88,40 @@ var length = items.length;
8788
var name = 'foo';
8889
````
8990

90-
Use a space before the opening curly brace
91+
##Use function expressions over function declarations
92+
93+
The function expression is clearly recognisable as what it really is (a variable with a function value). Additionally, it helps organize code so that all variable declarations appear at the top of a file, and invocations follow. This gives some predictablity when others are reading your code, allowing for a more consistent structure.
94+
95+
Function expressions are subject to [hoisting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting), and as such declaring functions as expressions will result in their being hoisted to the top of their enclosing function or global code.
96+
97+
98+
````javascript
99+
// bad
100+
function foo () {
101+
...
102+
}
103+
104+
// good
105+
var foo = function() {
106+
...
107+
}
108+
````
109+
110+
##Use a space before the opening curly brace for function calls
111+
91112
But no space before the opening argument parenthesis.
92113

93114
````javascript
94115
// bad
95-
function foo (){...}
116+
var foo = function(){...}
96117

97118
// good: whitespace improves readability here
98-
function foo() {
119+
var foo = function() {
99120
...
100121
}
101122
````
102123

103-
No preceding space before the opening parenthesis for function calls
124+
##No preceding space before the opening parenthesis for function calls
104125

105126
````javascript
106127
// bad: we want to differentiate between operations (see below) and function calls
@@ -110,7 +131,7 @@ doStuff ();
110131
doStuff();
111132
````
112133

113-
Cache the length in 'for' loops
134+
##Cache the length in 'for' loops
114135

115136
````javascript
116137
// bad: we are recalculating items.length every time
@@ -120,17 +141,17 @@ for (var i = 0; i < items.length; i++)
120141
for (var i = 0, length = items.length; i < length; i++)
121142
````
122143

123-
Use a space before the opening parenthesis for operations
144+
##Use a space before the opening parenthesis for conditions
124145

125146
````javascript
126-
// bad: we want to differentiate between function calls (see above) and operations
147+
// bad: we want to differentiate between function calls (see above) and conditions
127148
if(true)
128149

129150
// good
130151
if (true)
131152
````
132153

133-
Use a space between operands
154+
##Use a space between operands
134155

135156
````javascript
136157
// bad
@@ -140,7 +161,7 @@ var c=a+b;
140161
var c = a + b;
141162
````
142163

143-
Don’t use a newline before 'else' or 'else if' statements
164+
##Don’t use a newline before 'else' or 'else if' statements
144165

145166
````javascript
146167
// bad
@@ -159,7 +180,7 @@ if (true) {
159180
}
160181
````
161182

162-
Use a space after colons
183+
##Use a space after colons
163184

164185
````javascript
165186
// bad
@@ -171,7 +192,7 @@ Use a space after colons
171192
}
172193
````
173194

174-
Use curly braces, even if the block only has one line
195+
##Use curly braces, even if the block only has one line
175196

176197
````javascript
177198
// bad: it's more work to add a line to this block
@@ -183,7 +204,7 @@ if (isVisible) {
183204
}
184205
````
185206

186-
Return early when possible
207+
##Return early when possible
187208

188209
````javascript
189210
if (condition) {
@@ -192,7 +213,8 @@ if (condition) {
192213
// rest of codes
193214
````
194215

195-
Don't use the object type in your variable name
216+
##Don't use the object type in your variable name
217+
196218
Use a descriptive variable name instead.
197219

198220
````javascript
@@ -208,7 +230,7 @@ var items = [];
208230
var computer = {};
209231
````
210232

211-
Use camel-case for function names
233+
##Use camel case for function names
212234

213235
````javascript
214236
// bad: underscores shouldn’t be used in identifiers
@@ -221,7 +243,7 @@ function RecalculateItemHeight() { ... }
221243
function recalculateItemHeight() { ... }
222244
````
223245

224-
Use camel-case for variable names
246+
##Use camel case for variable names
225247

226248
````javascript
227249
// bad
@@ -231,7 +253,7 @@ var is_visible = true;
231253
var isVisible = true;
232254
````
233255

234-
Use Pascal case for constructors
256+
##Use Pascal case for constructors
235257

236258
````javascript
237259
// bad
@@ -249,7 +271,7 @@ function AwesomeMovie(options) {
249271
var fiftyShades = new AwesomeMovie({ title: '50 Shades Of Grey' });
250272
````
251273

252-
Declare methods for objects on the prototype, not in the object constructor
274+
##Declare methods for objects on the prototype, not in the object constructor
253275

254276
````javascript
255277
// bad
@@ -275,7 +297,7 @@ GoodExample.prototype.doSomeStuff = function() {
275297
};
276298
````
277299

278-
Cache variables if you use them more than once
300+
##Cache variables if you use them more than once
279301

280302
````javascript
281303
// bad: we're creating the same Zepto object multiple times
@@ -292,7 +314,7 @@ $('.items').on('click', function() {
292314
});
293315
````
294316

295-
Prepend jQuery/Zepto variables with $
317+
##Prepend jQuery/Zepto variables with $
296318

297319
````javascript
298320
// bad

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobify-code-style",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"description": "Code style guide and linting tools for Mobify",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)