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

Add jscs rule requireCurlyBraces and disallowKeywordsOnNewLine #10865

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"excludeFiles": ["src/ngLocale/**"],
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowNewlineBeforeBlockStatements": true,
Expand All @@ -22,6 +23,7 @@
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireLineFeedAtFileEnd": true,
"requireSpaceAfterBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
"requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
Expand Down
2 changes: 0 additions & 2 deletions .jscs.json.todo
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
// that correct the existing code base issues and make the new check pass.

{
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"disallowImplicitTypeConversion": ["string"],
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": ["else"],
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
Expand Down
78 changes: 56 additions & 22 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ function nextUid() {
function setHashKey(obj, h) {
if (h) {
obj.$$hashKey = h;
}
else {
} else {
delete obj.$$hashKey;
}
}
Expand Down Expand Up @@ -621,8 +620,9 @@ function isElement(node) {
*/
function makeMap(str) {
var obj = {}, items = str.split(","), i;
for (i = 0; i < items.length; i++)
for (i = 0; i < items.length; i++) {
obj[ items[i] ] = true;
}
return obj;
}

Expand All @@ -637,8 +637,9 @@ function includes(array, obj) {

function arrayRemove(array, value) {
var index = array.indexOf(value);
if (index >= 0)
if (index >= 0) {
array.splice(index, 1);
}
return value;
}

Expand Down Expand Up @@ -722,15 +723,18 @@ function copy(source, destination, stackSource, stackDest) {
}
}
} else {
if (source === destination) throw ngMinErr('cpi',
"Can't copy! Source and destination are identical.");
if (source === destination) {
throw ngMinErr('cpi', "Can't copy! Source and destination are identical.");
}

stackSource = stackSource || [];
stackDest = stackDest || [];

if (isObject(source)) {
var index = stackSource.indexOf(source);
if (index !== -1) return stackDest[index];
if (index !== -1) {
return stackDest[index];
}

stackSource.push(source);
stackDest.push(destination);
Expand Down Expand Up @@ -829,38 +833,58 @@ function shallowCopy(src, dst) {
* @returns {boolean} True if arguments are equal.
*/
function equals(o1, o2) {
if (o1 === o2) return true;
if (o1 === null || o2 === null) return false;
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
if (o1 === o2) {
return true;
}
if (o1 === null || o2 === null) {
return false;
}
if (o1 !== o1 && o2 !== o2) { // NaN === NaN
return true;
}
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 == t2) {
if (t1 == 'object') {
if (isArray(o1)) {
if (!isArray(o2)) return false;
if (!isArray(o2)) {
return false;
}
if ((length = o1.length) == o2.length) {
for (key = 0; key < length; key++) {
if (!equals(o1[key], o2[key])) return false;
if (!equals(o1[key], o2[key])) {
return false;
}
}
return true;
}
} else if (isDate(o1)) {
if (!isDate(o2)) return false;
if (!isDate(o2)) {
return false;
}
return equals(o1.getTime(), o2.getTime());
} else if (isRegExp(o1) && isRegExp(o2)) {
return o1.toString() == o2.toString();
} else {
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return false;
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) {
return false;
}
keySet = {};
for (key in o1) {
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
if (!equals(o1[key], o2[key])) return false;
if (key.charAt(0) === '$' || isFunction(o1[key])) {
continue;
}
if (!equals(o1[key], o2[key])) {
return false;
}
keySet[key] = true;
}
for (key in o2) {
if (!keySet.hasOwnProperty(key) &&
key.charAt(0) !== '$' &&
o2[key] !== undefined &&
!isFunction(o2[key])) return false;
!isFunction(o2[key])) {
return false;
}
}
return true;
}
Expand All @@ -870,7 +894,9 @@ function equals(o1, o2) {
}

var csp = function() {
if (isDefined(csp.isActive_)) return csp.isActive_;
if (isDefined(csp.isActive_)) {
return csp.isActive_;
}

var active = !!(document.querySelector('[ng-csp]') ||
document.querySelector('[data-ng-csp]'));
Expand Down Expand Up @@ -972,7 +998,9 @@ function toJsonReplacer(key, value) {
* @returns {string|undefined} JSON-ified string representing `obj`.
*/
function toJson(obj, pretty) {
if (typeof obj === 'undefined') return undefined;
if (typeof obj === 'undefined') {
return undefined;
}
if (!isNumber(pretty)) {
pretty = pretty ? 2 : null;
}
Expand Down Expand Up @@ -1344,7 +1372,9 @@ function angularInit(element, bootstrap) {
* @returns {auto.$injector} Returns the newly created injector for this app.
*/
function bootstrap(element, modules, config) {
if (!isObject(config)) config = {};
if (!isObject(config)) {
config = {};
}
var defaultConfig = {
strictDi: false
};
Expand Down Expand Up @@ -1540,7 +1570,9 @@ function assertNotHasOwnProperty(name, context) {
*/
//TODO(misko): this function needs to be removed
function getter(obj, path, bindFnToScope) {
if (!path) return obj;
if (!path) {
return obj;
}
var keys = path.split('.');
var key;
var lastInstance = obj;
Expand Down Expand Up @@ -1572,7 +1604,9 @@ function getBlockNodes(nodes) {

do {
node = node.nextSibling;
if (!node) break;
if (!node) {
break;
}
blockNodes.push(node);
} while (node !== endNode);

Expand Down
4 changes: 3 additions & 1 deletion src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ function createInjector(modulesToLoad, strictDi) {
function loadModules(modulesToLoad) {
var runBlocks = [], moduleFn;
forEach(modulesToLoad, function(module) {
if (loadedModules.get(module)) return;
if (loadedModules.get(module)) {
return;
}
loadedModules.put(module, true);

function runInvokeQueue(queue) {
Expand Down
60 changes: 45 additions & 15 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ function jqLiteClone(element) {
}

function jqLiteDealoc(element, onlyDescendants) {
if (!onlyDescendants) jqLiteRemoveData(element);
if (!onlyDescendants) {
jqLiteRemoveData(element);
}

if (element.querySelectorAll) {
var descendants = element.querySelectorAll('*');
Expand All @@ -265,13 +267,18 @@ function jqLiteDealoc(element, onlyDescendants) {
}

function jqLiteOff(element, type, fn, unsupported) {
if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
if (isDefined(unsupported)) {
throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
}

var expandoStore = jqLiteExpandoStore(element);
var events = expandoStore && expandoStore.events;
var handle = expandoStore && expandoStore.handle;

if (!handle) return; //no listeners registered
if (!handle) {
//no listeners registered
return;
}

if (!type) {
for (type in events) {
Expand Down Expand Up @@ -358,7 +365,9 @@ function jqLiteData(element, key, value) {
}

function jqLiteHasClass(element, selector) {
if (!element.getAttribute) return false;
if (!element.getAttribute) {
return false;
}
return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " ").
indexOf(" " + selector + " ") > -1);
}
Expand Down Expand Up @@ -432,7 +441,9 @@ function jqLiteInheritedData(element, name, value) {

while (element) {
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = jqLite.data(element, names[i])) !== undefined) return value;
if ((value = jqLite.data(element, names[i])) !== undefined) {
return value;
}
}

// If dealing with a document fragment node with a host element, and no parent, use the host
Expand All @@ -450,9 +461,13 @@ function jqLiteEmpty(element) {
}

function jqLiteRemove(element, keepData) {
if (!keepData) jqLiteDealoc(element);
if (!keepData) {
jqLiteDealoc(element);
}
var parent = element.parentNode;
if (parent) parent.removeChild(element);
if (parent) {
parent.removeChild(element);
}
}


Expand All @@ -477,7 +492,9 @@ var JQLitePrototype = JQLite.prototype = {
var fired = false;

function trigger() {
if (fired) return;
if (fired) {
return;
}
fired = true;
fn();
}
Expand Down Expand Up @@ -721,7 +738,9 @@ function createEventHandler(element, events) {
var eventFns = events[type || event.type];
var eventFnsLength = eventFns ? eventFns.length : 0;

if (!eventFnsLength) return;
if (!eventFnsLength) {
return;
}

if (isUndefined(event.immediatePropagationStopped)) {
var originalStopImmediatePropagation = event.stopImmediatePropagation;
Expand Down Expand Up @@ -769,7 +788,9 @@ forEach({
removeData: jqLiteRemoveData,

on: function jqLiteOn(element, type, fn, unsupported) {
if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');
if (isDefined(unsupported)) {
throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');
}

// Do not add event handlers to non-elements because they will not be cleaned up.
if (!jqLiteAcceptsData(element)) {
Expand Down Expand Up @@ -851,8 +872,9 @@ forEach({
children: function(element) {
var children = [];
forEach(element.childNodes, function(element) {
if (element.nodeType === NODE_TYPE_ELEMENT)
if (element.nodeType === NODE_TYPE_ELEMENT) {
children.push(element);
}
});
return children;
},
Expand All @@ -863,7 +885,9 @@ forEach({

append: function(element, node) {
var nodeType = element.nodeType;
if (nodeType !== NODE_TYPE_ELEMENT && nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT) return;
if (nodeType !== NODE_TYPE_ELEMENT && nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT) {
return;
}

node = new JQLite(node);

Expand Down Expand Up @@ -1010,15 +1034,21 @@ function $$jqLiteProvider() {
this.$get = function $$jqLite() {
return extend(JQLite, {
hasClass: function(node, classes) {
if (node.attr) node = node[0];
if (node.attr) {
node = node[0];
}
return jqLiteHasClass(node, classes);
},
addClass: function(node, classes) {
if (node.attr) node = node[0];
if (node.attr) {
node = node[0];
}
return jqLiteAddClass(node, classes);
},
removeClass: function(node, classes) {
if (node.attr) node = node[0];
if (node.attr) {
node = node[0];
}
return jqLiteRemoveClass(node, classes);
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ function setupModuleLoader(window) {
* @returns {angular.Module}
*/
function invokeLater(provider, method, insertMethod, queue) {
if (!queue) queue = invokeQueue;
if (!queue) {
queue = invokeQueue;
}
return function() {
queue[insertMethod || 'push']([provider, method, arguments]);
return moduleInstance;
Expand Down
Loading