From d8d1d77717d4226aeb8cba2738f9798db615ff6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Hodierne?= Date: Fri, 25 May 2018 08:49:31 +0200 Subject: [PATCH] style(eslint): update to eslint-config-opencollective 1.3.0 implement feedback from eslint-plugin-import and eslint-plugin-node --- .eslintrc | 10 +- package-lock.json | 127 +++++++++++++++++-------- package.json | 12 ++- src/next.config.js | 1 + src/server/controllers/collectives.js | 2 +- src/server/controllers/transactions.js | 52 +--------- src/server/lib/image-generator.js | 2 +- src/server/logger.js | 5 +- src/server/pages.js | 6 +- src/server/routes.js | 2 +- 10 files changed, 115 insertions(+), 104 deletions(-) diff --git a/.eslintrc b/.eslintrc index e692cdb3246..65ee4756844 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,10 +1,12 @@ { - "extends": "opencollective", + "extends": [ + "opencollective", + ], "env": { - "jest": true + "jest": true, }, "rules": { - // we still use console even on frontend - "no-console": 0 + "no-console": 1, + "node/no-unsupported-features": 0, } } diff --git a/package-lock.json b/package-lock.json index 266bd7df086..f83701daf93 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1238,9 +1238,9 @@ } }, "@material-ui/core": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@material-ui/core/-/core-1.2.1.tgz", - "integrity": "sha512-CG1jhJKUedImcdD8OdjQvDO89H/wUH5IVRYP1+cupr25iSpW84T/G0KHGPceoNRNUlbQpmuY98rffHQ7C74yvw==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@material-ui/core/-/core-1.2.2.tgz", + "integrity": "sha512-jg7zDmbPvZsaHkbOJJ+SVMiw1+xcv1GgKRCFV63rCh/IgLN9480K2FjfE2qeFropy2WLw0JBtTwefNzJv3BS3A==", "requires": { "@babel/runtime": "^7.0.0-beta.42", "@types/jss": "^9.5.3", @@ -1264,9 +1264,9 @@ "prop-types": "^15.6.0", "react-event-listener": "^0.6.0", "react-jss": "^8.1.0", - "react-popper": "^0.10.0", + "react-popper": "^1.0.0", "react-transition-group": "^2.2.1", - "recompose": "^0.26.0 || ^0.27.0", + "recompose": "^0.27.0", "scroll": "^2.0.3", "warning": "^4.0.1" } @@ -4453,6 +4453,15 @@ "object-assign": "^4.1.1" } }, + "create-react-context": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/create-react-context/-/create-react-context-0.2.2.tgz", + "integrity": "sha512-KkpaLARMhsTsgp0d2NA/R94F/eDLbhXERdIq3LvX2biCAXcDvHYoOqHfWCHf1+OLj+HKBotLG3KqaOOf+C1C+A==", + "requires": { + "fbjs": "^0.8.0", + "gud": "^1.0.0" + } + }, "cross-fetch": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-2.0.0.tgz", @@ -6027,9 +6036,9 @@ } }, "eslint-config-opencollective": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/eslint-config-opencollective/-/eslint-config-opencollective-1.2.1.tgz", - "integrity": "sha512-KCJVmB78lJazHE1vNxTqG2sKrr0ULqVB/s1gS/GkFlNoU+ioV0M8gszzuOf0CtLEzavtObVGlPYcug+MJdxmXg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-opencollective/-/eslint-config-opencollective-1.3.0.tgz", + "integrity": "sha512-bBYw8qaVipQzuq8aAGPRcIrE3V31vb56LGbV7MHoYYun28BATnVYlw0vo56Ob0+yCZId333AVtY9WIBC6H3ipQ==", "dev": true }, "eslint-import-resolver-node": { @@ -6082,6 +6091,15 @@ } } }, + "eslint-plugin-babel": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-babel/-/eslint-plugin-babel-5.1.0.tgz", + "integrity": "sha512-HBkv9Q0LU/IhNUauC8TrbhcN79Yq/+xh2bYTOcv6KMaV2tsvVphkHwDTJ9r3C6mJUnmxrtzT3DQfrWj0rOISqQ==", + "dev": true, + "requires": { + "eslint-rule-composer": "^0.3.0" + } + }, "eslint-plugin-cypress": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-cypress/-/eslint-plugin-cypress-2.0.1.tgz", @@ -6130,6 +6148,18 @@ } } }, + "eslint-plugin-node": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz", + "integrity": "sha512-Q/Cc2sW1OAISDS+Ji6lZS2KV4b7ueA/WydVWd1BECTQwVvfQy5JAi3glhINoKzoMnfnuRgNP+ZWKrGAbp3QDxw==", + "dev": true, + "requires": { + "ignore": "^3.3.6", + "minimatch": "^3.0.4", + "resolve": "^1.3.3", + "semver": "^5.4.1" + } + }, "eslint-plugin-react": { "version": "7.9.1", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.9.1.tgz", @@ -6142,6 +6172,12 @@ "prop-types": "^15.6.1" } }, + "eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true + }, "eslint-scope": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", @@ -8124,6 +8160,11 @@ "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", "dev": true }, + "gud": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/gud/-/gud-1.0.0.tgz", + "integrity": "sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==" + }, "gzip-size": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-4.1.0.tgz", @@ -12034,9 +12075,9 @@ "dev": true }, "newrelic": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/newrelic/-/newrelic-4.1.5.tgz", - "integrity": "sha1-56wIUrqBl3yQkMco/TJR5Qf1zkU=", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/newrelic/-/newrelic-4.2.0.tgz", + "integrity": "sha1-CI1xL1UN7C0Sidn7V/hq57rSVfs=", "requires": { "@newrelic/koa": "^1.0.0", "@newrelic/native-metrics": "^3.0.0", @@ -13456,11 +13497,10 @@ "integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM=" }, "prop-types": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz", - "integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==", + "version": "15.6.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", + "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", "requires": { - "fbjs": "^0.8.16", "loose-envify": "^1.3.1", "object-assign": "^4.1.1" } @@ -13994,23 +14034,13 @@ } }, "react-event-listener": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/react-event-listener/-/react-event-listener-0.6.0.tgz", - "integrity": "sha512-CqewJSQ/0p09oPZ9BABNvoFhGMhUAuLQ4B4skPsZXxxgOBx+2SP3AgM9lP7zc68pRmJXlCQBDjgOAQsp1jnhAQ==", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/react-event-listener/-/react-event-listener-0.6.1.tgz", + "integrity": "sha1-QceoCmazmMJ91RHiJxKwLz1OzMo=", "requires": { "@babel/runtime": "^7.0.0-beta.42", "prop-types": "^15.6.0", - "warning": "^3.0.0" - }, - "dependencies": { - "warning": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz", - "integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=", - "requires": { - "loose-envify": "^1.0.0" - } - } + "warning": "^4.0.1" } }, "react-geosuggest": { @@ -14062,9 +14092,9 @@ "integrity": "sha512-8ADZg/mBw+t2Fbr5Hm1K64v8q8Q6E+DprV5wQ5A8PSLW6XP0XJFMdUskVEW8efQ5oUgWHn8EYdHEPAMF0Co6hA==" }, "react-jss": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/react-jss/-/react-jss-8.5.0.tgz", - "integrity": "sha512-dHBne879zmufQpiKQG8z6bcarWLtm7K9u05zwZrq+z6Y7VT3PltkgnUG3UYE7isNH5OeCNS7MDR/mwW12nG/4w==", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/react-jss/-/react-jss-8.5.1.tgz", + "integrity": "sha512-5R3qCdGkE+K0+B4tuRyx8idLV7q2pT1QbGomGqberCQ/xLKEQbDukH7ER2QLkpIYqtRkeciG9S03uDJwC1o2gw==", "requires": { "hoist-non-react-statics": "^2.5.0", "jss": "^9.7.0", @@ -14079,9 +14109,9 @@ "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, "react-markdown": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-3.3.2.tgz", - "integrity": "sha512-3GzTB2JY+ciBcpok/t1acM49gAJTuzjSdwbG2+L6r31V6EsZqwx/F0Ht2sbuuKGyGmFCmORpxNrowT2VVbzv+w==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-3.3.4.tgz", + "integrity": "sha512-xOh2uzt93V92n4LxmKg5+ivgJSOFuWdl2K5veTwtMNoEhWnz/w21vEjlp3Da9ISJhEzXZEFFTnjwKboErVGOMQ==", "requires": { "prop-types": "^15.6.1", "remark-parse": "^5.0.0", @@ -14123,12 +14153,26 @@ } }, "react-popper": { - "version": "0.10.4", - "resolved": "https://registry.npmjs.org/react-popper/-/react-popper-0.10.4.tgz", - "integrity": "sha1-rypBXqIike3VBGeNev2opu4ylao=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/react-popper/-/react-popper-1.0.0.tgz", + "integrity": "sha1-uZRSFE6P5KzHf6PZWajHngemUIQ=", "requires": { + "babel-runtime": "6.x.x", + "create-react-context": "^0.2.1", "popper.js": "^1.14.1", - "prop-types": "^15.6.1" + "prop-types": "^15.6.1", + "typed-styles": "^0.0.5", + "warning": "^3.0.0" + }, + "dependencies": { + "warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz", + "integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=", + "requires": { + "loose-envify": "^1.0.0" + } + } } }, "react-prop-types": { @@ -16988,6 +17032,11 @@ "mime-types": "~2.1.18" } }, + "typed-styles": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/typed-styles/-/typed-styles-0.0.5.tgz", + "integrity": "sha512-ht+rEe5UsdEBAa3gr64+QjUOqjOLJfWLvl5HZR5Ev9uo/OnD3p43wPeFSB1hNFc13GXQF/JU1Bn0YHLUqBRIlw==" + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/package.json b/package.json index c0684dd3eaf..cd2cb9bb4eb 100644 --- a/package.json +++ b/package.json @@ -94,10 +94,10 @@ "stop:staging": "heroku ps:scale web=0 -a oc-staging-frontend && heroku ps:scale web=0 -a opencollective-staging-website && heroku ps:scale web=0 -a opencollective-staging-api", "git:clean": "./scripts/git_clean.sh", "postinstall": "if test \"$NODE_ENV\" = \"\" || test \"$NODE_ENV\" = \"development\" ; then echo \"Skipping postinstall build because NODE_ENV is '${NODE_ENV}'\" ; else npm run build ; fi", - "hint": "npm run lint", - "lint": "eslint '**/*.js' --quiet", - "lint:fix": "eslint '**/*.js' --fix", - "pretest": "npm run lint", + "lint": "eslint \"src/**/*.js\"", + "lint:fix": "npm run lint -- --fix", + "lint:quiet": "npm run lint -- --quiet", + "pretest": "npm run lint:quiet", "commit": "git-cz", "semantic-release": "semantic-release", "cypress": "TZ=UTC cypress run" @@ -119,9 +119,11 @@ "cypress": "3.0.1", "cz-conventional-changelog": "^2.1.0", "eslint": "^4.19.1", - "eslint-config-opencollective": "^1.2.1", + "eslint-config-opencollective": "^1.3.0", + "eslint-plugin-babel": "^5.1.0", "eslint-plugin-cypress": "^2.0.1", "eslint-plugin-import": "^2.12.0", + "eslint-plugin-node": "^6.0.1", "eslint-plugin-react": "^7.9.1", "jest": "23.1.0", "jest-styled-components": "^5.0.1", diff --git a/src/next.config.js b/src/next.config.js index 66f619c620c..1dadb5abbcf 100644 --- a/src/next.config.js +++ b/src/next.config.js @@ -13,6 +13,7 @@ module.exports = { new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en|fr|es|ja/), ); if (process.env.WEBPACK_BUNDLE_ANALYZER) { + // eslint-disable-next-line node/no-unpublished-require const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); config.plugins.push( new BundleAnalyzerPlugin({ diff --git a/src/server/controllers/collectives.js b/src/server/controllers/collectives.js index 5f41d1c0a76..9b31e19e6b8 100644 --- a/src/server/controllers/collectives.js +++ b/src/server/controllers/collectives.js @@ -303,7 +303,7 @@ export async function avatar(req, res) { } } - const base64data = new Buffer(data).toString('base64'); + const base64data = Buffer.from(data).toString('base64'); const svg = ` `; diff --git a/src/server/controllers/transactions.js b/src/server/controllers/transactions.js index 17cb520d7ea..154c5d3c4fd 100644 --- a/src/server/controllers/transactions.js +++ b/src/server/controllers/transactions.js @@ -1,55 +1,7 @@ import pdf from 'html-pdf'; -import { logger } from '../logger'; -import { fetchTransaction, fetchTransactions, fetchInvoice } from '../lib/graphql'; -export async function list(req, res, next) { - // Keeping the resulting info for 10m in the CDN cache - res.setHeader('Cache-Control', `public, max-age=${60*10}`); - let allTransactions, path = '/'; - if (req.params.collectiveSlug) { - path += `${req.params.collectiveSlug}/`; - } - try { - allTransactions = await fetchTransactions(req.params.collectiveSlug); - allTransactions = allTransactions.map(t => { - t.url = `https://opencollective.com${path}transactions/${t.id}`; - t.info = `https://opencollective.com${path}transactions/${t.id}.json`; - if (req.params.collectiveSlug) { - delete t.collective; - } - return t; - }) - res.send(allTransactions); - } catch (e) { - if (e.message.match(/No collective found/)) { - return res.status(404).send("Not found"); - } - logger.debug('>>> transactions.list error', e); - return next(e); - } -} - -export async function info(req, res, next) { - // Keeping the resulting info for 10mn in the CDN cache - res.setHeader('Cache-Control', `public, max-age=${60*10}`); - let transaction, path = ''; - if (req.params.collectiveSlug) { - path += `/${req.params.collectiveSlug}/`; - } - try { - transaction = await fetchTransaction(req.params.id); - transaction.url = `https://opencollective.com${path}transactions/${transaction.id}`; - transaction.attendees = `https://opencollective.com${path}transactions/${transaction.id}/attendees.json`; - res.send(transaction); - } catch (e) { - if (e.message.match(/No collective found/)) { - return res.status(404).send("Not found"); - } - logger.debug('>>> transactions.info error', e); - return next(e); - } - -} +import { logger } from '../logger'; +import { fetchInvoice } from '../lib/graphql'; export async function invoice(req, res, next) { // Keeping the resulting info for 10mn in the CDN cache diff --git a/src/server/lib/image-generator.js b/src/server/lib/image-generator.js index 201010b632a..f208093fdc2 100644 --- a/src/server/lib/image-generator.js +++ b/src/server/lib/image-generator.js @@ -142,7 +142,7 @@ export function generateSVGBannerForUsers(users, options) { const contentType = headers['content-type']; const website = (options.linkToProfile || !user.website) ? `${WEBSITE_URL}/${user.slug}` : user.website; - const base64data = new Buffer(rawData).toString('base64'); + const base64data = Buffer.from(rawData).toString('base64'); let avatarWidth = avatarHeight; try { // We make sure the image loaded properly diff --git a/src/server/logger.js b/src/server/logger.js index 9afe472dade..ec1c1c56df3 100644 --- a/src/server/logger.js +++ b/src/server/logger.js @@ -38,4 +38,7 @@ const loggerMiddleware = { }) } -module.exports = { logger, loggerMiddleware }; +export { + logger, + loggerMiddleware +} diff --git a/src/server/pages.js b/src/server/pages.js index a3ae44bbb64..a634436960d 100644 --- a/src/server/pages.js +++ b/src/server/pages.js @@ -38,6 +38,8 @@ pages .add('expense', '/:parentCollectiveSlug?/:collectiveType(events)?/:collectiveSlug/expenses/:ExpenseId([0-9]+)') .add('expenses', '/:parentCollectiveSlug?/:collectiveType(events)?/:collectiveSlug/expenses/:filter(categories|recipients)?/:value?') .add('collective', '/:slug') - .add('editCollective', '/:slug/edit') + .add('editCollective', '/:slug/edit'); - module.exports = pages; +export default pages; + +export const { Link, Router } = pages; diff --git a/src/server/routes.js b/src/server/routes.js index d25e37132f0..997ad124090 100644 --- a/src/server/routes.js +++ b/src/server/routes.js @@ -13,7 +13,7 @@ import { logger } from './logger'; import { getCloudinaryUrl } from './lib/utils'; import { translateApiUrl } from '../lib/utils'; -module.exports = (server, app) => { +export default (server, app) => { server.get('*', mw.ga, (req, res, next) => { req.app = app;