Skip to content

Commit 9d31c23

Browse files
committed
lib: Use === where possible
1 parent 913d92c commit 9d31c23

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

lib/ColumnDefinitions/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const ColumnDefinitions = {
118118
},
119119
enum() {
120120
const argsLength = arguments.length;
121-
if (!argsLength) {
121+
if (argsLength === 0) {
122122
throw new Error('You must provide at least one possible enum value');
123123
}
124124
const values = new Array(argsLength);
@@ -129,7 +129,7 @@ const ColumnDefinitions = {
129129
},
130130
set() {
131131
const argsLength = arguments.length;
132-
if (!argsLength) {
132+
if (argsLength === 0) {
133133
throw new Error('You must provide at least one possible set value');
134134
}
135135
const values = new Array(argsLength);

lib/MySQLTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class MySQLTable {
136136

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

139-
if (!cb) {
139+
if (cb === undefined) {
140140
return this._db.pquery(sqlString, values).then(checkExists);
141141
}
142142

lib/PoolPlus.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const MIGRATION_STRATEGIES = [
2020

2121
function isObjectEmpty(obj) {
2222
for (var key in obj) {
23-
if (!obj.hasOwnProperty || obj.hasOwnProperty(key)) {
23+
if (obj.hasOwnProperty === undefined || obj.hasOwnProperty(key)) {
2424
return false;
2525
}
2626
}
@@ -184,7 +184,7 @@ class PoolPlus extends Pool {
184184
}
185185

186186
var tablesRemaining = this._tables.size;
187-
if (!tablesRemaining) {
187+
if (tablesRemaining === 0) {
188188
process.nextTick(cb);
189189
return; // eslint-disable-line consistent-return
190190
}
@@ -335,7 +335,7 @@ class PoolPlus extends Pool {
335335
}
336336

337337
const trxnPromise = trxnHandler(connection, handleDone);
338-
if (trxnPromise) {
338+
if (typeof trxnPromise === 'object' && trxnPromise !== null) {
339339
trxnPromise.then(commit, rollback);
340340
}
341341
});
@@ -395,7 +395,7 @@ class PoolPlus extends Pool {
395395
}
396396

397397
_runOperations(operations, cb) {
398-
if (!operations.length) {
398+
if (operations.length === 0) {
399399
cb();
400400
return;
401401
}

lib/TableDefinition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class TableDefinition {
125125
const oldColumnDefinition = oldSchema.columns[oldColumnName];
126126
const position = lastColumnName ? ' AFTER ' + pool.escapeId(lastColumnName) : ' FIRST';
127127

128-
if (!oldColumnDefinition) {
128+
if (oldColumnDefinition === undefined) {
129129
operations.push(Operation.create(
130130
Operation.Types.ADD_COLUMN,
131131
'ADD COLUMN ' + pool.escapeId(columnName) + ' ' + newColumnDefinition.$toSQL() + position
@@ -545,7 +545,7 @@ function createNormalizedSchema(schema) {
545545
}
546546

547547
function getNormalizedForeignKeys(foreignKeys) {
548-
if (!foreignKeys) {
548+
if (foreignKeys === undefined) {
549549
return foreignKeys;
550550
}
551551

lib/sqlToSchema.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,15 @@ function generateColumnsSchema(createDefinitions) {
128128

129129
function columnsSQLToSchema(sql) {
130130
const schema = sql.replace(/`|\s/g, '');
131-
132131
return schema.indexOf(',') >= 0 ? schema.split(',') : schema;
133132
}
134133

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

138137
for (var i = 0; i < createDefinitions.length; i++) {
139-
var pkMatch = rgxPrimaryKey.exec(createDefinitions[i]);
140-
141-
if (pkMatch) {
138+
const pkMatch = rgxPrimaryKey.exec(createDefinitions[i]);
139+
if (pkMatch !== null) {
142140
return columnsSQLToSchema(pkMatch[1]);
143141
}
144142
}
@@ -163,9 +161,8 @@ function generateKeysSchema(createDefinitions, keyType) {
163161
}
164162

165163
for (var i = 0; i < createDefinitions.length; i++) {
166-
var keyMatch = rgxKey.exec(createDefinitions[i]);
167-
168-
if (keyMatch) {
164+
const keyMatch = rgxKey.exec(createDefinitions[i]);
165+
if (keyMatch !== null) {
169166
keys.push(columnsSQLToSchema(keyMatch[1]));
170167
}
171168
}
@@ -179,9 +176,8 @@ function getUnknownKeys(createDefinitions) {
179176
/^\s*(?:UNIQUE KEY `((?!unique_)\w+)`|KEY `((?!index_)\w+)`|SPATIAL KEY `((?!spatial_)\w+)`) \((.*?)\)/;
180177

181178
for (var i = 0; i < createDefinitions.length; i++) {
182-
var keyMatch = rgxKey.exec(createDefinitions[i]);
183-
184-
if (keyMatch) {
179+
const keyMatch = rgxKey.exec(createDefinitions[i]);
180+
if (keyMatch !== null) {
185181
keys.push({
186182
name: keyMatch[1] || keyMatch[2] || keyMatch[3],
187183
columns: columnsSQLToSchema(keyMatch[4]),
@@ -198,14 +194,12 @@ function generateForegnKeysSchema(createDefinitions) {
198194
/\s*CONSTRAINT `\w+` FOREIGN KEY \(`(.*?)`\) REFERENCES `(\w+)` \((.*?)\)(?: ON DELETE (RESTRICT|CASCADE|SET NULL|NO ACTION))?(?: ON UPDATE (RESTRICT|CASCADE|SET NULL|NO ACTION))?/;
199195

200196
for (var i = 0; i < createDefinitions.length; i++) {
201-
var keyMatch = rgxForeignKey.exec(createDefinitions[i]);
202-
203-
if (!keyMatch) {
197+
const keyMatch = rgxForeignKey.exec(createDefinitions[i]);
198+
if (keyMatch === null) {
204199
continue;
205200
}
206201

207202
const keyColumns = columnsSQLToSchema(keyMatch[1]);
208-
209203
foreignKeys[keyColumns] = {
210204
table: keyMatch[2],
211205
column: columnsSQLToSchema(keyMatch[3]),

lib/utils/cloneKeys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'use strict';
88

99
function cloneKeys(keys) {
10-
if (!keys) {
10+
if (keys === undefined || keys === null) {
1111
return null;
1212
}
1313

lib/utils/diffKeys.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
'use strict';
99

1010
function diffKeys(original, current) {
11-
if (!original) {
11+
if (original === undefined || original === null) {
1212
return {
13-
addedKeys: current ? current.slice() : [],
13+
addedKeys: current === undefined || current === null
14+
? []
15+
: current.slice(),
1416
removedKeys: [],
1517
};
1618
}
17-
if (!current) {
19+
if (current === undefined || current === null) {
1820
return {
1921
addedKeys: [],
2022
removedKeys: original.slice(),

0 commit comments

Comments
 (0)