Skip to content

Commit dc15b89

Browse files
committed
chore: Update ESLint configuration and refactor code to pass linting
1 parent bd513d2 commit dc15b89

29 files changed

+295
-421
lines changed

.eslintrc.json

Lines changed: 16 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,20 @@
11
{
22
"root": true,
3-
"env": {
4-
"es6": true,
5-
"node": true
6-
},
3+
"extends": "@nwoltman/eslint-config",
74
"rules": {
8-
"array-bracket-spacing": 2,
9-
"array-callback-return": 2,
10-
"arrow-parens": [2, "as-needed"],
11-
"arrow-spacing": 2,
12-
"block-scoped-var": 2,
13-
"block-spacing": 2,
14-
"brace-style": 2,
15-
"camelcase": 2,
16-
"comma-dangle": [2, "always-multiline"],
17-
"comma-spacing": 2,
18-
"comma-style": 2,
19-
"computed-property-spacing": 2,
20-
"consistent-return": 2,
21-
"constructor-super": 2,
22-
"curly": [2, "multi-line", "consistent"],
23-
"dot-location": [2, "property"],
24-
"dot-notation": 2,
25-
"eol-last": 2,
26-
"eqeqeq": [2, "always", {"null": "ignore"}],
27-
"func-call-spacing": 2,
28-
"func-style": [2, "declaration"],
29-
"generator-star-spacing": [2, "after"],
30-
"global-require": 2,
31-
"handle-callback-err": [2, "^(?:err(?:or)?)$"],
32-
"id-blacklist": [2, "self"],
33-
"indent": [2, 2, {"SwitchCase": 1}],
34-
"key-spacing": 2,
35-
"keyword-spacing": 2,
36-
"lines-around-directive": 2,
37-
"max-len": [2, 120, {"ignoreUrls": true, "ignoreRegExpLiterals": true}],
38-
"max-nested-callbacks": [2, 3],
39-
"new-cap": 2,
40-
"new-parens": 2,
41-
"no-array-constructor": 2,
42-
"no-case-declarations": 2,
43-
"no-class-assign": 2,
44-
"no-confusing-arrow": 2,
45-
"no-const-assign": 2,
46-
"no-constant-condition": 2,
47-
"no-control-regex": 2,
48-
"no-delete-var": 2,
49-
"no-dupe-class-members": 2,
50-
"no-dupe-keys": 2,
51-
"no-duplicate-case": 2,
52-
"no-else-return": 2,
53-
"no-empty": 2,
54-
"no-empty-character-class": 2,
55-
"no-empty-function": 2,
56-
"no-empty-pattern": 2,
57-
"no-eval": 2,
58-
"no-ex-assign": 2,
59-
"no-extend-native": 2,
60-
"no-extra-bind": 2,
61-
"no-extra-boolean-cast": 2,
62-
"no-extra-label": 2,
63-
"no-extra-parens": 2,
64-
"no-extra-semi": 2,
65-
"no-fallthrough": 2,
66-
"no-floating-decimal": 2,
67-
"no-func-assign": 2,
68-
"no-invalid-regexp": 2,
69-
"no-irregular-whitespace": [2, {"skipStrings": false}],
70-
"no-label-var": 2,
71-
"no-labels": [2, {"allowLoop": true}],
72-
"no-lone-blocks": 2,
73-
"no-lonely-if": 2,
74-
"no-loop-func": 2,
75-
"no-mixed-spaces-and-tabs": 2,
76-
"no-multi-spaces": 2,
77-
"no-multi-str": 2,
78-
"no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 1}],
79-
"no-negated-condition": 1,
80-
"no-nested-ternary": 2,
81-
"no-new": 2,
82-
"no-new-object": 2,
83-
"no-new-require": 2,
84-
"no-new-symbol": 2,
85-
"no-new-wrappers": 2,
86-
"no-octal-escape": 2,
87-
"no-path-concat": 2,
88-
"no-process-exit": 2,
89-
"no-proto": 2,
90-
"no-redeclare": [2, {"builtinGlobals": true}],
91-
"no-regex-spaces": 2,
92-
"no-return-assign": [2, "always"],
93-
"no-script-url": 2,
94-
"no-self-assign": 2,
95-
"no-self-compare": 2,
96-
"no-sequences": 2,
97-
"no-shadow": [2, {"allow": ["err", "result"], "builtinGlobals": true}],
98-
"no-shadow-restricted-names": 2,
99-
"no-sparse-arrays": 2,
100-
"no-tabs": 2,
101-
"no-template-curly-in-string": 2,
102-
"no-this-before-super": 2,
103-
"no-throw-literal": 2,
104-
"no-trailing-spaces": 2,
105-
"no-undef": 2,
106-
"no-undef-init": 2,
107-
"no-unexpected-multiline": 2,
108-
"no-unmodified-loop-condition": 2,
109-
"no-unneeded-ternary": [2, {"defaultAssignment": true}],
110-
"no-unreachable": 2,
111-
"no-unsafe-finally": 2,
112-
"no-unsafe-negation": 2,
113-
"no-unused-expressions": [2, {"allowShortCircuit": true}],
114-
"no-unused-labels": 2,
115-
"no-unused-vars": 2,
116-
"no-use-before-define": [2, "nofunc"],
117-
"no-useless-call": 2,
118-
"no-useless-computed-key": 2,
119-
"no-useless-concat": 2,
120-
"no-useless-escape": 2,
121-
"no-useless-rename": 2,
122-
"no-void": 2,
123-
"no-warning-comments": 1,
124-
"no-whitespace-before-property": 2,
125-
"no-with": 2,
126-
"object-curly-spacing": 2,
127-
"object-property-newline": [2, {"allowAllPropertiesOnSameLine": true}],
128-
"object-shorthand": 2,
129-
"one-var": [2, "never"],
130-
"one-var-declaration-per-line": 2,
131-
"operator-assignment": [1, "always"],
132-
"operator-linebreak": 2,
133-
"prefer-arrow-callback": [2, {"allowNamedFunctions": true}],
134-
"prefer-const": 2,
135-
"quote-props": [2, "as-needed"],
136-
"quotes": [2, "single", {"avoidEscape": true}],
137-
"rest-spread-spacing": 2,
138-
"require-yield": 2,
139-
"semi": 2,
140-
"semi-spacing": 2,
141-
"space-before-blocks": 2,
142-
"space-before-function-paren": [2, "never"],
143-
"space-in-parens": 2,
144-
"space-infix-ops": 2,
145-
"space-unary-ops": 2,
146-
"spaced-comment": 2,
147-
"strict": [2, "global"],
148-
"template-curly-spacing": 2,
149-
"use-isnan": 2,
150-
"valid-typeof": 2,
151-
"wrap-iife": [2, "inside"],
152-
"yield-star-spacing": [2, "before"],
153-
"yoda": [2, "never", {"exceptRange": true}]
154-
}
5+
"id-blacklist": 0,
6+
"max-len": [2, {
7+
"code": 120,
8+
"ignoreUrls": true,
9+
"ignoreRegExpLiterals": true
10+
}]
11+
},
12+
"overrides": [
13+
{
14+
"files": ["tasks/**"],
15+
"rules": {
16+
"no-sync": 0
17+
}
18+
}
19+
]
15520
}

