mirror of
https://github.com/strapi/strapi.git
synced 2025-08-20 14:49:38 +00:00
Use ESLint instead of xo
This commit is contained in:
parent
b7378d029a
commit
5c24f33c28
4
.eslintignore
Normal file
4
.eslintignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
packages/strapi-generate-new/files/public/**
|
||||||
|
packages/strapi-generate-admin/files/admin/public/**
|
||||||
|
website/
|
||||||
|
**/node_modules/**
|
31
.eslintrc
Normal file
31
.eslintrc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"plugins": [
|
||||||
|
"react",
|
||||||
|
"jsx-a11y"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
|
"es6": true,
|
||||||
|
"node": true,
|
||||||
|
"mocha": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"experimentalObjectRestSpread": true,
|
||||||
|
"jsx": true
|
||||||
|
},
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"strapi": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"indent": ["error", 2, { "SwitchCase": 1 }],
|
||||||
|
"linebreak-style": ["error", "unix"],
|
||||||
|
"no-console": 0,
|
||||||
|
"quotes": ["error", "single"],
|
||||||
|
"semi": ["error", "always"]
|
||||||
|
}
|
||||||
|
}
|
2
Makefile
2
Makefile
@ -5,7 +5,7 @@ export NODE_ENV = test
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
./node_modules/.bin/xo
|
./node_modules/.bin/eslint **/*.js
|
||||||
|
|
||||||
test: lint
|
test: lint
|
||||||
./scripts/test.sh
|
./scripts/test.sh
|
||||||
|
52
package.json
52
package.json
@ -3,50 +3,18 @@
|
|||||||
"version": "3.0.0-alpha.1",
|
"version": "3.0.0-alpha.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"assert": "~1.3.0",
|
"assert": "~1.3.0",
|
||||||
|
"babel-eslint": "^6.1.2",
|
||||||
"coveralls": "~2.11.9",
|
"coveralls": "~2.11.9",
|
||||||
|
"eslint": "^3.12.2",
|
||||||
|
"eslint-config-airbnb": "^13.0.0",
|
||||||
|
"eslint-plugin-import": "^2.2.0",
|
||||||
|
"eslint-plugin-jsx-a11y": "^3.0.2",
|
||||||
|
"eslint-plugin-react": "^6.8.0",
|
||||||
"istanbul": "~0.4.2",
|
"istanbul": "~0.4.2",
|
||||||
|
"lerna": "2.0.0-beta.30",
|
||||||
"mocha": "~2.4.5",
|
"mocha": "~2.4.5",
|
||||||
"mocha-lcov-reporter": "~1.2.0",
|
"mocha-lcov-reporter": "~1.2.0",
|
||||||
"pre-commit": "~1.1.2",
|
"pre-commit": "~1.1.2"
|
||||||
"xo": "~0.13.0",
|
|
||||||
"lerna": "2.0.0-beta.30"
|
|
||||||
},
|
|
||||||
"xo": {
|
|
||||||
"space": true,
|
|
||||||
"esnext": true,
|
|
||||||
"envs": [
|
|
||||||
"mocha",
|
|
||||||
"node"
|
|
||||||
],
|
|
||||||
"globals": [
|
|
||||||
"strapi"
|
|
||||||
],
|
|
||||||
"ignore": [
|
|
||||||
"packages/strapi-generate-new/files/public/**",
|
|
||||||
"packages/strapi-generate-admin/files/admin/public/**",
|
|
||||||
"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-eval": 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
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "make test",
|
"test": "make test",
|
||||||
@ -54,12 +22,12 @@
|
|||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"email": "hi@strapi.io",
|
"email": "hi@strapi.io",
|
||||||
"name": "Strapi team",
|
"name": "Strapi Solutions",
|
||||||
"url": "http://strapi.io"
|
"url": "http://strapi.io"
|
||||||
},
|
},
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
{
|
{
|
||||||
"name": "Strapi team",
|
"name": "Strapi Solutions",
|
||||||
"email": "hi@strapi.io",
|
"email": "hi@strapi.io",
|
||||||
"url": "http://strapi.io"
|
"url": "http://strapi.io"
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ module.exports = function (strapi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (verbose) {
|
switch (verbose) {
|
||||||
case 'hasOne':
|
case 'hasOne': {
|
||||||
const FK = _.findKey(strapi.models[details.model].attributes, details => {
|
const FK = _.findKey(strapi.models[details.model].attributes, details => {
|
||||||
if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
|
if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
|
||||||
return details;
|
return details;
|
||||||
@ -169,20 +169,20 @@ module.exports = function (strapi) {
|
|||||||
return this.hasOne(global[_.capitalize(details.model)], FK);
|
return this.hasOne(global[_.capitalize(details.model)], FK);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'hasMany':
|
case 'hasMany': {
|
||||||
loadedModel[name] = () => {
|
loadedModel[name] = () => {
|
||||||
return this.hasMany(global[_.capitalize(details.collection)], details.via);
|
return this.hasMany(global[_.capitalize(details.collection)], details.via);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'belongsTo':
|
case 'belongsTo': {
|
||||||
loadedModel[name] = () => {
|
loadedModel[name] = () => {
|
||||||
return this.belongsTo(global[_.capitalize(details.model)], name);
|
return this.belongsTo(global[_.capitalize(details.model)], name);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'belongsToMany':
|
case 'belongsToMany': {
|
||||||
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => {
|
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => {
|
||||||
return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
|
return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
|
||||||
}).join('__');
|
}).join('__');
|
||||||
@ -207,10 +207,11 @@ module.exports = function (strapi) {
|
|||||||
return this.belongsToMany(global[_.capitalize(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
|
return this.belongsToMany(global[_.capitalize(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -108,7 +108,7 @@ module.exports = {
|
|||||||
* @return {Object}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
create: (collectionIdentity, rootValue, args) => {
|
create: (collectionIdentity, rootValue) => {
|
||||||
return strapi.services[collectionIdentity.toLowerCase()]
|
return strapi.services[collectionIdentity.toLowerCase()]
|
||||||
.add(rootValue.context.request.body)
|
.add(rootValue.context.request.body)
|
||||||
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
|
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
|
||||||
|
@ -10,8 +10,12 @@ const path = require('path');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
index: async ctx => {
|
index: async ctx => {
|
||||||
|
try {
|
||||||
// Send the HTML file with injected scripts
|
// Send the HTML file with injected scripts
|
||||||
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
|
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
|
||||||
|
} catch (err) {
|
||||||
|
ctx.body = err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
file: async ctx => {
|
file: async ctx => {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
// Node.js core.
|
// Node.js core.
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
* Module dependencies
|
* Module dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Node.js core.
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
@ -19,10 +15,6 @@ const _ = require('lodash');
|
|||||||
module.exports = scope => {
|
module.exports = scope => {
|
||||||
const cliPkg = scope.strapiPackageJSON || {};
|
const cliPkg = scope.strapiPackageJSON || {};
|
||||||
|
|
||||||
// To determine the Strapi dependency to inject
|
|
||||||
// in the newly created `package.json`.
|
|
||||||
const frameworkPkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'strapi', 'package.json'))) || {};
|
|
||||||
|
|
||||||
// Finally, return the JSON.
|
// Finally, return the JSON.
|
||||||
return _.merge(scope.appPackageJSON || {}, {
|
return _.merge(scope.appPackageJSON || {}, {
|
||||||
'name': scope.name,
|
'name': scope.name,
|
||||||
|
@ -36,7 +36,6 @@ module.exports = (scope, cb) => {
|
|||||||
// Use configured module name for this `generatorType` if applicable.
|
// Use configured module name for this `generatorType` if applicable.
|
||||||
const module = 'strapi-generate-' + scope.generatorType;
|
const module = 'strapi-generate-' + scope.generatorType;
|
||||||
let generator;
|
let generator;
|
||||||
let requireError;
|
|
||||||
|
|
||||||
function throwIfModuleNotFoundError(error, module) {
|
function throwIfModuleNotFoundError(error, module) {
|
||||||
const isModuleNotFoundError = error && error.code === 'MODULE_NOT_FOUND' && error.message.match(new RegExp(module));
|
const isModuleNotFoundError = error && error.code === 'MODULE_NOT_FOUND' && error.message.match(new RegExp(module));
|
||||||
@ -52,7 +51,7 @@ module.exports = (scope, cb) => {
|
|||||||
try {
|
try {
|
||||||
generator = require('../../' + module);
|
generator = require('../../' + module);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
requireError = throwIfModuleNotFoundError(error, module);
|
throwIfModuleNotFoundError(error, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!generator) {
|
if (!generator) {
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const mongooseUtils = require('mongoose/lib/utils');
|
const mongooseUtils = require('mongoose/lib/utils');
|
||||||
const pluralize = require('pluralize');
|
|
||||||
|
|
||||||
// Local helpers.
|
// Local helpers.
|
||||||
const utils = require('./utils/');
|
const utils = require('./utils/');
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
* Module dependencies
|
* Module dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Public node modules.
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
module.exports = mongoose => {
|
module.exports = mongoose => {
|
||||||
require('mongoose-double')(mongoose);
|
require('mongoose-double')(mongoose);
|
||||||
require('mongoose-float').loadType(mongoose);
|
require('mongoose-float').loadType(mongoose);
|
||||||
|
@ -55,7 +55,6 @@ module.exports = {
|
|||||||
const ORM = this.getORM(collectionIdentity);
|
const ORM = this.getORM(collectionIdentity);
|
||||||
|
|
||||||
try {
|
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'));
|
const ORMFunctions = require(path.resolve(strapi.config.appPath, 'node_modules', 'strapi-' + ORM, 'lib', 'utils'));
|
||||||
|
|
||||||
if (!_.isUndefined(ORMFunctions)) {
|
if (!_.isUndefined(ORMFunctions)) {
|
||||||
@ -74,7 +73,6 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getNature: (association, key, models) => {
|
getNature: (association, key, models) => {
|
||||||
const strapi = _.isUndefined(global['strapi']) && !_.isUndefined(models) ? _.set({}, 'models', models) : global['strapi'];
|
|
||||||
const types = {
|
const types = {
|
||||||
current: '',
|
current: '',
|
||||||
other: ''
|
other: ''
|
||||||
|
@ -9,9 +9,6 @@
|
|||||||
// Node.js core.
|
// Node.js core.
|
||||||
const REPL = require('repl');
|
const REPL = require('repl');
|
||||||
|
|
||||||
// Public node modules.
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
// Local Strapi dependencies.
|
// Local Strapi dependencies.
|
||||||
const strapi = require('../lib/');
|
const strapi = require('../lib/');
|
||||||
|
|
||||||
|
@ -122,7 +122,9 @@ try {
|
|||||||
cmd.description(info.description);
|
cmd.description(info.description);
|
||||||
cmd.action(require('./strapi-generate'));
|
cmd.action(require('./strapi-generate'));
|
||||||
});
|
});
|
||||||
} catch (err) {}
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
// `$ strapi migrate:make`
|
// `$ strapi migrate:make`
|
||||||
cmd = program.command('migrate:make');
|
cmd = program.command('migrate:make');
|
||||||
|
@ -10,7 +10,6 @@ const http = require('http');
|
|||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
// Local dependencies.
|
// Local dependencies.
|
||||||
const _ = require('lodash');
|
|
||||||
const Koa = require('koa');
|
const Koa = require('koa');
|
||||||
const mixinAfter = require('./private/after');
|
const mixinAfter = require('./private/after');
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ const responses = require('./responses/index');
|
|||||||
const createResponses = ctx => {
|
const createResponses = ctx => {
|
||||||
return _.merge(
|
return _.merge(
|
||||||
responses,
|
responses,
|
||||||
_.mapValues(_.omit(Boom, ['wrap', 'create']), (fn, name) => (...rest) => {
|
_.mapValues(_.omit(Boom, ['wrap', 'create']), (fn) => (...rest) => {
|
||||||
ctx.body = fn(...rest);
|
ctx.body = fn(...rest);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -59,7 +59,7 @@ module.exports = strapi => {
|
|||||||
const endpoint = `${value.method} ${value.path}`;
|
const endpoint = `${value.method} ${value.path}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {route, policies, action, validate} = routerChecker(value, endpoint);
|
const {policies, action, validate} = routerChecker(value, endpoint);
|
||||||
|
|
||||||
if (_.isUndefined(action) || !_.isFunction(action)) {
|
if (_.isUndefined(action) || !_.isFunction(action)) {
|
||||||
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
||||||
@ -88,7 +88,7 @@ module.exports = strapi => {
|
|||||||
const endpoint = `${value.method} ${value.path}`;
|
const endpoint = `${value.method} ${value.path}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {route, policies, action, validate} = routerChecker(value, endpoint);
|
const {policies, action, validate} = routerChecker(value, endpoint);
|
||||||
|
|
||||||
if (_.isUndefined(action) || !_.isFunction(action)) {
|
if (_.isUndefined(action) || !_.isFunction(action)) {
|
||||||
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
||||||
@ -131,7 +131,7 @@ module.exports = strapi => {
|
|||||||
const endpoint = `${value.method} ${value.path}`;
|
const endpoint = `${value.method} ${value.path}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {route, policies, action, validate} = routerChecker(value, endpoint, plugin);
|
const {policies, action, validate} = routerChecker(value, endpoint, plugin);
|
||||||
|
|
||||||
if (_.isUndefined(action) || !_.isFunction(action)) {
|
if (_.isUndefined(action) || !_.isFunction(action)) {
|
||||||
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
||||||
@ -160,7 +160,7 @@ module.exports = strapi => {
|
|||||||
const endpoint = `${value.method} ${value.path}`;
|
const endpoint = `${value.method} ${value.path}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {route, policies, action, validate} = routerChecker(value, endpoint, plugin);
|
const {policies, action, validate} = routerChecker(value, endpoint, plugin);
|
||||||
|
|
||||||
if (_.isUndefined(action) || !_.isFunction(action)) {
|
if (_.isUndefined(action) || !_.isFunction(action)) {
|
||||||
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
|
||||||
|
@ -187,7 +187,7 @@ module.exports = strapi => {
|
|||||||
// an ES6 literal string without parenthesis inside (aka function call).
|
// an ES6 literal string without parenthesis inside (aka function call).
|
||||||
const regex = /^\$\{[^()]*\}$/g;
|
const regex = /^\$\{[^()]*\}$/g;
|
||||||
|
|
||||||
return _.mapValues(object, (value, key) => {
|
return _.mapValues(object, (value) => {
|
||||||
if (_.isPlainObject(value)) {
|
if (_.isPlainObject(value)) {
|
||||||
return templateConfigurations(value);
|
return templateConfigurations(value);
|
||||||
} else if (_.isString(value) && regex.test(value)) {
|
} else if (_.isString(value) && regex.test(value)) {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const async = require('async');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose the strategy to load
|
* Expose the strategy to load
|
||||||
|
@ -53,7 +53,7 @@ module.exports = function (configOverride, cb) {
|
|||||||
initializeHooks: ['loadDictionary', (result, cb) => initializeHooks.apply(this, [cb])],
|
initializeHooks: ['loadDictionary', (result, cb) => initializeHooks.apply(this, [cb])],
|
||||||
// Load hooks into memory.
|
// Load hooks into memory.
|
||||||
loadHooks: ['initializeHooks', (result, cb) => loadHooks.apply(this, [cb])]
|
loadHooks: ['initializeHooks', (result, cb) => loadHooks.apply(this, [cb])]
|
||||||
}, (err, results) => {
|
}, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ module.exports = function (configOverride, cb) {
|
|||||||
const mapper = _.clone(this.config.hooks);
|
const mapper = _.clone(this.config.hooks);
|
||||||
|
|
||||||
// Map (warning: we could have some order issues).
|
// Map (warning: we could have some order issues).
|
||||||
_.assignWith(mapper, this.tree, (objValue, srcValue) => {
|
_.assignWith(mapper, this.tree, (objValue) => {
|
||||||
if (_.isPlainObject(objValue)) {
|
if (_.isPlainObject(objValue)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
* Module dependencies
|
* Module dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Public node modules.
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `strapi.prototype.initialize()`
|
* `strapi.prototype.initialize()`
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user