mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Add eslint to ctm backend folders
This commit is contained in:
parent
80dd0ef7d8
commit
8a4412d6d6
75
packages/strapi-lint/lib/internals/eslintBack/.eslintrc.json
Normal file
75
packages/strapi-lint/lib/internals/eslintBack/.eslintrc.json
Normal file
@ -0,0 +1,75 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"extends": [
|
||||
"airbnb",
|
||||
"prettier",
|
||||
"eslint:recommended"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"mocha": true,
|
||||
"es6": true
|
||||
},
|
||||
"plugins": [
|
||||
"redux-saga",
|
||||
"react",
|
||||
"jsx-a11y"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 7,
|
||||
"sourceType": "module",
|
||||
"ecmaFeatures": {
|
||||
"impliedStrict": true,
|
||||
"jsx": true
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"comma-dangle": [
|
||||
0,
|
||||
"always-multiline"
|
||||
],
|
||||
"import/newline-after-import": 0,
|
||||
"import/no-dynamic-require": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/no-named-as-default": 0,
|
||||
"import/no-unresolved": 2,
|
||||
"import/prefer-default-export": 0,
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"groups": [
|
||||
"builtin",
|
||||
"external",
|
||||
"internal",
|
||||
"parent",
|
||||
"sibling",
|
||||
"index"
|
||||
]
|
||||
}
|
||||
],
|
||||
"import/imports-first": 2,
|
||||
"indent": [
|
||||
2,
|
||||
2,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"max-len": 0,
|
||||
"newline-per-chained-call": 0,
|
||||
"no-console": 1,
|
||||
"no-use-before-define": 0,
|
||||
"prefer-template": 2,
|
||||
"class-methods-use-this": 0,
|
||||
"no-undef": 0,
|
||||
"semi": 2
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"webpack": {
|
||||
"config": "node_modules/strapi-lint/lib/internals/webpack/webpack.test.babel.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
const config = require('./.eslintrc.json');
|
||||
// Update the eslint configuration for `strapi-helper-plugin` module
|
||||
if (process.env.IS_HELPER) {
|
||||
config.settings['import/resolver'].webpack.config = './lib/internals/webpack/webpack.test.babel.js';
|
||||
}
|
||||
module.exports = config;
|
||||
@ -6,7 +6,7 @@ module.exports = {
|
||||
_.forEach(params.where, (where, key) => {
|
||||
if (_.isArray(where.value)) {
|
||||
for (const value in where.value) {
|
||||
qb[value ? 'where' : 'orWhere'](key, where.symbol, where.value[value])
|
||||
qb[value ? 'where' : 'orWhere'](key, where.symbol, where.value[value]);
|
||||
}
|
||||
} else {
|
||||
qb.where(key, where.symbol, where.value);
|
||||
@ -29,13 +29,13 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
count: async function (params) {
|
||||
count: async function () {
|
||||
return await this
|
||||
.forge()
|
||||
.count();
|
||||
},
|
||||
|
||||
findOne: async function (params, populate, raw = true) {
|
||||
findOne: async function (params, populate) {
|
||||
const record = await this
|
||||
.forge({
|
||||
[this.primaryKey]: params[this.primaryKey]
|
||||
@ -50,12 +50,12 @@ module.exports = {
|
||||
if (_.isEmpty(populate)) {
|
||||
const arrayOfPromises = this.associations
|
||||
.filter(association => ['manyMorphToOne', 'manyMorphToMany'].includes(association.nature))
|
||||
.map(association => {
|
||||
.map(association => { // eslint-disable-line no-unused-vars
|
||||
return this.morph.forge()
|
||||
.where({
|
||||
[`${this.collectionName}_id`]: params[this.primaryKey]
|
||||
})
|
||||
.fetchAll()
|
||||
.fetchAll();
|
||||
});
|
||||
|
||||
const related = await Promise.all(arrayOfPromises);
|
||||
@ -82,7 +82,7 @@ module.exports = {
|
||||
.forge(values)
|
||||
.save()
|
||||
.catch((err) => {
|
||||
if (err.detail) {
|
||||
if (err.detail) {
|
||||
const field = _.last(_.words(err.detail.split('=')[0]));
|
||||
err = { message: `This ${field} is already taken`, field };
|
||||
}
|
||||
@ -223,7 +223,7 @@ module.exports = {
|
||||
});
|
||||
break;
|
||||
case 'oneToManyMorph':
|
||||
case 'manyToManyMorph':
|
||||
case 'manyToManyMorph': {
|
||||
const transformToArrayID = (array) => {
|
||||
if(_.isArray(array)) {
|
||||
return array.map(value => {
|
||||
@ -232,7 +232,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
if (association.type === 'model' || (association.type === 'collection' && _.isObject(array))) {
|
||||
@ -270,6 +270,7 @@ module.exports = {
|
||||
}));
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'oneMorphToOne':
|
||||
case 'oneMorphToMany':
|
||||
break;
|
||||
@ -371,11 +372,11 @@ module.exports = {
|
||||
}
|
||||
|
||||
return await this.morph.forge({
|
||||
[`${this.collectionName}_id`]: params.id,
|
||||
[`${params.alias}_id`]: params.refId,
|
||||
[`${params.alias}_type`]: params.ref,
|
||||
field: params.field
|
||||
})
|
||||
[`${this.collectionName}_id`]: params.id,
|
||||
[`${params.alias}_id`]: params.refId,
|
||||
[`${params.alias}_type`]: params.ref,
|
||||
field: params.field
|
||||
})
|
||||
.save();
|
||||
},
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ module.exports = {
|
||||
.populate(populate || this.associations.map(x => x.alias).join(' '));
|
||||
},
|
||||
|
||||
count: async function (params) {
|
||||
count: async function () {
|
||||
return Number(await this
|
||||
.count());
|
||||
},
|
||||
@ -105,7 +105,7 @@ module.exports = {
|
||||
}
|
||||
return Promise.resolve();
|
||||
})
|
||||
.then(response => {
|
||||
.then(() => {
|
||||
// Updating the new relations
|
||||
// When params.values[current] is null this means that we are removing the relation.
|
||||
// Recreate relation on the first side
|
||||
@ -206,11 +206,11 @@ module.exports = {
|
||||
ref: obj.refId,
|
||||
kind: globalId,
|
||||
[association.filter]: obj.field
|
||||
}
|
||||
};
|
||||
});
|
||||
break;
|
||||
case 'oneToManyMorph':
|
||||
case 'manyToManyMorph':
|
||||
case 'manyToManyMorph': {
|
||||
const transformToArrayID = (array) => {
|
||||
if (_.isArray(array)) {
|
||||
return array.map(value => {
|
||||
@ -219,7 +219,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
if (association.type === 'model' || (association.type === 'collection' && _.isObject(array))) {
|
||||
@ -229,21 +229,21 @@ module.exports = {
|
||||
return [];
|
||||
};
|
||||
|
||||
// Compare array of ID to find deleted files.
|
||||
const currentValue = transformToArrayID(response[current]).map(id => id.toString());
|
||||
const storedValue = transformToArrayID(params.values[current]).map(id => id.toString());
|
||||
// Compare array of ID to find deleted files.
|
||||
const currentValue = transformToArrayID(response[current]).map(id => id.toString());
|
||||
const storedValue = transformToArrayID(params.values[current]).map(id => id.toString());
|
||||
|
||||
const toAdd = _.difference(storedValue, currentValue);
|
||||
const toRemove = _.difference(currentValue, storedValue);
|
||||
const toAdd = _.difference(storedValue, currentValue);
|
||||
const toRemove = _.difference(currentValue, storedValue);
|
||||
|
||||
// Remove relations in the other side.
|
||||
toAdd.forEach(id => {
|
||||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).addRelationMorph({
|
||||
id,
|
||||
alias: association.via,
|
||||
ref: this.globalId,
|
||||
refId: response._id,
|
||||
field: association.alias
|
||||
// Remove relations in the other side.
|
||||
toAdd.forEach(id => {
|
||||
virtualFields.push(strapi.query(details.model || details.collection, details.plugin).addRelationMorph({
|
||||
id,
|
||||
alias: association.via,
|
||||
ref: this.globalId,
|
||||
refId: response._id,
|
||||
field: association.alias
|
||||
}));
|
||||
});
|
||||
|
||||
@ -258,6 +258,7 @@ module.exports = {
|
||||
}));
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'oneMorphToOne':
|
||||
case 'oneMorphToMany':
|
||||
break;
|
||||
|
||||
@ -17,9 +17,10 @@
|
||||
"build:clean": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build",
|
||||
"start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development PLUGIN=true node ./node_modules/strapi-helper-plugin/lib/server",
|
||||
"generate": "node ./node_modules/plop/plop.js --plopfile ./node_modules/strapi-helper-plugin/lib/internals/generators/index.js",
|
||||
"lint": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslintFront/.eslintrc.json admin",
|
||||
"lint:front": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslintFront/.eslintrc.json admin",
|
||||
"lint:back": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslintBack/.eslintrc.json controllers config services",
|
||||
"prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"",
|
||||
"test": "npm run lint",
|
||||
"test": "npm run lint:front && npm run lint:back",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -48,4 +49,4 @@
|
||||
"npm": ">= 5.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
fetchAll: async (params, query) => {
|
||||
const { limit, skip = 0, sort, query : request, queryAttribute, source, page, populate = [] } = query;
|
||||
const { limit, skip = 0, sort, query : request, queryAttribute, source, page, populate = [] } = query; // eslint-disable-line no-unused-vars
|
||||
|
||||
// Find entries using `queries` system
|
||||
return await strapi.query(params.model, source).find({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user