Skip to content

Commit

Permalink
Use ESLint instead of xo
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelsicoko committed Jan 4, 2017
1 parent b7378d0 commit 5c24f33
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 89 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
@@ -0,0 +1,4 @@
packages/strapi-generate-new/files/public/**
packages/strapi-generate-admin/files/admin/public/**
website/
**/node_modules/**
31 changes: 31 additions & 0 deletions .eslintrc
@@ -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 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@ export NODE_ENV = test
.PHONY: test

lint:
./node_modules/.bin/xo
./node_modules/.bin/eslint **/*.js

test: lint
./scripts/test.sh
Expand Down
52 changes: 10 additions & 42 deletions package.json
Expand Up @@ -3,63 +3,31 @@
"version": "3.0.0-alpha.1",
"devDependencies": {
"assert": "~1.3.0",
"babel-eslint": "^6.1.2",
"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",
"lerna": "2.0.0-beta.30",
"mocha": "~2.4.5",
"mocha-lcov-reporter": "~1.2.0",
"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
}
"pre-commit": "~1.1.2"
},
"scripts": {
"test": "make test",
"setup": "make setup"
},
"author": {
"email": "hi@strapi.io",
"name": "Strapi team",
"name": "Strapi Solutions",
"url": "http://strapi.io"
},
"maintainers": [
{
"name": "Strapi team",
"name": "Strapi Solutions",
"email": "hi@strapi.io",
"url": "http://strapi.io"
}
Expand Down
19 changes: 10 additions & 9 deletions packages/strapi-bookshelf/lib/index.js
Expand Up @@ -158,7 +158,7 @@ module.exports = function (strapi) {
}

switch (verbose) {
case 'hasOne':
case 'hasOne': {
const FK = _.findKey(strapi.models[details.model].attributes, details => {
if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
return details;
Expand All @@ -169,20 +169,20 @@ module.exports = function (strapi) {
return this.hasOne(global[_.capitalize(details.model)], FK);
};
break;

case 'hasMany':
}
case 'hasMany': {
loadedModel[name] = () => {
return this.hasMany(global[_.capitalize(details.collection)], details.via);
};
break;

case 'belongsTo':
}
case 'belongsTo': {
loadedModel[name] = () => {
return this.belongsTo(global[_.capitalize(details.model)], name);
};
break;

case 'belongsToMany':
}
case 'belongsToMany': {
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => {
return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
}).join('__');
Expand All @@ -207,9 +207,10 @@ module.exports = function (strapi) {
return this.belongsToMany(global[_.capitalize(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
};
break;

default:
}
default: {
break;
}
}

done();
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-bookshelf/lib/utils/graphql.js
Expand Up @@ -108,7 +108,7 @@ module.exports = {
* @return {Object}
*/

create: (collectionIdentity, rootValue, args) => {
create: (collectionIdentity, rootValue) => {
return strapi.services[collectionIdentity.toLowerCase()]
.add(rootValue.context.request.body)
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
Expand Down
Expand Up @@ -10,8 +10,12 @@ const path = require('path');
module.exports = {

index: async ctx => {
// Send the HTML file with injected scripts
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
try {
// Send the HTML file with injected scripts
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
} catch (err) {
ctx.body = err;
}
},

file: async ctx => {
Expand Down
1 change: 0 additions & 1 deletion packages/strapi-generate-api/json/routes.json.js
Expand Up @@ -6,7 +6,6 @@

// Node.js core.
const fs = require('fs');
const path = require('path');

// Public node modules.
const _ = require('lodash');
Expand Down
8 changes: 0 additions & 8 deletions packages/strapi-generate-new/json/package.json.js
Expand Up @@ -4,10 +4,6 @@
* Module dependencies
*/

// Node.js core.
const fs = require('fs');
const path = require('path');

// Public node modules.
const _ = require('lodash');

Expand All @@ -19,10 +15,6 @@ const _ = require('lodash');
module.exports = scope => {
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.
return _.merge(scope.appPackageJSON || {}, {
'name': scope.name,
Expand Down
3 changes: 1 addition & 2 deletions packages/strapi-generate/lib/index.js
Expand Up @@ -36,7 +36,6 @@ module.exports = (scope, cb) => {
// Use configured module name for this `generatorType` if applicable.
const module = 'strapi-generate-' + scope.generatorType;
let generator;
let requireError;

function throwIfModuleNotFoundError(error, module) {
const isModuleNotFoundError = error && error.code === 'MODULE_NOT_FOUND' && error.message.match(new RegExp(module));
Expand All @@ -52,7 +51,7 @@ module.exports = (scope, cb) => {
try {
generator = require('../../' + module);
} catch (error) {
requireError = throwIfModuleNotFoundError(error, module);
throwIfModuleNotFoundError(error, module);
}

if (!generator) {
Expand Down
1 change: 0 additions & 1 deletion packages/strapi-mongoose/lib/index.js
Expand Up @@ -8,7 +8,6 @@
const _ = require('lodash');
const mongoose = require('mongoose');
const mongooseUtils = require('mongoose/lib/utils');
const pluralize = require('pluralize');

// Local helpers.
const utils = require('./utils/');
Expand Down
3 changes: 0 additions & 3 deletions packages/strapi-mongoose/lib/utils/index.js
Expand Up @@ -4,9 +4,6 @@
* Module dependencies
*/

// Public node modules.
const _ = require('lodash');

module.exports = mongoose => {
require('mongoose-double')(mongoose);
require('mongoose-float').loadType(mongoose);
Expand Down
2 changes: 0 additions & 2 deletions packages/strapi-utils/lib/models.js
Expand Up @@ -55,7 +55,6 @@ 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)) {
Expand All @@ -74,7 +73,6 @@ module.exports = {
*/

getNature: (association, key, models) => {
const strapi = _.isUndefined(global['strapi']) && !_.isUndefined(models) ? _.set({}, 'models', models) : global['strapi'];
const types = {
current: '',
other: ''
Expand Down
3 changes: 0 additions & 3 deletions packages/strapi/bin/strapi-console.js
Expand Up @@ -9,9 +9,6 @@
// Node.js core.
const REPL = require('repl');

// Public node modules.
const _ = require('lodash');

// Local Strapi dependencies.
const strapi = require('../lib/');

Expand Down
4 changes: 3 additions & 1 deletion packages/strapi/bin/strapi.js
Expand Up @@ -122,7 +122,9 @@ try {
cmd.description(info.description);
cmd.action(require('./strapi-generate'));
});
} catch (err) {}
} catch (err) {
logger.error(err);
}

// `$ strapi migrate:make`
cmd = program.command('migrate:make');
Expand Down
1 change: 0 additions & 1 deletion packages/strapi/lib/Strapi.js
Expand Up @@ -10,7 +10,6 @@ const http = require('http');
const EventEmitter = require('events').EventEmitter;

// Local dependencies.
const _ = require('lodash');
const Koa = require('koa');
const mixinAfter = require('./private/after');

Expand Down
Expand Up @@ -16,7 +16,7 @@ const responses = require('./responses/index');
const createResponses = ctx => {
return _.merge(
responses,
_.mapValues(_.omit(Boom, ['wrap', 'create']), (fn, name) => (...rest) => {
_.mapValues(_.omit(Boom, ['wrap', 'create']), (fn) => (...rest) => {
ctx.body = fn(...rest);
})
);
Expand Down
8 changes: 4 additions & 4 deletions packages/strapi/lib/configuration/hooks/core/router/index.js
Expand Up @@ -59,7 +59,7 @@ module.exports = strapi => {
const endpoint = `${value.method} ${value.path}`;

try {
const {route, policies, action, validate} = routerChecker(value, endpoint);
const {policies, action, validate} = routerChecker(value, endpoint);

if (_.isUndefined(action) || !_.isFunction(action)) {
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = strapi => {
const endpoint = `${value.method} ${value.path}`;

try {
const {route, policies, action, validate} = routerChecker(value, endpoint);
const {policies, action, validate} = routerChecker(value, endpoint);

if (_.isUndefined(action) || !_.isFunction(action)) {
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = strapi => {
const endpoint = `${value.method} ${value.path}`;

try {
const {route, policies, action, validate} = routerChecker(value, endpoint, plugin);
const {policies, action, validate} = routerChecker(value, endpoint, plugin);

if (_.isUndefined(action) || !_.isFunction(action)) {
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
Expand Down Expand Up @@ -160,7 +160,7 @@ module.exports = strapi => {
const endpoint = `${value.method} ${value.path}`;

try {
const {route, policies, action, validate} = routerChecker(value, endpoint, plugin);
const {policies, action, validate} = routerChecker(value, endpoint, plugin);

if (_.isUndefined(action) || !_.isFunction(action)) {
return strapi.log.warn('Ignored attempt to bind route `' + endpoint + '` to unknown controller/action.');
Expand Down
Expand Up @@ -187,7 +187,7 @@ module.exports = strapi => {
// an ES6 literal string without parenthesis inside (aka function call).
const regex = /^\$\{[^()]*\}$/g;

return _.mapValues(object, (value, key) => {
return _.mapValues(object, (value) => {
if (_.isPlainObject(value)) {
return templateConfigurations(value);
} else if (_.isString(value) && regex.test(value)) {
Expand Down
1 change: 0 additions & 1 deletion packages/strapi/lib/configuration/hooks/index.js
Expand Up @@ -6,7 +6,6 @@

// Public node modules.
const _ = require('lodash');
const async = require('async');

/**
* Expose the strategy to load
Expand Down
4 changes: 2 additions & 2 deletions packages/strapi/lib/load.js
Expand Up @@ -53,7 +53,7 @@ module.exports = function (configOverride, cb) {
initializeHooks: ['loadDictionary', (result, cb) => initializeHooks.apply(this, [cb])],
// Load hooks into memory.
loadHooks: ['initializeHooks', (result, cb) => loadHooks.apply(this, [cb])]
}, (err, results) => {
}, (err) => {
if (err) {
console.log(err);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = function (configOverride, cb) {
const mapper = _.clone(this.config.hooks);

// Map (warning: we could have some order issues).
_.assignWith(mapper, this.tree, (objValue, srcValue) => {
_.assignWith(mapper, this.tree, (objValue) => {
if (_.isPlainObject(objValue)) {
return true;
}
Expand Down
3 changes: 0 additions & 3 deletions packages/strapi/lib/private/initialize.js
Expand Up @@ -4,9 +4,6 @@
* Module dependencies
*/

// Public node modules.
const _ = require('lodash');

/**
* `strapi.prototype.initialize()`
*
Expand Down

0 comments on commit 5c24f33

Please sign in to comment.