Skip to content

Commit

Permalink
Update coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Jul 27, 2016
1 parent a22b146 commit 2e0236a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 101 deletions.
66 changes: 1 addition & 65 deletions .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" }
2 changes: 1 addition & 1 deletion lib/adapter.js
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/client-wrapper.js
Expand Up @@ -30,7 +30,7 @@ module.exports = function(client) {

if (method !== 'run') {
return resolve(result);
}
}

const lastID = result.insertId;
const changes = result.affectedRows;
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Expand Up @@ -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';
Expand Down
41 changes: 18 additions & 23 deletions lib/enum-factory.js
@@ -1,40 +1,40 @@
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;
} else {
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(',');
Expand All @@ -43,8 +43,3 @@ function stringified(anEnum) {
exports.EnumFactory = EnumFactory;







8 changes: 4 additions & 4 deletions lib/information-schema.js
Expand Up @@ -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) {
Expand All @@ -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 ]));
}
});

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/lookup-by-query.js
Expand Up @@ -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) {
Expand All @@ -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 + '`';
Expand Down
2 changes: 1 addition & 1 deletion lib/query-builder.js
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions lib/schema-operations.js
Expand Up @@ -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;
})
Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -252,7 +252,7 @@ module.exports = function(informationSchema, db, settings) {
indexName,
i.kind,
i.type,
i.keys
i.keys
);
}));

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 2e0236a

Please sign in to comment.