Permalink
Browse files

CS: no yoda

  • Loading branch information...
1 parent 50c82bc commit 95c9f5fc102682a599cfbde76b8cbe9bd183ab01 @puzrin puzrin committed Feb 11, 2016
View
@@ -123,4 +123,4 @@ rules:
radix: 2
use-isnan: 2
valid-typeof: 2
- #yoda: [ 2, never, { "exceptRange": true } ]
+ yoda: [ 2, never, { "exceptRange": true } ]
View
@@ -108,8 +108,8 @@ readFile(options.file, 'utf8', function (error, input) {
yaml.loadAll(input, function (doc) { output.push(doc); }, {});
isYaml = true;
- if (0 === output.length) output = null;
- else if (1 === output.length) output = output[0];
+ if (output.length === 0) output = null;
+ else if (output.length === 1) output = output[0];
} catch (e) {
if (options.trace && err.stack) console.error(e.stack);
@@ -2,12 +2,12 @@
function isNothing(subject) {
- return (typeof subject === 'undefined') || (null === subject);
+ return (typeof subject === 'undefined') || (subject === null);
}
function isObject(subject) {
- return (typeof subject === 'object') && (null !== subject);
+ return (typeof subject === 'object') && (subject !== null);
}
@@ -47,7 +47,7 @@ function repeat(string, count) {
function isNegativeZero(number) {
- return (0 === number) && (Number.NEGATIVE_INFINITY === 1 / number);
+ return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
}
View
@@ -60,7 +60,7 @@ var DEPRECATED_BOOLEANS_SYNTAX = [
function compileStyleMap(schema, map) {
var result, keys, index, length, tag, style, type;
- if (null === map) return {};
+ if (map === null) return {};
result = {};
keys = Object.keys(map);
@@ -69,7 +69,7 @@ function compileStyleMap(schema, map) {
tag = keys[index];
style = String(map[tag]);
- if ('!!' === tag.slice(0, 2)) {
+ if (tag.slice(0, 2) === '!!') {
tag = 'tag:yaml.org,2002:' + tag.slice(2);
}
@@ -214,12 +214,12 @@ function writeScalar(state, object, level, iskey) {
position, escapeSeq, hexEsc, previous, lineLength, modifier,
trailingLineBreaks, result;
- if (0 === object.length) {
+ if (object.length === 0) {
state.dump = "''";
return;
}
- if (-1 !== DEPRECATED_BOOLEANS_SYNTAX.indexOf(object)) {
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(object) !== -1) {
state.dump = "'" + object + "'";
return;
}
@@ -477,7 +477,7 @@ function simpleChar(character) {
// Returns true if the character code needs to be escaped.
function needsHexEscape(character) {
return !((0x00020 <= character && character <= 0x00007E) ||
- (0x00085 === character) ||
+ (character === 0x00085) ||
(0x000A0 <= character && character <= 0x00D7FF) ||
(0x0E000 <= character && character <= 0x00FFFD) ||
(0x10000 <= character && character <= 0x10FFFF));
@@ -492,7 +492,7 @@ function writeFlowSequence(state, level, object) {
for (index = 0, length = object.length; index < length; index += 1) {
// Write only valid elements.
if (writeNode(state, level, object[index], false, false)) {
- if (0 !== index) _result += ', ';
+ if (index !== 0) _result += ', ';
_result += state.dump;
}
}
@@ -510,7 +510,7 @@ function writeBlockSequence(state, level, object, compact) {
for (index = 0, length = object.length; index < length; index += 1) {
// Write only valid elements.
if (writeNode(state, level + 1, object[index], true, true)) {
- if (!compact || 0 !== index) {
+ if (!compact || index !== 0) {
_result += generateNextLine(state, level);
}
_result += '- ' + state.dump;
@@ -534,7 +534,7 @@ function writeFlowMapping(state, level, object) {
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
pairBuffer = '';
- if (0 !== index) pairBuffer += ', ';
+ if (index !== 0) pairBuffer += ', ';
objectKey = objectKeyList[index];
objectValue = object[objectKey];
@@ -587,7 +587,7 @@ function writeBlockMapping(state, level, object, compact) {
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
pairBuffer = '';
- if (!compact || 0 !== index) {
+ if (!compact || index !== 0) {
pairBuffer += generateNextLine(state, level);
}
@@ -598,7 +598,7 @@ function writeBlockMapping(state, level, object, compact) {
continue; // Skip this pair because of invalid key.
}
- explicitPair = (null !== state.tag && '?' !== state.tag) ||
+ explicitPair = (state.tag !== null && state.tag !== '?') ||
(state.dump && state.dump.length > 1024);
if (explicitPair) {
@@ -644,15 +644,15 @@ function detectType(state, object, explicit) {
type = typeList[index];
if ((type.instanceOf || type.predicate) &&
- (!type.instanceOf || (('object' === typeof object) && (object instanceof type.instanceOf))) &&
+ (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
(!type.predicate || type.predicate(object))) {
state.tag = explicit ? type.tag : '?';
if (type.represent) {
style = state.styleMap[type.tag] || type.defaultStyle;
- if ('[object Function]' === _toString.call(type.represent)) {
+ if (_toString.call(type.represent) === '[object Function]') {
_result = type.represent(object, style);
} else if (_hasOwnProperty.call(type.represent, style)) {
_result = type.represent[style](object, style);
@@ -684,10 +684,10 @@ function writeNode(state, level, object, block, compact, iskey) {
var type = _toString.call(state.dump);
if (block) {
- block = (0 > state.flowLevel || state.flowLevel > level);
+ block = (state.flowLevel < 0 || state.flowLevel > level);
}
- var objectOrArray = '[object Object]' === type || '[object Array]' === type,
+ var objectOrArray = type === '[object Object]' || type === '[object Array]',
duplicateIndex,
duplicate;
@@ -696,7 +696,7 @@ function writeNode(state, level, object, block, compact, iskey) {
duplicate = duplicateIndex !== -1;
}
- if ((null !== state.tag && '?' !== state.tag) || duplicate || (2 !== state.indent && level > 0)) {
+ if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
compact = false;
}
@@ -706,8 +706,8 @@ function writeNode(state, level, object, block, compact, iskey) {
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
state.usedDuplicates[duplicateIndex] = true;
}
- if ('[object Object]' === type) {
- if (block && (0 !== Object.keys(state.dump).length)) {
+ if (type === '[object Object]') {
+ if (block && (Object.keys(state.dump).length !== 0)) {
writeBlockMapping(state, level, state.dump, compact);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + state.dump;
@@ -718,8 +718,8 @@ function writeNode(state, level, object, block, compact, iskey) {
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
}
}
- } else if ('[object Array]' === type) {
- if (block && (0 !== state.dump.length)) {
+ } else if (type === '[object Array]') {
+ if (block && (state.dump.length !== 0)) {
writeBlockSequence(state, level, state.dump, compact);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + state.dump;
@@ -730,16 +730,16 @@ function writeNode(state, level, object, block, compact, iskey) {
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
}
}
- } else if ('[object String]' === type) {
- if ('?' !== state.tag) {
+ } else if (type === '[object String]') {
+ if (state.tag !== '?') {
writeScalar(state, state.dump, level, iskey);
}
} else {
if (state.skipInvalid) return false;
throw new YAMLException('unacceptable kind of an object to dump ' + type);
}
- if (null !== state.tag && '?' !== state.tag) {
+ if (state.tag !== null && state.tag !== '?') {
state.dump = '!<' + state.tag + '> ' + state.dump;
}
}
@@ -766,10 +766,10 @@ function inspectNode(object, objects, duplicatesIndexes) {
index,
length;
- if (null !== object && 'object' === typeof object) {
+ if (object !== null && typeof object === 'object') {
index = objects.indexOf(object);
- if (-1 !== index) {
- if (-1 === duplicatesIndexes.indexOf(index)) {
+ if (index !== -1) {
+ if (duplicatesIndexes.indexOf(index) === -1) {
duplicatesIndexes.push(index);
}
} else {
Oops, something went wrong.

0 comments on commit 95c9f5f

Please sign in to comment.