Start lint fixes

This commit is contained in:
Alexandre Bodin 2019-05-29 16:09:19 +02:00
parent 69b18992df
commit 31a222ecb1
19 changed files with 692 additions and 382 deletions

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
module.exports = async ctx => { module.exports = async (/* ctx */) => {
// return ctx.notFound('My custom message 404'); // return ctx.notFound('My custom message 404');
}; };

View File

@ -1,8 +1,7 @@
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
process(src, filename, config, options) { process(src, filename) {
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
}, },
}; };

View File

@ -1,5 +1,3 @@
const jest = require('jest');
module.exports = { module.exports = {
collectCoverageFrom: [ collectCoverageFrom: [
'packages/strapi-admin/admin/src/**/**/*.js', 'packages/strapi-admin/admin/src/**/**/*.js',

View File

@ -1,5 +1,4 @@
const path = require('path'); const path = require('path');
const chalk = require('chalk');
const fs = require('fs-extra'); const fs = require('fs-extra');
const webpack = require('webpack'); const webpack = require('webpack');
const getWebpackConfig = require('./webpack.config.js'); const getWebpackConfig = require('./webpack.config.js');

View File

@ -1,6 +1,3 @@
const path = require('path');
const pkg = require('./package.json');
const alias = [ const alias = [
'object-assign', 'object-assign',
'whatwg-fetch', 'whatwg-fetch',

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
module.exports = async ctx => { module.exports = async (/* ctx */) => {
// return ctx.notFound('My custom message 404'); // return ctx.notFound('My custom message 404');
}; };

View File

@ -284,7 +284,7 @@ async function handleCustomDatabase({ scope, hasDatabaseConfig, isQuick }) {
message: `Port${ message: `Port${
isMongo ? ' (It will be ignored if you enable +srv)' : '' isMongo ? ' (It will be ignored if you enable +srv)' : ''
}:`, }:`,
default: answers => { default: () => {
// eslint-disable-line no-unused-vars // eslint-disable-line no-unused-vars
if (_.get(scope.database, 'port')) { if (_.get(scope.database, 'port')) {
return scope.database.port; return scope.database.port;

View File

@ -1,5 +1,6 @@
import 'whatwg-fetch'; import 'whatwg-fetch';
import auth from './auth'; import auth from './auth';
import _ from 'lodash';
/** /**
* Parses the JSON returned by a network request * Parses the JSON returned by a network request
@ -136,7 +137,7 @@ export default function request(...args) {
options.headers, options.headers,
{ {
'X-Forwarded-Host': 'strapi', 'X-Forwarded-Host': 'strapi',
}, }
); );
} }
@ -147,7 +148,7 @@ export default function request(...args) {
{ {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
options.headers, options.headers
); );
} }

View File

@ -1,9 +1,14 @@
const _ = require('lodash'); const _ = require('lodash');
const pluralize = require('pluralize');
const { models: utilsModels } = require('strapi-utils'); const { models: utilsModels } = require('strapi-utils');
/* global StrapiConfigs */ /* global StrapiConfigs */
module.exports = async ({ ORM, loadedModel, definition, connection, model }) => { module.exports = async ({
ORM,
loadedModel,
definition,
connection,
model,
}) => {
const quote = definition.client === 'pg' ? '"' : '`'; const quote = definition.client === 'pg' ? '"' : '`';
// Equilize database tables // Equilize database tables

View File

@ -9,8 +9,15 @@ const utils = require('./utils')();
* @param {Object} options.populate - An array of paths to populate * @param {Object} options.populate - An array of paths to populate
* @param {boolean} options.aggregate - Force aggregate function to use group by feature * @param {boolean} options.aggregate - Force aggregate function to use group by feature
*/ */
const buildQuery = ({ model, filters = {}, populate = [], aggregate = false } = {}) => { const buildQuery = ({
const deepFilters = (filters.where || []).filter(({ field }) => field.split('.').length > 1); model,
filters = {},
populate = [],
aggregate = false,
} = {}) => {
const deepFilters = (filters.where || []).filter(
({ field }) => field.split('.').length > 1
);
if (deepFilters.length === 0 && aggregate === false) { if (deepFilters.length === 0 && aggregate === false) {
return buildSimpleQuery({ model, filters, populate }); return buildSimpleQuery({ model, filters, populate });
@ -60,7 +67,11 @@ const buildDeepQuery = ({ model, filters, populate }) => {
// Init the query // Init the query
let query = model let query = model
.aggregate(buildQueryAggregate(model, { paths: _.merge({}, populatePaths, wherePaths) })) .aggregate(
buildQueryAggregate(model, {
paths: _.merge({}, populatePaths, wherePaths),
})
)
.append(buildQueryMatches(model, filters)); .append(buildQueryMatches(model, filters));
query = applyQueryParams({ query, filters }); query = applyQueryParams({ query, filters });
@ -98,7 +109,9 @@ const buildDeepQuery = ({ model, filters, populate }) => {
* Maps to query.count * Maps to query.count
*/ */
count() { count() {
return query.count('count').then(results => _.get(results, ['0', 'count'], 0)); return query
.count('count')
.then(results => _.get(results, ['0', 'count'], 0));
}, },
/** /**
@ -202,7 +215,8 @@ const computePopulatedPaths = ({ model, populate = [], where = [] }) => {
* } * }
* @param {Array<string>} paths - A list of paths to transform * @param {Array<string>} paths - A list of paths to transform
*/ */
const pathsToTree = paths => paths.reduce((acc, path) => _.merge(acc, _.set({}, path, {})), {}); const pathsToTree = paths =>
paths.reduce((acc, path) => _.merge(acc, _.set({}, path, {})), {});
/** /**
* Builds the aggregations pipeling of the query * Builds the aggregations pipeling of the query
@ -246,11 +260,11 @@ const buildLookup = ({ model, key, paths }) => {
].concat( ].concat(
assoc.type === 'model' assoc.type === 'model'
? { ? {
$unwind: { $unwind: {
path: `$${assoc.alias}`, path: `$${assoc.alias}`,
preserveNullAndEmptyArrays: true, preserveNullAndEmptyArrays: true,
}, },
} }
: [] : []
); );
}; };
@ -314,7 +328,9 @@ const buildLookupMatch = ({ assoc }) => {
case 'manyToManyMorph': case 'manyToManyMorph':
case 'oneToManyMorph': { case 'oneToManyMorph': {
return [ return [
{ $unwind: { path: `$${assoc.via}`, preserveNullAndEmptyArrays: true } }, {
$unwind: { path: `$${assoc.via}`, preserveNullAndEmptyArrays: true },
},
{ {
$match: { $match: {
$expr: { $expr: {
@ -424,7 +440,7 @@ const buildWhereClause = ({ field, operator, value }) => {
}; };
default: default:
throw new Error(`Unhandled whereClause : ${fullField} ${operator} ${value}`); throw new Error(`Unhandled whereClause : ${field} ${operator} ${value}`);
} }
}; };
@ -497,7 +513,9 @@ const hydrateModel = ({ model: rootModel, populatedModels }) => async obj => {
acc.push({ acc.push({
path: key, path: key,
data: Array.isArray(val) ? Promise.all(val.map(v => subHydrate(v))) : subHydrate(val), data: Array.isArray(val)
? Promise.all(val.map(v => subHydrate(v)))
: subHydrate(val),
}); });
return acc; return acc;

View File

@ -6,8 +6,6 @@
* @description: A set of functions similar to controller's actions to avoid code duplication. * @description: A set of functions similar to controller's actions to avoid code duplication.
*/ */
const fs = require('fs');
const path = require('path');
const { gql, makeExecutableSchema } = require('apollo-server-koa'); const { gql, makeExecutableSchema } = require('apollo-server-koa');
const _ = require('lodash'); const _ = require('lodash');
const graphql = require('graphql'); const graphql = require('graphql');
@ -287,7 +285,7 @@ const schemaBuilder = {
writeGenerateSchema: schema => { writeGenerateSchema: schema => {
return strapi.fs.writeAppFile('exports/graphql/schema.graphql', schema); return strapi.fs.writeAppFile('exports/graphql/schema.graphql', schema);
} },
}; };
module.exports = schemaBuilder; module.exports = schemaBuilder;

View File

@ -42,7 +42,9 @@ describe('convertRestQueryParams', () => {
expect(() => convertRestQueryParams({ _sort: {} })).toThrow(); expect(() => convertRestQueryParams({ _sort: {} })).toThrow();
expect(() => convertRestQueryParams({ _sort: 'id,,test' })).toThrow(); expect(() => convertRestQueryParams({ _sort: 'id,,test' })).toThrow();
expect(() => convertRestQueryParams({ _sort: 'id,test,' })).toThrow(); expect(() => convertRestQueryParams({ _sort: 'id,test,' })).toThrow();
expect(() => convertRestQueryParams({ _sort: 'id:asc,test:dasc' })).toThrow(); expect(() =>
convertRestQueryParams({ _sort: 'id:asc,test:dasc' })
).toThrow();
expect(() => convertRestQueryParams({ _sort: 'id:asc,:asc' })).toThrow(); expect(() => convertRestQueryParams({ _sort: 'id:asc,:asc' })).toThrow();
}); });
@ -52,9 +54,18 @@ describe('convertRestQueryParams', () => {
['id:ASC', [{ field: 'id', order: 'asc' }]], ['id:ASC', [{ field: 'id', order: 'asc' }]],
['id:DESC', [{ field: 'id', order: 'desc' }]], ['id:DESC', [{ field: 'id', order: 'desc' }]],
['id:asc', [{ field: 'id', order: 'asc' }]], ['id:asc', [{ field: 'id', order: 'asc' }]],
['id,price', [{ field: 'id', order: 'asc' }, { field: 'price', order: 'asc' }]], [
['id:desc,price', [{ field: 'id', order: 'desc' }, { field: 'price', order: 'asc' }]], 'id,price',
['id:desc,price:desc', [{ field: 'id', order: 'desc' }, { field: 'price', order: 'desc' }]], [{ field: 'id', order: 'asc' }, { field: 'price', order: 'asc' }],
],
[
'id:desc,price',
[{ field: 'id', order: 'desc' }, { field: 'price', order: 'asc' }],
],
[
'id:desc,price:desc',
[{ field: 'id', order: 'desc' }, { field: 'price', order: 'desc' }],
],
[ [
'id:asc,price,date:desc', 'id:asc,price,date:desc',
[ [
@ -72,7 +83,9 @@ describe('convertRestQueryParams', () => {
], ],
], ],
])('Converts sort query "%s" correctly', (input, expected) => { ])('Converts sort query "%s" correctly', (input, expected) => {
expect(convertRestQueryParams({ _sort: input })).toMatchObject({ sort: expected }); expect(convertRestQueryParams({ _sort: input })).toMatchObject({
sort: expected,
});
}); });
}); });
@ -86,7 +99,7 @@ describe('convertRestQueryParams', () => {
expect(() => convertRestQueryParams({ _start: 'Infinity' })).toThrow(); expect(() => convertRestQueryParams({ _start: 'Infinity' })).toThrow();
expect(() => convertRestQueryParams({ _start: Infinity })).toThrow(); expect(() => convertRestQueryParams({ _start: Infinity })).toThrow();
expect(() => convertRestQueryParams({ _start: -Infinity })).toThrow(); expect(() => convertRestQueryParams({ _start: -Infinity })).toThrow();
expect(() => convertRestQueryParams({ _start: Nan })).toThrow(); expect(() => convertRestQueryParams({ _start: NaN })).toThrow();
expect(() => convertRestQueryParams({ _start: 1.2 })).toThrow(); expect(() => convertRestQueryParams({ _start: 1.2 })).toThrow();
expect(() => convertRestQueryParams({ _start: -10 })).toThrow(); expect(() => convertRestQueryParams({ _start: -10 })).toThrow();
expect(() => convertRestQueryParams({ _start: {} })).toThrow(); expect(() => convertRestQueryParams({ _start: {} })).toThrow();
@ -95,7 +108,9 @@ describe('convertRestQueryParams', () => {
test.each([['1', 1], ['12', 12], ['0', 0]])( test.each([['1', 1], ['12', 12], ['0', 0]])(
'Converts start query "%s" correctly', 'Converts start query "%s" correctly',
(input, expected) => { (input, expected) => {
expect(convertRestQueryParams({ _start: input })).toMatchObject({ start: expected }); expect(convertRestQueryParams({ _start: input })).toMatchObject({
start: expected,
});
} }
); );
}); });
@ -110,7 +125,7 @@ describe('convertRestQueryParams', () => {
expect(() => convertRestQueryParams({ _limit: 'Infinity' })).toThrow(); expect(() => convertRestQueryParams({ _limit: 'Infinity' })).toThrow();
expect(() => convertRestQueryParams({ _limit: Infinity })).toThrow(); expect(() => convertRestQueryParams({ _limit: Infinity })).toThrow();
expect(() => convertRestQueryParams({ _limit: -Infinity })).toThrow(); expect(() => convertRestQueryParams({ _limit: -Infinity })).toThrow();
expect(() => convertRestQueryParams({ _limit: Nan })).toThrow(); expect(() => convertRestQueryParams({ _limit: NaN })).toThrow();
expect(() => convertRestQueryParams({ _limit: 1.2 })).toThrow(); expect(() => convertRestQueryParams({ _limit: 1.2 })).toThrow();
expect(() => convertRestQueryParams({ _limit: -10 })).toThrow(); expect(() => convertRestQueryParams({ _limit: -10 })).toThrow();
expect(() => convertRestQueryParams({ _limit: {} })).toThrow(); expect(() => convertRestQueryParams({ _limit: {} })).toThrow();
@ -119,7 +134,9 @@ describe('convertRestQueryParams', () => {
test.each([['1', 1], ['12', 12], ['0', 0]])( test.each([['1', 1], ['12', 12], ['0', 0]])(
'Converts start query "%s" correctly', 'Converts start query "%s" correctly',
(input, expected) => { (input, expected) => {
expect(convertRestQueryParams({ _start: input })).toMatchObject({ start: expected }); expect(convertRestQueryParams({ _start: input })).toMatchObject({
start: expected,
});
} }
); );
}); });
@ -130,7 +147,9 @@ describe('convertRestQueryParams', () => {
describe('Filters', () => { describe('Filters', () => {
test('Can combine filters', () => { test('Can combine filters', () => {
expect(convertRestQueryParams({ id: '1', test_ne: 'text', test_: 'content' })).toMatchObject({ expect(
convertRestQueryParams({ id: '1', test_ne: 'text', test_: 'content' })
).toMatchObject({
where: [ where: [
{ {
field: 'id', field: 'id',
@ -167,7 +186,9 @@ describe('convertRestQueryParams', () => {
], ],
}); });
expect(convertRestQueryParams({ id_eq: '1', test_eq: 'text' })).toMatchObject({ expect(
convertRestQueryParams({ id_eq: '1', test_eq: 'text' })
).toMatchObject({
where: [ where: [
{ {
field: 'id', field: 'id',
@ -182,7 +203,9 @@ describe('convertRestQueryParams', () => {
], ],
}); });
expect(convertRestQueryParams({ published_at: '2019-01-01:00:00:00' })).toMatchObject({ expect(
convertRestQueryParams({ published_at: '2019-01-01:00:00:00' })
).toMatchObject({
where: [ where: [
{ {
field: 'published_at', field: 'published_at',
@ -302,7 +325,9 @@ describe('convertRestQueryParams', () => {
}); });
test('Not Contains', () => { test('Not Contains', () => {
expect(convertRestQueryParams({ sub_title_ncontains: 'text' })).toMatchObject({ expect(
convertRestQueryParams({ sub_title_ncontains: 'text' })
).toMatchObject({
where: [ where: [
{ {
field: 'sub_title', field: 'sub_title',
@ -314,7 +339,9 @@ describe('convertRestQueryParams', () => {
}); });
test('Not Contains sensitive', () => { test('Not Contains sensitive', () => {
expect(convertRestQueryParams({ content_text_ncontainss: 'test' })).toMatchObject({ expect(
convertRestQueryParams({ content_text_ncontainss: 'test' })
).toMatchObject({
where: [ where: [
{ {
field: 'content_text', field: 'content_text',
@ -326,7 +353,9 @@ describe('convertRestQueryParams', () => {
}); });
test('Not Contains sensitive', () => { test('Not Contains sensitive', () => {
expect(convertRestQueryParams({ 'content.text_ncontainss': 'test' })).toMatchObject({ expect(
convertRestQueryParams({ 'content.text_ncontainss': 'test' })
).toMatchObject({
where: [ where: [
{ {
field: 'content.text', field: 'content.text',

View File

@ -2,7 +2,6 @@
const path = require('path'); const path = require('path');
const cluster = require('cluster'); const cluster = require('cluster');
const _ = require('lodash');
const fs = require('fs-extra'); const fs = require('fs-extra');
const { cyan } = require('chalk'); const { cyan } = require('chalk');
const chokidar = require('chokidar'); const chokidar = require('chokidar');

View File

@ -1,6 +1,7 @@
const { join } = require('path'); const { join } = require('path');
const { existsSync } = require('fs-extra'); const { existsSync } = require('fs-extra');
const ora = require('ora'); const ora = require('ora');
const { cyan } = require('chalk');
const execa = require('execa'); const execa = require('execa');
const { cli } = require('strapi-utils'); const { cli } = require('strapi-utils');
const findPackagePath = require('../load/package-path'); const findPackagePath = require('../load/package-path');

View File

@ -14,7 +14,6 @@ const path = require('path');
const _ = require('lodash'); const _ = require('lodash');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { machineIdSync } = require('node-machine-id'); const { machineIdSync } = require('node-machine-id');
const shell = require('shelljs');
const execa = require('execa'); const execa = require('execa');
// Master of ceremonies for generators. // Master of ceremonies for generators.

View File

@ -4,6 +4,7 @@ const { join } = require('path');
const { existsSync, rmdirSync } = require('fs-extra'); const { existsSync, rmdirSync } = require('fs-extra');
const ora = require('ora'); const ora = require('ora');
const execa = require('execa'); const execa = require('execa');
const { cyan } = require('chalk');
const inquirer = require('inquirer'); const inquirer = require('inquirer');
const { cli } = require('strapi-utils'); const { cli } = require('strapi-utils');
const findPackagePath = require('../load/package-path'); const findPackagePath = require('../load/package-path');

View File

@ -1,6 +1,5 @@
'use strict'; 'use strict';
const _ = require('lodash');
const findPackagePath = require('../load/package-path'); const findPackagePath = require('../load/package-path');
const loadFiles = require('../load/load-files'); const loadFiles = require('../load/load-files');
const loadConfig = require('../load/load-config-files'); const loadConfig = require('../load/load-config-files');

View File

@ -1,6 +1,5 @@
'use strict'; 'use strict';
const path = require('path');
const _ = require('lodash'); const _ = require('lodash');
/** /**