Fix linter errors

This commit is contained in:
Alberto Maturano 2018-08-20 14:34:22 -05:00
parent 41ff4a84be
commit 1a3e01c66f

View File

@ -456,15 +456,15 @@ module.exports = function(strapi) {
}, start); }, start);
}; };
const generateIndexes = async (table, attrs) => { const generateIndexes = async (table) => {
try { try {
const connection = strapi.config.connections[definition.connection]; const connection = strapi.config.connections[definition.connection];
let columns = Object.keys(attributes).filter(attribute => ['string', 'text'].includes(attributes[attribute].type)); let columns = Object.keys(attributes).filter(attribute => ['string', 'text'].includes(attributes[attribute].type));
switch (connection.settings.client) { switch (connection.settings.client) {
case 'pg': case 'pg': {
// Enable extension to allow GIN indexes. // Enable extension to allow GIN indexes.
await ORM.knex.raw(`CREATE EXTENSION IF NOT EXISTS pg_trgm`); await ORM.knex.raw('CREATE EXTENSION IF NOT EXISTS pg_trgm');
// Create GIN indexes for every column. // Create GIN indexes for every column.
const indexes = columns const indexes = columns
@ -479,6 +479,8 @@ module.exports = function(strapi) {
await Promise.all(indexes); await Promise.all(indexes);
break; break;
}
default: default:
columns = columns columns = columns
.map(attribute => `\`${attribute}\``) .map(attribute => `\`${attribute}\``)
@ -685,9 +687,8 @@ module.exports = function(strapi) {
), ),
table => { table => {
return _.snakeCase( return _.snakeCase(
pluralize.plural(table.collection) + // eslint-disable-next-line prefer-template
' ' + pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via)
pluralize.plural(table.via)
); );
} }
).join('__'); ).join('__');
@ -704,7 +705,7 @@ module.exports = function(strapi) {
resolve(); resolve();
})); }));
} catch (err) { } catch (err) {
strapi.log.error('Impossible to register the `' + model + '` model.'); strapi.log.error(`Impossible to register the '${model}' model.`);
strapi.log.error(err); strapi.log.error(err);
strapi.stop(); strapi.stop();
} }
@ -822,9 +823,8 @@ module.exports = function(strapi) {
), ),
table => { table => {
return _.snakeCase( return _.snakeCase(
pluralize.plural(table.collection) + // eslint-disable-next-line prefer-template
' ' + pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via)
pluralize.plural(table.via)
); );
} }
).join('__'); ).join('__');
@ -848,10 +848,7 @@ module.exports = function(strapi) {
// Sometimes the many-to-many relationships // Sometimes the many-to-many relationships
// is on the same keys on the same models (ex: `friends` key in model `User`) // is on the same keys on the same models (ex: `friends` key in model `User`)
if ( if (`${details.attribute}_${details.column}` === `${relationship.attribute}_${relationship.column}`) {
details.attribute + '_' + details.column ===
relationship.attribute + '_' + relationship.column
) {
relationship.attribute = pluralize.singular(details.via); relationship.attribute = pluralize.singular(details.via);
} }
@ -866,16 +863,16 @@ module.exports = function(strapi) {
return this.belongsToMany( return this.belongsToMany(
GLOBALS[globalId], GLOBALS[globalId],
collectionName, collectionName,
relationship.attribute + '_' + relationship.column, `${relationship.attribute}_${relationship.column}`,
details.attribute + '_' + details.column `${details.attribute}_${details.column}`
).withPivot(details.withPivot); ).withPivot(details.withPivot);
} }
return this.belongsToMany( return this.belongsToMany(
GLOBALS[globalId], GLOBALS[globalId],
collectionName, collectionName,
relationship.attribute + '_' + relationship.column, `${relationship.attribute}_${relationship.column}`,
details.attribute + '_' + details.column `${details.attribute}_${details.column}`
); );
}; };
break; break;
@ -933,7 +930,7 @@ module.exports = function(strapi) {
} }
if (models.length === 0) { if (models.length === 0) {
strapi.log.error('Impossible to register the `' + model + '` model.'); strapi.log.error(`Impossible to register the '${model}' model.`);
strapi.log.error('The collection name cannot be found for the morphTo method.'); strapi.log.error('The collection name cannot be found for the morphTo method.');
strapi.stop(); strapi.stop();
} }