Gruntfile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/* eslint-disable camelcase, global-require */
2-
31
'use strict';
42

3+
/* eslint-disable camelcase, no-sync */
4+
5+
const fs = require('fs');
6+
57
module.exports = function(grunt) {
68
require('jit-grunt')(grunt, {
79
jsdoc2md: 'grunt-jsdoc-to-markdown',
@@ -78,7 +80,7 @@ module.exports = function(grunt) {
7880
],
7981
separators: true,
8082
'sort-by': ['order'],
81-
template: require('fs').readFileSync('jsdoc2md/README.hbs', 'utf8'),
83+
template: fs.readFileSync('jsdoc2md/README.hbs', 'utf8'),
8284
},
8385
src: ['lib/MySQLPlus.js', 'lib/PoolPlus.js', 'lib/Connection.js', 'lib/MySQLTable.js'],
8486
dest: 'README.md',

lib/ColumnDefinitions/ColumnDefinition.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ function escapeDefault(value) {
1616
class ColumnDefinition {
1717
constructor(type, m, d) {
1818
this._baseType = type;
19-
if (m == null) {
19+
if (m === null || m === undefined) {
2020
this.$hasLength = false;
2121
this._type = type;
2222
} else {
2323
this.$hasLength = true;
24-
this._type = type + '(' + mysql.escape(m) + (d == null ? '' : ',' + mysql.escape(d)) + ')';
24+
this._type =
25+
type +
26+
'(' +
27+
mysql.escape(m) +
28+
(d === null || d === undefined ? '' : ',' + mysql.escape(d)) +
29+
')';
2530
}
2631
this.$primaryKey = false;
2732
this.$unique = false;
@@ -108,7 +113,7 @@ class ColumnDefinition {
108113
return sql;
109114
}
110115

111-
__getExtendedType() {
116+
__getExtendedType() { // eslint-disable-line class-methods-use-this
112117
return '';
113118
}
114119
}

lib/ColumnDefinitions/index.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
22
* ColumnDefinitions
3+
*
4+
* Reference: http://dev.mysql.com/doc/refman/5.7/en/data-type-overview.html
35
*/
4-
5-
// Reference: http://dev.mysql.com/doc/refman/5.7/en/data-type-overview.html
6-
76
'use strict';
87

98
const ColumnDefinition = require('./ColumnDefinition');
@@ -78,7 +77,7 @@ const ColumnDefinitions = {
7877
return new TextColumnDefinition('char', m);
7978
},
8079
varchar(m) {
81-
if (m == null) {
80+
if (m === null || m === undefined) {
8281
throw new Error('You must specify the `m` argument for varchar');
8382
}
8483
return new TextColumnDefinition('varchar', m);
@@ -99,7 +98,7 @@ const ColumnDefinitions = {
9998
return new ColumnDefinition('binary', m);
10099
},
101100
varbinary(m) {
102-
if (m == null) {
101+
if (m === null || m === undefined) {
103102
throw new Error('You must specify the `m` argument for varbinary');
104103
}
105104
return new ColumnDefinition('varbinary', m);
@@ -116,26 +115,16 @@ const ColumnDefinitions = {
116115
longblob() {
117116
return new ColumnDefinition('longblob');
118117
},
119-
enum() {
120-
const argsLength = arguments.length;
121-
if (argsLength === 0) {
118+
enum(...values) {
119+
if (values.length === 0) {
122120
throw new Error('You must provide at least one possible enum value');
123121
}
124-
const values = new Array(argsLength);
125-
for (var i = 0; i < argsLength; i++) {
126-
values[i] = arguments[i];
127-
}
128122
return new TextColumnDefinition('enum', values);
129123
},
130-
set() {
131-
const argsLength = arguments.length;
132-
if (argsLength === 0) {
124+
set(...values) {
125+
if (values.length === 0) {
133126
throw new Error('You must provide at least one possible set value');
134127
}
135-
const values = new Array(argsLength);
136-
for (var i = 0; i < argsLength; i++) {
137-
values[i] = arguments[i];
138-
}
139128
return new TextColumnDefinition('set', values);
140129
},
141130
json() {

lib/PoolPlus.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* PoolPlus - Extends MySQL's Pool class
33
*/
4-
54
'use strict';
65

76
const ColumnDefinitions = require('./ColumnDefinitions');
@@ -85,7 +84,7 @@ class PoolPlus extends Pool {
8584
* // INSERT INTO `place`
8685
* // SET `placeId` = 'ChIJK2f', `coordinates` = POINT(-80.5204, 43.4642);
8786
*/
88-
raw(sql) {
87+
raw(sql) { // eslint-disable-line class-methods-use-this
8988
return SqlString.raw(sql);
9089
}
9190

@@ -173,7 +172,7 @@ class PoolPlus extends Pool {
173172
sync(cb) { // eslint-disable-line consistent-return
174173
if (!cb) {
175174
return new Promise((resolve, reject) => {
176-
this.sync(err => {
175+
this.sync((err) => {
177176
if (err) {
178177
reject(err);
179178
} else {
@@ -195,7 +194,7 @@ class PoolPlus extends Pool {
195194
if (err) {
196195
error = error || err;
197196
} else if (operations.length) {
198-
allOperations.push.apply(allOperations, operations);
197+
allOperations.push(...operations);
199198
}
200199

201200
if (--tablesRemaining > 0) {
@@ -310,7 +309,7 @@ class PoolPlus extends Pool {
310309
}
311310

312311
function commit(result) {
313-
connection.commit(err => {
312+
connection.commit((err) => {
314313
if (err) {
315314
rollback(err);
316315
return;
@@ -328,7 +327,7 @@ class PoolPlus extends Pool {
328327
}
329328
}
330329

331-
connection.beginTransaction(err => {
330+
connection.beginTransaction((err) => {
332331
if (err) {
333332
reject(err);
334333
return;
@@ -427,7 +426,7 @@ class PoolPlus extends Pool {
427426

428427
if (this._debug) {
429428
for (let i = 0; i < opsLeft; i++) {
430-
connection.query(operations[i].sql, err => { // eslint-disable-line no-loop-func
429+
connection.query(operations[i].sql, (err) => { // eslint-disable-line no-loop-func
431430
if (err && !errored) {
432431
debugSyncErrorOperation(operations[i]);
433432
}
@@ -456,11 +455,12 @@ function debugOperations(operations, debuggingError) {
456455
? '\n====== mysql-plus sync errored on operation: ======\n\n'
457456
: '\n============= mysql-plus operations: ==============\n\n';
458457

459-
console.log(
458+
console.log( // eslint-disable-line no-console
460459
header +
461-
operations.map(operation =>
462-
'type: ' + opTypeNames.find(typeName => Operation.Types[typeName] === operation.type) +
463-
`\n${operation.sql};`
460+
operations.map(
461+
operation =>
462+
'type: ' + opTypeNames.find(typeName => Operation.Types[typeName] === operation.type) +
463+
`\n${operation.sql};`
464464
).join('\n\n') +
465465
'\n\n===================================================\n'
466466
);

0 commit comments

Comments
 (0)