Skip to content

Commit

Permalink
lib: Use === where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoltman committed Feb 15, 2018
1 parent 913d92c commit 9d31c23
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/ColumnDefinitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const ColumnDefinitions = {
},
enum() {
const argsLength = arguments.length;
if (!argsLength) {
if (argsLength === 0) {
throw new Error('You must provide at least one possible enum value');
}
const values = new Array(argsLength);
Expand All @@ -129,7 +129,7 @@ const ColumnDefinitions = {
},
set() {
const argsLength = arguments.length;
if (!argsLength) {
if (argsLength === 0) {
throw new Error('You must provide at least one possible set value');
}
const values = new Array(argsLength);
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQLTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MySQLTable {

sqlString = 'SELECT EXISTS ( SELECT 1 FROM ' + this._escapedName + ' ' + sqlString + ' LIMIT 1 ) as `exists`';

if (!cb) {
if (cb === undefined) {
return this._db.pquery(sqlString, values).then(checkExists);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/PoolPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MIGRATION_STRATEGIES = [

function isObjectEmpty(obj) {
for (var key in obj) {
if (!obj.hasOwnProperty || obj.hasOwnProperty(key)) {
if (obj.hasOwnProperty === undefined || obj.hasOwnProperty(key)) {
return false;
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ class PoolPlus extends Pool {
}

var tablesRemaining = this._tables.size;
if (!tablesRemaining) {
if (tablesRemaining === 0) {
process.nextTick(cb);
return; // eslint-disable-line consistent-return
}
Expand Down Expand Up @@ -335,7 +335,7 @@ class PoolPlus extends Pool {
}

const trxnPromise = trxnHandler(connection, handleDone);
if (trxnPromise) {
if (typeof trxnPromise === 'object' && trxnPromise !== null) {
trxnPromise.then(commit, rollback);
}
});
Expand Down Expand Up @@ -395,7 +395,7 @@ class PoolPlus extends Pool {
}

_runOperations(operations, cb) {
if (!operations.length) {
if (operations.length === 0) {
cb();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/TableDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TableDefinition {
const oldColumnDefinition = oldSchema.columns[oldColumnName];
const position = lastColumnName ? ' AFTER ' + pool.escapeId(lastColumnName) : ' FIRST';

if (!oldColumnDefinition) {
if (oldColumnDefinition === undefined) {
operations.push(Operation.create(
Operation.Types.ADD_COLUMN,
'ADD COLUMN ' + pool.escapeId(columnName) + ' ' + newColumnDefinition.$toSQL() + position
Expand Down Expand Up @@ -545,7 +545,7 @@ function createNormalizedSchema(schema) {
}

function getNormalizedForeignKeys(foreignKeys) {
if (!foreignKeys) {
if (foreignKeys === undefined) {
return foreignKeys;
}

Expand Down
22 changes: 8 additions & 14 deletions lib/sqlToSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,15 @@ function generateColumnsSchema(createDefinitions) {

function columnsSQLToSchema(sql) {
const schema = sql.replace(/`|\s/g, '');

return schema.indexOf(',') >= 0 ? schema.split(',') : schema;
}

function generatePrimaryKeySchema(createDefinitions) {
const rgxPrimaryKey = /^\s*PRIMARY KEY \((.*?)\)/;

for (var i = 0; i < createDefinitions.length; i++) {
var pkMatch = rgxPrimaryKey.exec(createDefinitions[i]);

if (pkMatch) {
const pkMatch = rgxPrimaryKey.exec(createDefinitions[i]);
if (pkMatch !== null) {
return columnsSQLToSchema(pkMatch[1]);
}
}
Expand All @@ -163,9 +161,8 @@ function generateKeysSchema(createDefinitions, keyType) {
}

for (var i = 0; i < createDefinitions.length; i++) {
var keyMatch = rgxKey.exec(createDefinitions[i]);

if (keyMatch) {
const keyMatch = rgxKey.exec(createDefinitions[i]);
if (keyMatch !== null) {
keys.push(columnsSQLToSchema(keyMatch[1]));
}
}
Expand All @@ -179,9 +176,8 @@ function getUnknownKeys(createDefinitions) {
/^\s*(?:UNIQUE KEY `((?!unique_)\w+)`|KEY `((?!index_)\w+)`|SPATIAL KEY `((?!spatial_)\w+)`) \((.*?)\)/;

for (var i = 0; i < createDefinitions.length; i++) {
var keyMatch = rgxKey.exec(createDefinitions[i]);

if (keyMatch) {
const keyMatch = rgxKey.exec(createDefinitions[i]);
if (keyMatch !== null) {
keys.push({
name: keyMatch[1] || keyMatch[2] || keyMatch[3],
columns: columnsSQLToSchema(keyMatch[4]),
Expand All @@ -198,14 +194,12 @@ function generateForegnKeysSchema(createDefinitions) {
/\s*CONSTRAINT `\w+` FOREIGN KEY \(`(.*?)`\) REFERENCES `(\w+)` \((.*?)\)(?: ON DELETE (RESTRICT|CASCADE|SET NULL|NO ACTION))?(?: ON UPDATE (RESTRICT|CASCADE|SET NULL|NO ACTION))?/;

for (var i = 0; i < createDefinitions.length; i++) {
var keyMatch = rgxForeignKey.exec(createDefinitions[i]);

if (!keyMatch) {
const keyMatch = rgxForeignKey.exec(createDefinitions[i]);
if (keyMatch === null) {
continue;
}

const keyColumns = columnsSQLToSchema(keyMatch[1]);

foreignKeys[keyColumns] = {
table: keyMatch[2],
column: columnsSQLToSchema(keyMatch[3]),
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/cloneKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict';

function cloneKeys(keys) {
if (!keys) {
if (keys === undefined || keys === null) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions lib/utils/diffKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
'use strict';

function diffKeys(original, current) {
if (!original) {
if (original === undefined || original === null) {
return {
addedKeys: current ? current.slice() : [],
addedKeys: current === undefined || current === null
? []
: current.slice(),
removedKeys: [],
};
}
if (!current) {
if (current === undefined || current === null) {
return {
addedKeys: [],
removedKeys: original.slice(),
Expand Down

0 comments on commit 9d31c23

Please sign in to comment.