Respect guidelines

This commit is contained in:
loicsaintroch 2016-04-04 22:09:19 +02:00
parent 6df354d809
commit c330c47a4a
9 changed files with 41 additions and 29 deletions

View File

@ -24,10 +24,23 @@
"website/**"
],
"rules": {
"array-callback-return": 0,
"brace-style": 0,
"camelcase": 0,
"default-case": 0,
"dot-notation": 0,
"no-case-declarations": 0,
"no-else-return": 0,
"no-implicit-coercion": 0,
"no-lonely-if": 0,
"no-negated-condition": 0,
"no-throw-literal": 0,
"no-unused-expressions": 0,
"no-unused-vars": 0,
"padded-blocks": 0,
"prefer-template": 0,
"quote-props": 0,
"space-infix-ops": 0,
"strict": 0
}
},

View File

@ -36,7 +36,6 @@ module.exports = function (strapi) {
initialize: function (cb) {
let globalName;
let attributes = [];
// Make sure the Knex hook is present since Knex needs it.
if (!strapi.hooks.knex) {
@ -101,7 +100,7 @@ module.exports = function (strapi) {
const done = _.after(_.size(definition.attributes), function () {
try {
// Initialize lifecycle callbacks.
loadedModel.initialize = function() {
loadedModel.initialize = function () {
const self = this;
const lifecycle = {
creating: 'beforeCreate',
@ -116,7 +115,7 @@ module.exports = function (strapi) {
saved: 'afterSave'
};
_.forEach(lifecycle, function(fn, key) {
_.forEach(lifecycle, function (fn, key) {
if (_.isFunction(strapi.models[model.toLowerCase()][fn])) {
self.on(key, strapi.models[model.toLowerCase()][fn]);
}
@ -155,13 +154,12 @@ module.exports = function (strapi) {
// Build associations key
if (!_.isEmpty(verbose)) {
utilsModels.defineAssociations(globalName, definition, details, name)
utilsModels.defineAssociations(globalName, definition, details, name);
}
switch (verbose) {
case 'hasOne':
// Looking for foreign key on one-to-one relation
const FK = _.findKey(strapi.models[details.model].attributes, function(details) {
const FK = _.findKey(strapi.models[details.model].attributes, function (details) {
if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
return details;
}

View File

@ -32,7 +32,7 @@ module.exports = {
* @return {Object}
*/
fetch: function(collectionIdentity, collection, criteria) {
fetch: function (collectionIdentity, collection, criteria) {
return collection.forge(criteria)
.fetch({withRelated: helpers.getAssociationsByIdentity(collectionIdentity)})
.then(function (data) {
@ -46,7 +46,7 @@ module.exports = {
* @return {Array}
*/
fetchAll: function(collectionIdentity, collection, criteria) {
fetchAll: function (collectionIdentity, collection, criteria) {
const filters = _.omit(helpers.handleFilters(criteria), function (value) {
return _.isUndefined(value) || _.isNumber(value) ? _.isNull(value) : _.isEmpty(value);
});
@ -119,7 +119,7 @@ module.exports = {
return strapi.services[collectionIdentity.toLowerCase()]
.add(rootValue.context.request.body)
.then(function (data) {
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
});
},
@ -145,14 +145,14 @@ module.exports = {
* @return {Object}
*/
delete : function (collectionIdentity, rootValue, args) {
delete: function (collectionIdentity, rootValue, args) {
_.merge(args, rootValue.context.request.body);
return strapi.services[collectionIdentity.toLowerCase()]
.remove(args)
.then(function (data) {
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
})
});
},
/**

View File

@ -20,7 +20,7 @@ module.exports = {
getPK: function (collectionIdentity, collection, models) {
// This is not a Bookshelf collection, only the name.
if (_.isString(collectionIdentity) && !_.isUndefined(models)) {
const PK = _.findKey(_.get(models, collectionIdentity + '.attributes'), function(o) {
const PK = _.findKey(_.get(models, collectionIdentity + '.attributes'), function (o) {
return o.hasOwnProperty('primary');
});
@ -57,4 +57,4 @@ module.exports = {
return count;
});
}
}
};

View File

@ -40,7 +40,7 @@ module.exports = function () {
scope.generatorType = process.argv[2].split(':')[1];
// Register the name.
scope.generatorName = cliArguments[1]
scope.generatorName = cliArguments[1];
// Check that we're in a valid Strapi project.
if (scope.generatorType !== 'new' || scope.generatorType !== 'generator' || scope.generatorType !== 'hook') {

View File

@ -60,25 +60,25 @@ module.exports = function (strapi) {
_.forEach(strapi.config.connections, function (connection, name) {
// Make sure we use the client even if the typo is not the exact one.
switch(connection.client) {
switch (connection.client) {
case 'postgre':
case 'postgres':
case 'postgresql':
connection.client = 'pg'
break;
connection.client = 'pg';
break;
case 'sqlite':
connection.client = 'sqlite3'
break;
connection.client = 'sqlite3';
break;
case 'maria':
case 'mariadb':
connection.client = 'mariasql'
break;
connection.client = 'mariasql';
break;
case 'ms':
connection.client = 'mssql'
break;
connection.client = 'mssql';
break;
case 'web':
connection.client = 'websql'
break;
connection.client = 'websql';
break;
}
// Make sure the client is supported.

View File

@ -95,7 +95,7 @@ module.exports = {
const rootValue = {
graphql: _.get(strapi.api, rootKey + '.config.graphql') || {}
}
};
// Override or write file
fs.writeJson(path.join(strapi.config.appPath, 'api', rootKey, 'config', 'graphql.json'), _.merge(value, rootValue), function (err) {

View File

@ -23,9 +23,9 @@ module.exports = {
getPK: function (collectionIdentity, collection, models) {
if (_.isString(collectionIdentity)) {
const ORM = this.getORM(collectionIdentity);
let GraphQLFunctions;
try {
const GraphQLFunctions = require(path.resolve(strapi.config.appPath, 'node_modules', 'strapi-' + ORM, 'lib', 'utils'));
if (!_.isUndefined(GraphQLFunctions)) {
return GraphQLFunctions.getPK(collectionIdentity, collection, models || strapi.models);
}
@ -46,9 +46,7 @@ module.exports = {
const ORM = this.getORM(collectionIdentity);
try {
const GraphQLFunctions = require(path.resolve(strapi.config.appPath, 'node_modules', 'strapi-' + ORM, 'lib', 'utils'));
const ORMFunctions = require(path.resolve(strapi.config.appPath, 'node_modules', 'strapi-' + ORM, 'lib', 'utils'));
if (!_.isUndefined(ORMFunctions)) {
return ORMFunctions.getCount(collectionIdentity);
}

View File

@ -7,6 +7,9 @@
// Node.js core.
const cluster = require('cluster');
// Public node modules.
const _ = require('lodash');
/**
* `strapi.prototype.initialize()`
*