From e9f68a3bc9465d9ccaba083041fae962a505181f Mon Sep 17 00:00:00 2001 From: soupette Date: Fri, 4 May 2018 17:29:44 +0200 Subject: [PATCH] Lint in strapi-bookshelf --- packages/strapi-admin/admin/src/app.js | 2 +- packages/strapi-bookshelf/lib/index.js | 53 ++++++++++--------- .../lib/utils/connectivity.js | 8 +-- .../strapi-bookshelf/lib/utils/graphql.js | 2 +- packages/strapi-bookshelf/lib/utils/index.js | 2 +- scripts/lint.js | 2 +- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/packages/strapi-admin/admin/src/app.js b/packages/strapi-admin/admin/src/app.js index e7731ac01b..a7f4cff8d0 100755 --- a/packages/strapi-admin/admin/src/app.js +++ b/packages/strapi-admin/admin/src/app.js @@ -8,7 +8,7 @@ /* eslint-disable */ import './public-path'; import 'babel-polyfill'; - +/* eslint-disable no-console */ // Import all the third party stuff import { Provider } from 'react-redux'; import React from 'react'; diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index d2a6e5a8f9..7706431cf9 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -12,12 +12,12 @@ const _ = require('lodash'); const bookshelf = require('bookshelf'); const pluralize = require('pluralize'); -// Local helpers. -const utils = require('./utils/'); - // Strapi helpers for models. const utilsModels = require('strapi-utils').models; +// Local helpers. +const utils = require('./utils/'); + const PIVOT_PREFIX = '_pivot_'; const GLOBALS = {}; @@ -25,6 +25,9 @@ const GLOBALS = {}; * Bookshelf hook */ +/* eslint-disable no-unused-vars */ +/* eslint-disable prefer-template */ +/* eslint-disable no-case-declarations */ module.exports = function(strapi) { const hook = { /** @@ -86,18 +89,18 @@ module.exports = function(strapi) { // Register the final model for Bookshelf. const loadedModel = _.assign({ - tableName: definition.collectionName, - hasTimestamps: _.get(definition, 'options.timestamps') === true, - idAttribute: _.get(definition, 'options.idAttribute', 'id'), - associations: [], - defaults: Object.keys(definition.attributes).reduce((acc, current) => { - if (definition.attributes[current].type && definition.attributes[current].default) { - acc[current] = definition.attributes[current].default; - } + tableName: definition.collectionName, + hasTimestamps: _.get(definition, 'options.timestamps') === true, + idAttribute: _.get(definition, 'options.idAttribute', 'id'), + associations: [], + defaults: Object.keys(definition.attributes).reduce((acc, current) => { + if (definition.attributes[current].type && definition.attributes[current].default) { + acc[current] = definition.attributes[current].default; + } - return acc; - }, {}) - }, definition.options); + return acc; + }, {}) + }, definition.options); if (_.isString(_.get(connection, 'options.pivot_prefix'))) { loadedModel.toJSON = function(options = {}) { @@ -201,7 +204,7 @@ module.exports = function(strapi) { }); return attrs; - } + }; // Initialize lifecycle callbacks. loadedModel.initialize = function() { @@ -497,7 +500,7 @@ module.exports = function(strapi) { .query(qb => { qb.where(_.get(model, `attributes.${details.via}.filter`, 'field'), name); }); - } + }; break; } case 'morphMany': { @@ -513,7 +516,7 @@ module.exports = function(strapi) { .query(qb => { qb.where(_.get(collection, `attributes.${details.via}.filter`, 'field'), name); }); - } + }; break; } case 'belongsToMorph': @@ -605,7 +608,7 @@ module.exports = function(strapi) { cb(); }, - getQueryParams: (value, type, key) => { + getQueryParams: (value, type, key) => { const result = {}; switch (type) { @@ -821,7 +824,7 @@ module.exports = function(strapi) { strapi.plugins[obj.source].models[obj.ref]: strapi.models[obj.ref]; - virtualFields.push(this.addRelationMorph(details.model || details.collection, { + virtualFields.push(this.addRelationMorph(details.model || details.collection, { id: response[this.primaryKey], alias: association.alias, ref: model.collectionName, @@ -840,7 +843,7 @@ module.exports = function(strapi) { } return value; - }) + }); } if (association.type === 'model') { @@ -987,11 +990,11 @@ module.exports = function(strapi) { } return await Model.morph.forge({ - [`${Model.collectionName}_id`]: params.id, - [`${params.alias}_id`]: params.refId, - [`${params.alias}_type`]: params.ref, - field: params.field - }) + [`${Model.collectionName}_id`]: params.id, + [`${params.alias}_id`]: params.refId, + [`${params.alias}_type`]: params.ref, + field: params.field + }) .save(); }, diff --git a/packages/strapi-bookshelf/lib/utils/connectivity.js b/packages/strapi-bookshelf/lib/utils/connectivity.js index 2924d88893..2b3bac008f 100644 --- a/packages/strapi-bookshelf/lib/utils/connectivity.js +++ b/packages/strapi-bookshelf/lib/utils/connectivity.js @@ -24,8 +24,8 @@ module.exports = (scope, success, error) => { success(); }) - .catch(() => { - logger.warn('Database connection has failed! Make sure your database is running.'); - error(); - }); + .catch(() => { + logger.warn('Database connection has failed! Make sure your database is running.'); + error(); + }); }; diff --git a/packages/strapi-bookshelf/lib/utils/graphql.js b/packages/strapi-bookshelf/lib/utils/graphql.js index f4131a0184..30def64e5b 100755 --- a/packages/strapi-bookshelf/lib/utils/graphql.js +++ b/packages/strapi-bookshelf/lib/utils/graphql.js @@ -8,7 +8,7 @@ const _ = require('lodash'); // Strapi helper for GraphQL. -const helpers = require('strapi/lib/configuration/hooks/graphql/helpers/'); +const helpers = require('strapi/lib/configuration/hooks/graphql/helpers/'); // eslint-disable-line import/no-unresolved const utils = require('./'); /** diff --git a/packages/strapi-bookshelf/lib/utils/index.js b/packages/strapi-bookshelf/lib/utils/index.js index 5d0c462602..4492a343c0 100755 --- a/packages/strapi-bookshelf/lib/utils/index.js +++ b/packages/strapi-bookshelf/lib/utils/index.js @@ -10,7 +10,7 @@ const _ = require('lodash'); /** * Utils functions for BookShelf */ - +/* eslint-disable prefer-template */ module.exports = { /** diff --git a/scripts/lint.js b/scripts/lint.js index ae978906e4..e2300a728e 100644 --- a/scripts/lint.js +++ b/scripts/lint.js @@ -27,7 +27,7 @@ const watcher = (label, pckgName, type = 'front') => { const packagesPath = path.resolve(process.env.PWD, 'packages'); shell.ls('* -d', packagesPath) // TODO temporary just for eslint - .filter(package => package === 'strapi') + .filter(package => package === 'strapi-bookshelf') // .filter(package => package !== 'README.md') .forEach(package => { watcher(`Testing ${package}`, package);