From cf4d19b03e8f389b873b2f321009b384f577e5a3 Mon Sep 17 00:00:00 2001 From: Fahad Ibnay Heylaal Date: Fri, 4 Dec 2015 23:37:08 +0100 Subject: [PATCH] eslint fixes. --- .eslintrc | 139 +++++++++++++++++------------ src/Collection.js | 12 ++- src/Model.js | 2 +- src/Query.js | 10 +-- src/Schema.js | 4 +- src/adapters/Memory/Adapter.js | 14 ++- src/adapters/Memory/Query.js | 19 ++-- src/adapters/Sql/Expression.js | 3 +- src/adapters/Sql/Functions.js | 2 +- src/adapters/Sql/makeAdapter.js | 6 +- src/adapters/Sql/makeConnection.js | 2 +- src/adapters/Sql/makeQuery.js | 21 ++--- 12 files changed, 124 insertions(+), 110 deletions(-) diff --git a/.eslintrc b/.eslintrc index 14d3124..091655d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,166 +4,191 @@ "env": { "node": true }, + "ecmaFeatures": {}, "rules": { - "no-alert": 2, + "no-alert": 0, "no-array-constructor": 2, - "no-bitwise": 0, + "no-bitwise": 2, "no-caller": 2, "no-catch-shadow": 2, - "no-comma-dangle": 0, + "no-class-assign": 2, "no-cond-assign": 2, "no-console": 2, + "no-const-assign": 2, "no-constant-condition": 2, "no-continue": 0, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, - "no-div-regex": 0, + "no-div-regex": 2, + "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-dupe-args": 2, "no-duplicate-case": 2, - "no-else-return": 0, + "no-else-return": 2, "no-empty": 2, - "no-empty-class": 2, + "no-empty-character-class": 2, "no-empty-label": 2, - "no-eq-null": 0, + "no-eq-null": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, - "no-extra-bind": 2, + "no-extra-bind": 0, "no-extra-boolean-cast": 2, "no-extra-parens": 0, "no-extra-semi": 2, - "no-extra-strict": 2, "no-fallthrough": 2, - "no-floating-decimal": 0, + "no-floating-decimal": 2, "no-func-assign": 2, + "no-implicit-coercion": 0, "no-implied-eval": 2, "no-inline-comments": 0, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, + "no-invalid-this": 2, "no-irregular-whitespace": 2, - "no-iterator": 2, + "no-iterator": 0, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, - "no-lonely-if": 0, + "no-lonely-if": 2, "no-loop-func": 2, - "no-mixed-requires": [0, false], + "no-mixed-requires": [2, false], "no-mixed-spaces-and-tabs": [2, false], - "linebreak-style": [0, "unix"], + "linebreak-style": [2, "unix"], "no-multi-spaces": 2, "no-multi-str": 2, - "no-multiple-empty-lines": [0, {"max": 2}], + "no-multiple-empty-lines": [2, {"max": 1}], "no-native-reassign": 2, "no-negated-in-lhs": 2, - "no-nested-ternary": 0, + "no-nested-ternary": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, - "no-new-require": 0, + "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, - "no-param-reassign": 0, + "no-param-reassign": 2, "no-path-concat": 0, "no-plusplus": 0, "no-process-env": 0, - "no-process-exit": 2, + "no-process-exit": 0, "no-proto": 2, "no-redeclare": 2, "no-regex-spaces": 2, - "no-reserved-keys": 0, "no-restricted-modules": 0, + "no-restricted-syntax": 0, "no-return-assign": 2, "no-script-url": 2, - "no-self-compare": 0, + "no-self-compare": 2, "no-sequences": 2, - "no-shadow": 2, - "no-shadow-restricted-names": 2, - "no-space-before-semi": 0, - "no-spaced-func": 2, + "no-shadow": 0, + "no-shadow-restricted-names": 0, + "no-spaced-func": 0, "no-sparse-arrays": 2, "no-sync": 0, "no-ternary": 0, "no-trailing-spaces": 2, - "no-throw-literal": 0, + "no-this-before-super": 2, + "no-throw-literal": 2, "no-undef": 2, "no-undef-init": 2, - "no-undefined": 0, - "no-underscore-dangle": 2, - "no-unneeded-ternary": 0, + "no-undefined": 2, + "no-unexpected-multiline": 2, + "no-underscore-dangle": 0, + "no-unneeded-ternary": 2, "no-unreachable": 2, "no-unused-expressions": 2, "no-unused-vars": [2, {"vars": "all", "args": "after-used"}], "no-use-before-define": 2, - "no-void": 0, + "no-useless-call": 2, + "no-useless-concat": 2, + "no-void": 2, "no-var": 0, "no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }], "no-with": 2, - "no-wrap-func": 2, + "array-bracket-spacing": [2, "never"], + "arrow-parens": 0, + "arrow-spacing": 0, + "accessor-pairs": 0, "block-scoped-var": 0, + "block-spacing": 0, "brace-style": [0, "1tbs"], - "camelcase": 2, + "callback-return": 0, + "camelcase": 0, "comma-dangle": [2, "never"], - "comma-spacing": 2, + "comma-spacing": 0, "comma-style": 0, "complexity": [0, 11], - "consistent-return": 2, + "computed-property-spacing": [0, "never"], + "consistent-return": 0, "consistent-this": [0, "that"], + "constructor-super": 0, "curly": [2, "all"], - "default-case": 0, + "default-case": 2, + "dot-location": 0, "dot-notation": [2, { "allowKeywords": true }], - "eol-last": 2, - "eqeqeq": 2, + "eol-last": 0, + "eqeqeq": 0, "func-names": 0, "func-style": [0, "declaration"], - "generator-star": 0, "generator-star-spacing": 0, - "global-strict": [2, "never"], + "global-require": 0, "guard-for-in": 0, "handle-callback-err": 0, + "id-length": 0, "indent": 0, - "key-spacing": [2, { "beforeColon": false, "afterColon": true }], + "init-declarations": 0, + "jsx-quotes": [2, "prefer-double"], + "key-spacing": [0, { "beforeColon": false, "afterColon": true }], + "lines-around-comment": 0, "max-depth": [0, 4], "max-len": [0, 80, 4], "max-nested-callbacks": [0, 2], "max-params": [0, 3], "max-statements": [0, 10], - "new-cap": 2, - "new-parens": 2, + "new-cap": 0, + "new-parens": 0, "newline-after-var": 0, + "object-curly-spacing": [0, "never"], "object-shorthand": 0, - "one-var": 0, + "one-var": [0, "always"], "operator-assignment": [0, "always"], "operator-linebreak": 0, "padded-blocks": 0, + "prefer-arrow-callback": 0, + "prefer-const": 0, + "prefer-spread": 0, + "prefer-reflect": 0, + "prefer-template": 0, "quote-props": 0, - "quotes": [1, "single"], - "radix": 0, - "semi": 2, + "quotes": [2, "single"], + "radix": 2, + "id-match": 0, + "require-jsdoc": 0, + "require-yield": 0, + "semi": [2, "always"], "semi-spacing": [2, {"before": false, "after": true}], "sort-vars": 0, - "space-after-function-name": [0, "never"], - "space-after-keywords": [0, "always"], + "space-after-keywords": [2, "always"], + "space-before-keywords": [0, "always"], "space-before-blocks": [0, "always"], - "space-before-function-paren": [0, "always"], - "space-before-function-parentheses": [0, "always"], - "space-in-brackets": [0, "never"], + "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], "space-in-parens": [0, "never"], - "space-infix-ops": 2, - "space-return-throw-case": 2, - "space-unary-ops": [2, { "words": true, "nonwords": false }], - "spaced-line-comment": [0, "always"], - "strict": [2, "never"], + "space-infix-ops": 0, + "space-return-throw-case": 0, + "space-unary-ops": [0, { "words": true, "nonwords": false }], + "spaced-comment": 0, + "strict": 0, "use-isnan": 2, "valid-jsdoc": 0, "valid-typeof": 2, "vars-on-top": 0, "wrap-iife": 0, "wrap-regex": 0, - "yoda": [2, "never"] + "yoda": [0, "never"] } } diff --git a/src/Collection.js b/src/Collection.js index 0432519..7abe65c 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -529,7 +529,7 @@ export default class Collection { // * `callbacks`: Defaults to true, pass false to disable before/after callbacks. // validate(model, options = {}) { - let callbacks = (_.isUndefined(options.callbacks) || options.callbacks) ? true : false; + let callbacks = (_.isUndefined(options.callbacks) || options.callbacks); return new P((resolve, reject) => { return async.waterfall([ @@ -655,10 +655,8 @@ export default class Collection { // // Returns a promise with true if validated, otherwise error message // - validateField(model, field, value = null) { - if (!value) { - value = model.get(field); - } + validateField(model, field, givenValue = null) { + const value = !givenValue ? model.get(field) : givenValue; let fieldSchema = this.schema[field]; if (!_.isObject(fieldSchema) || !fieldSchema.validate) { @@ -748,7 +746,7 @@ export default class Collection { // * `callbacks`: Defaults to true, pass false to disable before/after callbacks. // save(model, options = {}) { - let callbacks = (_.isUndefined(options.callbacks) || options.callbacks) ? true : false; + let callbacks = (_.isUndefined(options.callbacks) || options.callbacks); return new P((resolve, reject) => { return async.waterfall([ @@ -868,7 +866,7 @@ export default class Collection { // * `callbacks`: Defaults to true, pass false to disable before/after callbacks. // delete(model, options = {}) { - let callbacks = (_.isUndefined(options.callbacks) || options.callbacks) ? true : false; + let callbacks = (_.isUndefined(options.callbacks) || options.callbacks); return new P((resolve, reject) => { return async.waterfall([ diff --git a/src/Model.js b/src/Model.js index 76cba02..7437273 100644 --- a/src/Model.js +++ b/src/Model.js @@ -160,7 +160,7 @@ export default class Model { // Is the current model new? As in saved in Database, or yet to be saved? // isNew() { - return this.getId() ? false : true; + return this.getId() ? false : true; // eslint-disable-line } // ### save(options = {}) diff --git a/src/Query.js b/src/Query.js index 5f90280..c5c371b 100644 --- a/src/Query.js +++ b/src/Query.js @@ -26,11 +26,11 @@ import Functions from './Functions'; // ``` // export default class Query { - constructor(options = {}) { - options = { + constructor(givenOptions = {}) { + const options = { expressionClass: Expression, functionsClass: Functions, - ...options + ...givenOptions }; this.adapter = null; @@ -63,11 +63,11 @@ export default class Query { return this; } - select(fields) { return this; } + select() { return this; } distinct() { return this; } - from(table, alias) { return this; } + from() { return this; } where() { return this; } diff --git a/src/Schema.js b/src/Schema.js index f7adcbe..b890083 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -9,11 +9,11 @@ export default class Schema { return this.adapter.getConnection(); } - dropTable(collection) { + dropTable(collection) { // eslint-disable-line return new P.resolve(true); } - createTable(collection) { + createTable(collection) { // eslint-disable-line return new P.resolve(true); } diff --git a/src/adapters/Memory/Adapter.js b/src/adapters/Memory/Adapter.js index dc4ccea..67ee244 100644 --- a/src/adapters/Memory/Adapter.js +++ b/src/adapters/Memory/Adapter.js @@ -1,15 +1,11 @@ /* eslint-disable new-cap */ - import _ from 'lodash'; -import f from '../../'; -import async from 'async'; + +import {Adapter} from '../../'; import Query from './Query'; import Schema from './Schema'; -let P = f.Promise; -let Adapter = f.Adapter; - // ## Usage // // ### Node.js @@ -61,11 +57,11 @@ let Adapter = f.Adapter; // ``` // export default class MemoryAdapter extends Adapter { - constructor(options) { - options = { + constructor(givenOptions = {}) { + const options = { queryClass: Query, schemaClass: Schema, - ...options + ...givenOptions }; super(options); diff --git a/src/adapters/Memory/Query.js b/src/adapters/Memory/Query.js index 89abb03..6c20bc1 100644 --- a/src/adapters/Memory/Query.js +++ b/src/adapters/Memory/Query.js @@ -12,7 +12,7 @@ export default class MemoryQuery extends Query { this.builder = _(this.data); } - from(table, alias) { + from(table) { this._from = table; return this; @@ -32,10 +32,8 @@ export default class MemoryQuery extends Query { return this; } - groupBy(columns) { - if (_.isString(columns)) { - columns = [columns]; - } + groupBy(givenColumns) { + const columns = _.isString(givenColumns) ? [givenColumns] : givenColumns; this._groupBy = columns; @@ -120,7 +118,6 @@ export default class MemoryQuery extends Query { _runDelete() { const table = this._table; - const ids = []; let tableRows = this.adapter.getData(table); if (typeof tableRows === 'undefined') { @@ -223,18 +220,20 @@ export default class MemoryQuery extends Query { }); const results = []; - _.each(grouped, (rows, groupedK) => { + _.each(grouped, (rows) => { results.push(rows[0]); }); return results; }) - .thru((data) => { + .thru((givenData) => { // offset and limit + let data; + if (this._offset && this._limit) { - data = data.slice(this._offset, this._limit + 1); + data = givenData.slice(this._offset, this._limit + 1); } else if (this._limit) { - data = data.slice(0, this._limit); + data = givenData.slice(0, this._limit); } return data; diff --git a/src/adapters/Sql/Expression.js b/src/adapters/Sql/Expression.js index 6f12a33..92619d7 100644 --- a/src/adapters/Sql/Expression.js +++ b/src/adapters/Sql/Expression.js @@ -1,5 +1,4 @@ -import _ from 'lodash'; - +/* eslint-disable no-use-before-define, no-invalid-this */ import Expression from '../../Expression'; function applyConditions(context, method, ...args) { diff --git a/src/adapters/Sql/Functions.js b/src/adapters/Sql/Functions.js index 6aac9d4..a4e3f0b 100644 --- a/src/adapters/Sql/Functions.js +++ b/src/adapters/Sql/Functions.js @@ -44,7 +44,7 @@ export default class SqlFunctions extends Functions { toString() { let str = this.column ? this.column : ''; - this.funcs.forEach((funcName, i) => { + this.funcs.forEach((funcName) => { str = `${funcName}(${str})`; }); diff --git a/src/adapters/Sql/makeAdapter.js b/src/adapters/Sql/makeAdapter.js index b58db64..76d90c7 100644 --- a/src/adapters/Sql/makeAdapter.js +++ b/src/adapters/Sql/makeAdapter.js @@ -8,11 +8,11 @@ let P = f.Promise; export default function makeAdapter(makeConnection) { class SqlAdapter extends Adapter { - constructor(options) { - options = { + constructor(givenOptions) { + const options = { queryClass: Query, schemaClass: Schema, - ...options + ...givenOptions }; super(options); diff --git a/src/adapters/Sql/makeConnection.js b/src/adapters/Sql/makeConnection.js index 4251957..8aaf1af 100644 --- a/src/adapters/Sql/makeConnection.js +++ b/src/adapters/Sql/makeConnection.js @@ -1,4 +1,4 @@ -import _ from 'lodash'; +/* eslint-disable no-undefined */ import knex from 'knex'; export default function makeConnection(options = {}) { diff --git a/src/adapters/Sql/makeQuery.js b/src/adapters/Sql/makeQuery.js index 1f0e399..3e10bb4 100644 --- a/src/adapters/Sql/makeQuery.js +++ b/src/adapters/Sql/makeQuery.js @@ -1,3 +1,4 @@ +/* eslint-disable no-invalid-this */ import _ from 'lodash'; import P from '../../Promise'; @@ -24,11 +25,11 @@ function makeWhere(query, method, ...args) { export default function makeQuery(knex) { class SqlQuery extends Query { - constructor(options = {}) { - options = { + constructor(givenOptions = {}) { + const options = { expressionClass: SqlExpression, functionsClass: SqlFunctions, - ...options + ...givenOptions }; super(options); @@ -117,10 +118,8 @@ export default function makeQuery(knex) { return this; } - distinct(fields = []) { - if (_.isString(fields)) { - fields = [fields]; - } + distinct(givenFields = []) { + const fields = _.isString(givenFields) ? [givenFields] : givenFields; if (fields.length === 0) { return this; @@ -157,10 +156,8 @@ export default function makeQuery(knex) { return this; } - groupBy(columns) { - if (_.isString(columns)) { - columns = [columns]; - } + groupBy(givenColumns) { + const columns = _.isString(givenColumns) ? [givenColumns] : givenColumns; this.builder.groupBy(columns); @@ -233,7 +230,7 @@ export default function makeQuery(knex) { } debug() { - console.log('query:', this.builder.toString()); + console.log('query:', this.builder.toString()); // eslint-disable-line return this; }