Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 1d7d39d

Browse files
Krinklemarkelog
authored andcommitted
Preset: update wikimedia preset
Preset: Update order of rules to match node-jscs documentation. * requireSpaceBeforeKeywords: Add. * requireSpaceAfterKeywords: Simplify by using true. * disallowSpacesInCallExpression: Add. * requireSpacesInsideParentheses: Add. * disallowQuotedKeysInObjects: Change from all to allButReserved for ES3. * requireSpaceBeforeBinaryOperators: Simplify by using true. It was hardcoded as it used include ",", but that was fixed. * disallowImplicitTypeConversion: Add, require explicit '!== -1' and String(). * disallowOperatorBeforeLineBreak: Add, place dots in chaining before line break. * requireLineBreakAfterVariableAssignment: Add. * requireSpaceAfterLineComment: Add. * disallowNewlineBeforeBlockStatements: Add. Test: * Add example of space before keyword 'empty' and 'while'. * Add example of one-line block. * Add example of quoted ES3 reserved word object key. * Add example of type converstion and method chaining. Closes gh-843
1 parent 5ccacb5 commit 1d7d39d

File tree

2 files changed

+78
-42
lines changed

2 files changed

+78
-42
lines changed

presets/wikimedia.json

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@
88
"try",
99
"catch"
1010
],
11-
"requireSpaceAfterKeywords": [
12-
"if",
13-
"else",
14-
"for",
15-
"while",
16-
"do",
17-
"switch",
18-
"case",
19-
"return",
20-
"try",
21-
"catch",
22-
"function",
23-
"typeof"
24-
],
11+
"requireSpaceBeforeKeywords": true,
12+
"requireSpaceAfterKeywords": true,
2513
"requireSpaceBeforeBlockStatements": true,
2614
"requireParenthesesAroundIIFE": true,
2715
"requireSpacesInConditionalExpression": true,
@@ -31,52 +19,51 @@
3119
"disallowSpacesInFunctionDeclaration": {
3220
"beforeOpeningRoundBrace": true
3321
},
22+
"disallowSpacesInCallExpression": true,
3423
"requireMultipleVarDecl": "onevar",
3524
"requireBlocksOnNewline": 1,
3625
"disallowEmptyBlocks": true,
3726
"requireSpacesInsideObjectBrackets": "all",
3827
"requireSpacesInsideArrayBrackets": "all",
39-
"disallowQuotedKeysInObjects": true,
28+
"requireSpacesInsideParentheses": "all",
29+
"disallowQuotedKeysInObjects": "allButReserved",
4030
"disallowDanglingUnderscores": true,
4131
"disallowSpaceAfterObjectKeys": true,
32+
"requireSpaceBeforeObjectValues": true,
4233
"requireCommaBeforeLineBreak": true,
4334
"disallowSpaceAfterPrefixUnaryOperators": true,
4435
"disallowSpaceBeforePostfixUnaryOperators": true,
4536
"disallowSpaceBeforeBinaryOperators": [
4637
","
4738
],
48-
"requireSpaceBeforeBinaryOperators": [
49-
"=",
50-
"+=",
51-
"-=",
52-
"+",
53-
"-",
54-
"*",
55-
"/",
56-
"&&",
57-
"||",
58-
"===",
59-
"==",
60-
">=",
61-
"<=",
62-
">",
63-
"<",
64-
"!=",
65-
"!=="
66-
],
39+
"requireSpaceBeforeBinaryOperators": true,
6740
"requireSpaceAfterBinaryOperators": true,
41+
"disallowImplicitTypeConversion": [
42+
"binary",
43+
"string"
44+
],
6845
"requireCamelCaseOrUpperCaseIdentifiers": true,
69-
"disallowKeywords": [ "with" ],
46+
"disallowKeywords": [
47+
"with"
48+
],
7049
"disallowMultipleLineBreaks": true,
71-
"validateLineBreaks": "LF",
72-
"validateQuoteMarks": "'",
73-
"validateIndentation": "\t",
7450
"disallowMixedSpacesAndTabs": true,
51+
"disallowOperatorBeforeLineBreak": [
52+
"."
53+
],
7554
"disallowTrailingWhitespace": true,
7655
"disallowTrailingComma": true,
77-
"disallowKeywordsOnNewLine": [ "else" ],
56+
"disallowKeywordsOnNewLine": [
57+
"else"
58+
],
59+
"requireLineBreakAfterVariableAssignment": true,
7860
"requireLineFeedAtFileEnd": true,
7961
"requireCapitalizedConstructors": true,
8062
"requireDotNotation": true,
81-
"disallowYodaConditions": true
63+
"disallowYodaConditions": true,
64+
"requireSpaceAfterLineComment": true,
65+
"disallowNewlineBeforeBlockStatements": true,
66+
"validateLineBreaks": "LF",
67+
"validateQuoteMarks": "'",
68+
"validateIndentation": "\t"
8269
}

test/data/options/preset/wikimedia.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
var APP,
33
hasOwn = Object.prototype.hasOwnProperty;
44

5+
// Empty function declaration
56
function upHere() {}
67

8+
// Non-empty function declaration
9+
function upHereAlso( y ) {
10+
return y;
11+
}
12+
713
/**
814
* Example description.
915
*
@@ -19,10 +25,14 @@
1925

2026
this.total = upHere() + id;
2127

22-
name = options.bar ? upHere( id ) : id;
28+
name = options.bar ? upHereAlso( id ) : id;
2329

2430
if ( options.quux ) {
2531
name += options.quux;
32+
} else if ( options.quux ) {
33+
name += options.quux;
34+
} else {
35+
name += 'default';
2636
}
2737

2838
if ( bar &&
@@ -33,6 +43,16 @@
3343
return;
3444
}
3545

46+
// One line function
47+
inline = function ( items ) { return items.slice(); };
48+
49+
// Multi-line function
50+
inline = function ( items ) {
51+
items = items.slice();
52+
items.pop();
53+
return items;
54+
};
55+
3656
inline = function named( items ) {
3757
try {
3858
return APP.loop( items );
@@ -49,6 +69,7 @@
4969

5070
APP.loop = function ( items ) {
5171
var i, len, item, key,
72+
j = 1,
5273
ret = {};
5374

5475
for ( i = 0, len = items.length; i < len; i++ ) {
@@ -68,6 +89,11 @@
6889
}
6990
}
7091

92+
do {
93+
j = i++;
94+
APP.fall( --j );
95+
} while ( i < 5 );
96+
7197
return ret;
7298
};
7399

@@ -80,12 +106,35 @@
80106
}
81107
};
82108

109+
APP.cast = function ( options, val ) {
110+
options.enable = !!val;
111+
options.disable = Boolean( val );
112+
113+
options.posX = +val;
114+
options.posY = Number( val );
115+
116+
options.title = String( val );
117+
118+
return options.title.indexOf( '.' ) !== -1;
119+
};
120+
83121
APP.example = new APP.Example( 'banana', {
84122
first: 'Who',
85123
second: 'What',
86-
third: 'I don\'t know'
124+
third: 'I don\'t know',
125+
'default': 'Legacy'
87126
} );
88127

128+
APP.example( 'banana' )
129+
.done( function () { } );
130+
131+
APP.example( 'banana' )
132+
.done( function () {} )
133+
.fail( function () {} );
134+
135+
APP.$head
136+
.appendTo( APP.$element );
137+
89138
global.APP = APP;
90139

91140
}( this ) );

0 commit comments

Comments
 (0)