Skip to content

Commit

Permalink
Merge pull request moment#1718 from ichernev/jscs-support
Browse files Browse the repository at this point in the history
Jscs support

@changelog
@section misc
@description code style checking with jscs (jshint is only for bug detection)
  • Loading branch information
ichernev committed Jun 19, 2014
2 parents bc84a17 + 9fd1c26 commit b5c9b3f
Show file tree
Hide file tree
Showing 94 changed files with 1,107 additions and 1,030 deletions.
63 changes: 63 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireMultipleVarDecl": "onevar",
"requireBlocksOnNewline": true,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=",

"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"disallowKeywords": ["with"],
"disallowMultipleLineStrings": true,
"validateLineBreaks": "LF",
"validateIndentation": 4,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true
}
22 changes: 17 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = function (grunt) {

var embedOption = grunt.option('embedLanguages'),
embedLanguageDest = embedOption ?
'min/moment-with-customlangs.js' :
Expand Down Expand Up @@ -160,6 +159,15 @@ module.exports = function (grunt) {
}
}
},
jscs: {
all: [
"Gruntfile.js", "moment.js", "lang/**/*.js",
"test/**/*.js", "!test/browser*.js"
],
options: {
config: ".jscs.json"
}
},
watch : {
test : {
files : [
Expand Down Expand Up @@ -187,9 +195,9 @@ module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);

// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);
grunt.registerTask('default', ['jshint', 'jscs', 'nodeunit']);

//test tasks
// test tasks
grunt.registerTask('test', ['test:node', 'test:browser']);
grunt.registerTask('test:node', ['nodeunit']);
grunt.registerTask('test:server', ['concat', 'embedLanguages', 'karma:server']);
Expand All @@ -199,8 +207,12 @@ module.exports = function (grunt) {

// travis build task
grunt.registerTask('build:travis', [
'jshint', 'test:node', 'check-sauce-creds',
'test:travis-sauce-browser'
// code style
'jshint', 'jscs',
// node tests
'test:node',
// sauce tests
'check-sauce-creds', 'test:travis-sauce-browser'
]);

// Task to be run when releasing a new version
Expand Down
2 changes: 1 addition & 1 deletion lang/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
return symbolMap[match];
});
},
//Bengali is a vast language its spoken
//Bengali is a vast language its spoken
//in different forms in various parts of the world.
//I have just generalized with most common one used
meridiem : function (hour, minute, isLower) {
Expand Down
4 changes: 2 additions & 2 deletions lang/bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
}

