diff --git a/.eslintrc b/.eslintrc index 6268c22..4f08dd2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,65 +1 @@ -{ - "parserOptions": { - "ecmaVersion": 6 - }, - "env": { - "node": true, - "browser": false, - "es6": true - }, - "ecmaFeatures": { - "arrowFunctions": true, - "blockBindings": true, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "destructuring": true, - "templateStrings": true - }, - "rules": { - "no-var": 2, - "prefer-const": 2, - "no-const-assign": 2, - "no-mixed-requires": 0, - "curly": 0, - "camelcase": 2, - "no-process-exit": 0, - "eqeqeq": [2, "smart"], - "no-shadow": 0, - "no-underscore-dangle": 0, - "no-use-before-define": 0, - "guard-for-in": 2, - "no-else-return": 2, - "no-floating-decimal": 2, - "no-param-reassign": 0, - "no-self-compare": 2, - "no-undef": 2, - "no-unused-vars": 2, - "no-undefined": 0, - "no-console": 0, - "semi": [2, "always"], - "no-extra-semi": 2, - "brace-style": [2, "1tbs", { "allowSingleLine": true }], - "indent": [2, 4, { "SwitchCase": 1 }], - "quotes": [2, "single"], - "space-before-function-paren": [2, { - "anonymous": "never", - "named": "never" - }], - "no-multiple-empty-lines": [2, { - "max": 2 - }], - "max-nested-callbacks": [2, 4], - "no-lonely-if": 2, - "space-in-parens": [2, "never"], - "no-empty": 0 - }, - "globals": { - "it": true, - "before": true, - "after": true, - "beforeEach": true, - "afterEach": true, - "context": true, - "describe": true - } -} +{ "extends": "1602" } diff --git a/lib/adapter.js b/lib/adapter.js index a667081..05ac584 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -18,7 +18,7 @@ module.exports = function createMySQLAdapter(client, settings) { name: 'mysql', disconnect: cb => client.end(cb), closeConnection: () => { - return new Promise((resolve) => { + return new Promise(resolve => { client.end(function() { resolve(); }); diff --git a/lib/client-wrapper.js b/lib/client-wrapper.js index e0e0cc1..b8f9992 100644 --- a/lib/client-wrapper.js +++ b/lib/client-wrapper.js @@ -30,7 +30,7 @@ module.exports = function(client) { if (method !== 'run') { return resolve(result); - } + } const lastID = result.insertId; const changes = result.affectedRows; diff --git a/lib/connection.js b/lib/connection.js index 656e9df..2fdd859 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -15,7 +15,7 @@ function getConnection(settings) { if (settings.collation) { // Charset should be first 'chunk' of collation. settings.charset = settings.collation.substr(0, - settings.collation.indexOf('_')); + settings.collation.indexOf('_')); } else { settings.collation = 'utf8mb4_general_ci'; settings.charset = 'utf8mb4'; diff --git a/lib/enum-factory.js b/lib/enum-factory.js index 8d49ec5..e9609a7 100644 --- a/lib/enum-factory.js +++ b/lib/enum-factory.js @@ -1,11 +1,11 @@ -var EnumFactory = function() { - if(arguments.length > 0){ - var Enum = function Enum(arg){ - if(typeof arg === 'number' && arg % 1 == 0) { +const EnumFactory = function() { + if (arguments.length > 0) { + const Enum = function Enum(arg) { + if (typeof arg === 'number' && arg % 1 == 0) { return Enum._values[arg]; - } else if(Enum[arg]){ - return Enum[arg] - } else if (Enum._values.indexOf(arg) !== -1 ) { + } else if (Enum[arg]) { + return Enum[arg]; + } else if (Enum._values.indexOf(arg) !== -1) { return arg; } else if (arg === null) { return null; @@ -13,28 +13,28 @@ var EnumFactory = function() { return ''; } }; - var dxList = []; + const dxList = []; dxList.push(''); // Want empty value to be at index 0 to match MySQL Enum values and MySQL non-strict behavior. - for(var arg in arguments){ + for (let arg in arguments) { arg = String(arguments[arg]); - Object.defineProperty(Enum, arg.toUpperCase(), {configurable: false, enumerable: true, value: arg, writable: false}); + Object.defineProperty(Enum, arg.toUpperCase(), { configurable: false, enumerable: true, value: arg, writable: false }); dxList.push(arg); } - Object.defineProperty(Enum, '_values', {configurable: false, enumerable: false, value: dxList, writable: false}); - Object.defineProperty(Enum, '_members', {configurable: false, enumerable: false, value: dxList.slice(1), writable: false}); - Object.defineProperty(Enum, '_string', {configurable: false, enumerable: false, value: stringified(Enum), writable: false}); + Object.defineProperty(Enum, '_values', { configurable: false, enumerable: false, value: dxList, writable: false }); + Object.defineProperty(Enum, '_members', { configurable: false, enumerable: false, value: dxList.slice(1), writable: false }); + Object.defineProperty(Enum, '_string', { configurable: false, enumerable: false, value: stringified(Enum), writable: false }); Object.freeze(Enum); return Enum; } else { - throw "No arguments - could not create Enum."; + throw 'No arguments - could not create Enum.'; } }; function stringified(anEnum) { - var s = []; - for(var i in anEnum._values){ - if(anEnum._values[i] != ''){ - s.push("'" + anEnum._values[i] + "'"); + const s = []; + for (const i in anEnum._values) { + if (anEnum._values[i] != '') { + s.push('\'' + anEnum._values[i] + '\''); } } return s.join(','); @@ -43,8 +43,3 @@ function stringified(anEnum) { exports.EnumFactory = EnumFactory; - - - - - diff --git a/lib/information-schema.js b/lib/information-schema.js index 3d04abd..9253af5 100644 --- a/lib/information-schema.js +++ b/lib/information-schema.js @@ -127,9 +127,9 @@ module.exports = function() { let sql; const uuidVersion = getSetting(model, 'uuid'); if (uuidVersion === 'v4' || uuidVersion === 'v1') { - sql = ['`id` CHAR(36) NOT NULL PRIMARY KEY']; + sql = [ '`id` CHAR(36) NOT NULL PRIMARY KEY' ]; } else { - sql = ['`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY']; + sql = [ '`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY' ]; } Object.keys(models[model].properties).forEach(function(prop) { @@ -142,7 +142,7 @@ module.exports = function() { const p = models[model].properties[prop]; const i = p.index; if (i && !(p.type instanceof Array)) { - sql.push(formatIndexDefinition(prop, i.kind, i.type, [prop])); + sql.push(formatIndexDefinition(prop, i.kind, i.type, [ prop ])); } }); @@ -169,7 +169,7 @@ module.exports = function() { function propertySettingsSQL(model, prop) { const p = models[model].properties[prop]; const line = dataType(p) + ' ' + - (p.allowNull === false || p['null'] === false ? 'NOT NULL': 'NULL'); + (p.allowNull === false || p['null'] === false ? 'NOT NULL' : 'NULL'); return line; } diff --git a/lib/lookup-by-query.js b/lib/lookup-by-query.js index 7c7c955..35308e2 100644 --- a/lib/lookup-by-query.js +++ b/lib/lookup-by-query.js @@ -71,7 +71,7 @@ module.exports = function(informationSchema, db) { }); function buildOrderBy(order) { - if (typeof order === 'string') order = [order]; + if (typeof order === 'string') order = [ order ]; return 'ORDER BY ' + order.map(function(o) { const t = o.split(/\s+/); if (t.length === 1) { @@ -82,7 +82,7 @@ module.exports = function(informationSchema, db) { } function buildGroupBy(group) { - if (typeof group === 'string') group = [group]; + if (typeof group === 'string') group = [ group ]; return 'GROUP BY ' + group.map(function(o) { const t = o.split(/\s+/); if (t.length === 1) return '`' + o + '`'; diff --git a/lib/query-builder.js b/lib/query-builder.js index a501f5c..3d762da 100644 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -22,7 +22,7 @@ module.exports = function(informationSchema) { // allow both { attributes: 'id'} and { attributes: [ 'name', 'email' ] } if (!Array.isArray(attributes)) { - attributes = [attributes]; + attributes = [ attributes ]; } [].splice.apply(queryParams, [ queryParams.length, 0 ].concat( diff --git a/lib/schema-operations.js b/lib/schema-operations.js index f1cf784..63e399d 100644 --- a/lib/schema-operations.js +++ b/lib/schema-operations.js @@ -42,7 +42,7 @@ module.exports = function(informationSchema, db, settings) { ]) .catch(err => { if (err.code === 'ER_NO_SUCH_TABLE') { - return [[], [], [], true]; + return [[], [], [], true ]; } throw err; }) @@ -144,7 +144,7 @@ module.exports = function(informationSchema, db, settings) { const indexNames = m.settings.indexes ? Object.keys(m.settings.indexes).filter(name => { return !!m.settings.indexes[name]; - }): []; + }) : []; const sql = []; const ai = {}; @@ -252,7 +252,7 @@ module.exports = function(informationSchema, db, settings) { indexName, i.kind, i.type, - i.keys + i.keys ); })); diff --git a/package.json b/package.json index b6c8b87..d5af61e 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "devDependencies": { "coffee-script": "latest", "eslint": "^3.1.0", + "eslint-config-1602": "^1.0.0", "expect": "^1.20.2", "istanbul": "^0.4.4", "mocha": "^2.4.3",