diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..8adabe5f85 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +packages/strapi-generate-new/files/public/** +packages/strapi-generate-admin/files/admin/public/** +website/ +**/node_modules/** diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000000..caeccce790 --- /dev/null +++ b/.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"] + } +} diff --git a/Makefile b/Makefile index e370586897..57201cf075 100755 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/package.json b/package.json index 116b516275..83a25d5ed1 100644 --- a/package.json +++ b/package.json @@ -3,50 +3,18 @@ "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", @@ -54,12 +22,12 @@ }, "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" } diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index 69705cea5c..097d7ec12a 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -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; @@ -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('__'); @@ -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(); diff --git a/packages/strapi-bookshelf/lib/utils/graphql.js b/packages/strapi-bookshelf/lib/utils/graphql.js index cb5b5d7d00..f4131a0184 100755 --- a/packages/strapi-bookshelf/lib/utils/graphql.js +++ b/packages/strapi-bookshelf/lib/utils/graphql.js @@ -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); diff --git a/packages/strapi-generate-admin/files/admin/controllers/Admin.js b/packages/strapi-generate-admin/files/admin/controllers/Admin.js index 8f063b4ede..62539a2665 100644 --- a/packages/strapi-generate-admin/files/admin/controllers/Admin.js +++ b/packages/strapi-generate-admin/files/admin/controllers/Admin.js @@ -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 => { diff --git a/packages/strapi-generate-api/json/routes.json.js b/packages/strapi-generate-api/json/routes.json.js index 31656e2c37..ef3db85573 100755 --- a/packages/strapi-generate-api/json/routes.json.js +++ b/packages/strapi-generate-api/json/routes.json.js @@ -6,7 +6,6 @@ // Node.js core. const fs = require('fs'); -const path = require('path'); // Public node modules. const _ = require('lodash'); diff --git a/packages/strapi-generate-new/json/package.json.js b/packages/strapi-generate-new/json/package.json.js index 34e072ada5..30252d8d5f 100755 --- a/packages/strapi-generate-new/json/package.json.js +++ b/packages/strapi-generate-new/json/package.json.js @@ -4,10 +4,6 @@ * Module dependencies */ -// Node.js core. -const fs = require('fs'); -const path = require('path'); - // Public node modules. const _ = require('lodash'); @@ -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, diff --git a/packages/strapi-generate/lib/index.js b/packages/strapi-generate/lib/index.js index e3f556b68b..4fd3955557 100755 --- a/packages/strapi-generate/lib/index.js +++ b/packages/strapi-generate/lib/index.js @@ -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)); @@ -52,7 +51,7 @@ module.exports = (scope, cb) => { try { generator = require('../../' + module); } catch (error) { - requireError = throwIfModuleNotFoundError(error, module); + throwIfModuleNotFoundError(error, module); } if (!generator) { diff --git a/packages/strapi-mongoose/lib/index.js b/packages/strapi-mongoose/lib/index.js index 6ef54094e3..699f0be90b 100644 --- a/packages/strapi-mongoose/lib/index.js +++ b/packages/strapi-mongoose/lib/index.js @@ -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/'); diff --git a/packages/strapi-mongoose/lib/utils/index.js b/packages/strapi-mongoose/lib/utils/index.js index 84f681aeb8..cce47d239f 100644 --- a/packages/strapi-mongoose/lib/utils/index.js +++ b/packages/strapi-mongoose/lib/utils/index.js @@ -4,9 +4,6 @@ * Module dependencies */ -// Public node modules. -const _ = require('lodash'); - module.exports = mongoose => { require('mongoose-double')(mongoose); require('mongoose-float').loadType(mongoose); diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js index 4bce03a2e1..2aef036f39 100644 --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -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)) { @@ -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: '' diff --git a/packages/strapi/bin/strapi-console.js b/packages/strapi/bin/strapi-console.js index 0c9dc2cd23..c9556cef77 100755 --- a/packages/strapi/bin/strapi-console.js +++ b/packages/strapi/bin/strapi-console.js @@ -9,9 +9,6 @@ // Node.js core. const REPL = require('repl'); -// Public node modules. -const _ = require('lodash'); - // Local Strapi dependencies. const strapi = require('../lib/'); diff --git a/packages/strapi/bin/strapi.js b/packages/strapi/bin/strapi.js index d1cad5e7b9..bb4d966246 100755 --- a/packages/strapi/bin/strapi.js +++ b/packages/strapi/bin/strapi.js @@ -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'); diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 9171ba431e..d99a0ec0c2 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -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'); diff --git a/packages/strapi/lib/configuration/hooks/core/responses/policy.js b/packages/strapi/lib/configuration/hooks/core/responses/policy.js index dc165b35e7..e5b91e901d 100644 --- a/packages/strapi/lib/configuration/hooks/core/responses/policy.js +++ b/packages/strapi/lib/configuration/hooks/core/responses/policy.js @@ -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); }) ); diff --git a/packages/strapi/lib/configuration/hooks/core/router/index.js b/packages/strapi/lib/configuration/hooks/core/router/index.js index 5ad66ae31e..9aef389bde 100644 --- a/packages/strapi/lib/configuration/hooks/core/router/index.js +++ b/packages/strapi/lib/configuration/hooks/core/router/index.js @@ -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.'); @@ -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.'); @@ -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.'); @@ -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.'); diff --git a/packages/strapi/lib/configuration/hooks/dictionary/_config/index.js b/packages/strapi/lib/configuration/hooks/dictionary/_config/index.js index 94f950b356..86f2d11319 100644 --- a/packages/strapi/lib/configuration/hooks/dictionary/_config/index.js +++ b/packages/strapi/lib/configuration/hooks/dictionary/_config/index.js @@ -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)) { diff --git a/packages/strapi/lib/configuration/hooks/index.js b/packages/strapi/lib/configuration/hooks/index.js index 2937391098..411cb23b16 100644 --- a/packages/strapi/lib/configuration/hooks/index.js +++ b/packages/strapi/lib/configuration/hooks/index.js @@ -6,7 +6,6 @@ // Public node modules. const _ = require('lodash'); -const async = require('async'); /** * Expose the strategy to load diff --git a/packages/strapi/lib/load.js b/packages/strapi/lib/load.js index 876d15e208..5ac2cefcce 100644 --- a/packages/strapi/lib/load.js +++ b/packages/strapi/lib/load.js @@ -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); } @@ -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; } diff --git a/packages/strapi/lib/private/initialize.js b/packages/strapi/lib/private/initialize.js index ae1e0d51d1..dbb55af7a4 100644 --- a/packages/strapi/lib/private/initialize.js +++ b/packages/strapi/lib/private/initialize.js @@ -4,9 +4,6 @@ * Module dependencies */ -// Public node modules. -const _ = require('lodash'); - /** * `strapi.prototype.initialize()` *