return moment.lang('bs', {
months : "januar_februar_mart_april_maj_juni_juli_avgust_septembar_oktobar_novembar_decembar".split("_"),
monthsShort : "jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.".split("_"),
months : "januar_februar_mart_april_maj_juni_juli_avgust_septembar_oktobar_novembar_decembar".split("_"),
monthsShort : "jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.".split("_"),
weekdays : "nedjelja_ponedjeljak_utorak_srijeda_četvrtak_petak_subota".split("_"),
weekdaysShort : "ned._pon._uto._sri._čet._pet._sub.".split("_"),
weekdaysMin : "ne_po_ut_sr_če_pe_su".split("_"),
Expand Down
2 changes: 1 addition & 1 deletion lang/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
nextDay : '[Αύριο {}] LT',
nextWeek : 'dddd [{}] LT',
lastDay : '[Χθες {}] LT',
lastWeek : function() {
lastWeek : function () {
switch (this.day()) {
case 6:
return '[το προηγούμενο] dddd [{}] LT';
Expand Down
2 changes: 1 addition & 1 deletion lang/en-au.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
ordinal : function (number) {
var b = number % 10,
output = (~~ (number % 100 / 10) === 1) ? 'th' :
output = (~~(number % 100 / 10) === 1) ? 'th' :
(b === 1) ? 'st' :
(b === 2) ? 'nd' :
(b === 3) ? 'rd' : 'th';
Expand Down
2 changes: 1 addition & 1 deletion lang/en-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
ordinal : function (number) {
var b = number % 10,
output = (~~ (number % 100 / 10) === 1) ? 'th' :
output = (~~(number % 100 / 10) === 1) ? 'th' :
(b === 1) ? 'st' :
(b === 2) ? 'nd' :
(b === 3) ? 'rd' : 'th';
Expand Down
2 changes: 1 addition & 1 deletion lang/en-gb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
ordinal : function (number) {
var b = number % 10,
output = (~~ (number % 100 / 10) === 1) ? 'th' :
output = (~~(number % 100 / 10) === 1) ? 'th' :
(b === 1) ? 'st' :
(b === 2) ? 'nd' :
(b === 3) ? 'rd' : 'th';
Expand Down
6 changes: 4 additions & 2 deletions lang/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
}
}(function (moment) {
var numbersPast = 'nolla yksi kaksi kolme neljä viisi kuusi seitsemän kahdeksan yhdeksän'.split(' '),
numbersFuture = ['nolla', 'yhden', 'kahden', 'kolmen', 'neljän', 'viiden', 'kuuden',
numbersPast[7], numbersPast[8], numbersPast[9]];
numbersFuture = [
'nolla', 'yhden', 'kahden', 'kolmen', 'neljän', 'viiden', 'kuuden',
numbersPast[7], numbersPast[8], numbersPast[9]
];

function translate(number, withoutSuffix, key, isFuture) {
var result = "";
Expand Down
2 changes: 1 addition & 1 deletion lang/ko.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// moment.js language configuration
// language : korean (ko)
//
// authors
// authors
//
// - Kyungwook, Park : https://github.com/kyungw00k
// - Jeeeyul Lee <[email protected]>
Expand Down
12 changes: 6 additions & 6 deletions lang/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
}(function (moment) {
function relativeTimeWithPlural(number, withoutSuffix, key) {
var format = {
'mm': 'minute',
'hh': 'ore',
'dd': 'zile',
'MM': 'luni',
'yy': 'ani'
},
'mm': 'minute',
'hh': 'ore',
'dd': 'zile',
'MM': 'luni',
'yy': 'ani'
},
separator = ' ';
if (number % 100 >= 20 || (number >= 100 && number % 100 === 0)) {
separator = ' de ';
Expand Down
2 changes: 1 addition & 1 deletion lang/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
ordinal : function (number) {
var b = number % 10,
output = (~~ (number % 100 / 10) === 1) ? 'e' :
output = (~~(number % 100 / 10) === 1) ? 'e' :
(b === 1) ? 'a' :
(b === 2) ? 'a' :
(b === 3) ? 'e' : 'e';
Expand Down
12 changes: 6 additions & 6 deletions lang/ta.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@
},


// refer http://ta.wikipedia.org/s/1er1
// refer http://ta.wikipedia.org/s/1er1

meridiem : function (hour, minute, isLower) {
if (hour >= 6 && hour <= 10) {
return " காலை";
} else if (hour >= 10 && hour <= 14) {
} else if (hour >= 10 && hour <= 14) {
return " நண்பகல்";
} else if (hour >= 14 && hour <= 18) {
} else if (hour >= 14 && hour <= 18) {
return " எற்பாடு";
} else if (hour >= 18 && hour <= 20) {
} else if (hour >= 18 && hour <= 20) {
return " மாலை";
} else if (hour >= 20 && hour <= 24) {
} else if (hour >= 20 && hour <= 24) {
return " இரவு";
} else if (hour >= 0 && hour <= 6) {
} else if (hour >= 0 && hour <= 6) {
return " வைகறை";
}
},
Expand Down
91 changes: 56 additions & 35 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
res.months = other.month() - base.month() +
(other.year() - base.year()) * 12;
if (base.clone().add(res.months, 'M').isAfter(other)) {
-- res.months;
--res.months;
}

res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
Expand All @@ -482,8 +482,8 @@
res = positiveMomentsDifference(base, other);
} else {
res = positiveMomentsDifference(other, base);
res.milliseconds = - res.milliseconds;
res.months = - res.months;
res.milliseconds = -res.milliseconds;
res.months = -res.months;
}

return res;
Expand Down Expand Up @@ -516,8 +516,8 @@
}

function isDate(input) {
return Object.prototype.toString.call(input) === '[object Date]' ||
input instanceof Date;
return Object.prototype.toString.call(input) === '[object Date]' ||
input instanceof Date;
}

// compare two arrays, return the number of differences
Expand Down Expand Up @@ -1035,13 +1035,19 @@
case 'ggggg':
return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
case 'S':
if (strict) { return parseTokenOneDigit; }
if (strict) {
return parseTokenOneDigit;
}
/* falls through */
case 'SS':
if (strict) { return parseTokenTwoDigits; }
if (strict) {
return parseTokenTwoDigits;
}
/* falls through */
case 'SSS':
if (strict) { return parseTokenThreeDigits; }
if (strict) {
return parseTokenThreeDigits;
}
/* falls through */
case 'DDD':
return parseTokenOneToThreeDigits;
Expand Down Expand Up @@ -1730,13 +1736,14 @@
moment.suppressDeprecationWarnings = false;

moment.createFromInputFallback = deprecate(
"moment construction falls back to js Date. This is " +
"discouraged and will be removed in upcoming major " +
"release. Please refer to " +
"https://github.com/moment/moment/issues/1407 for more info.",
function (config) {
config._d = new Date(config._i);
});
"moment construction falls back to js Date. This is " +
"discouraged and will be removed in upcoming major " +
"release. Please refer to " +
"https://github.com/moment/moment/issues/1407 for more info.",
function (config) {
config._d = new Date(config._i);
}
);

// Pick a moment m from moments so that m[fn](other) is true for all
// other. This relies on the function fn to be transitive.
Expand Down Expand Up @@ -1888,17 +1895,15 @@
moment.updateOffset = function () {};

// This function allows you to set a threshold for relative time strings
moment.relativeTimeThreshold = function(threshold, limit) {
if (relativeTimeThresholds[threshold] === undefined) {
return false;
}

if(limit === undefined){
return relativeTimeThresholds[threshold];
}

relativeTimeThresholds[threshold] = limit;
return true;
moment.relativeTimeThreshold = function (threshold, limit) {
if (relativeTimeThresholds[threshold] === undefined) {
return false;
}
if (limit === undefined) {
return relativeTimeThresholds[threshold];
}
relativeTimeThresholds[threshold] = limit;
return true;
};

// This function will load languages and then set the global language. If
Expand Down Expand Up @@ -2151,7 +2156,7 @@
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
if (input != null) {
input = parseWeekday(input, this.lang());
return this.add({ d : input - day });
return this.add(input - day, 'days');
} else {
return day;
}
Expand Down Expand Up @@ -2636,14 +2641,30 @@
}
}

moment.duration.fn.asMilliseconds = function () { return this.as('ms'); };
moment.duration.fn.asSeconds = function () { return this.as('s'); };
moment.duration.fn.asMinutes = function () { return this.as('m'); };
moment.duration.fn.asHours = function () { return this.as('h'); };
moment.duration.fn.asDays = function () { return this.as('d'); };
moment.duration.fn.asWeeks = function () { return this.as('weeks'); };
moment.duration.fn.asMonths = function () { return this.as('M'); };
moment.duration.fn.asYears = function () { return this.as('y'); };
moment.duration.fn.asMilliseconds = function () {
return this.as('ms');
};
moment.duration.fn.asSeconds = function () {
return this.as('s');
};
moment.duration.fn.asMinutes = function () {
return this.as('m');
};
moment.duration.fn.asHours = function () {
return this.as('h');
};
moment.duration.fn.asDays = function () {
return this.as('d');
};
moment.duration.fn.asWeeks = function () {
return this.as('weeks');
};
moment.duration.fn.asMonths = function () {
return this.as('M');
};
moment.duration.fn.asYears = function () {
return this.as('y');
};

/************************************
Default Lang
Expand Down
Loading

0 comments on commit b5c9b3f

Please sign in to comment.