From 2809ff6888847d6e6a5a149fb29f68251c8cc501 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Mon, 9 Oct 2017 14:46:30 -0400 Subject: [PATCH] Configure prettier and eslint-config-standard (#1123) --- .eslintrc-preferred.yml | 27 ++++++++++++++++++--------- .prettierignore | 4 ++++ .prettierrc.yml | 3 +++ lib/badge.js | 1 + lib/github-provider.js | 2 +- lib/request-handler.js | 1 + lib/suggest.js | 2 ++ package.json | 8 ++++++++ service-tests/bower.js | 2 +- service-tests/helpers/validators.js | 2 +- 10 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.yml diff --git a/.eslintrc-preferred.yml b/.eslintrc-preferred.yml index 4c2dafdfef439..c5097e46ae9c3 100644 --- a/.eslintrc-preferred.yml +++ b/.eslintrc-preferred.yml @@ -1,13 +1,22 @@ +# plugins: +# - "prettier" + +extends: + - "standard" + - "prettier" + +parserOptions: + # Override eslint-config-standard, which incorrectly sets this to "module", + # though that setting is only for ES6 modules, not CommonJS modules. + sourceType: "script" + rules: - # From eslint-config-standard. - arrow-spacing: ["error", { "before": true, "after": true }] - brace-style: ["error", "1tbs", { "allowSingleLine": true }] - camelcase: ["error", { "properties": "never" }] - func-style: ["error", "declaration", { "allowArrowFunctions": true }] - indent: ["error", 2, { "SwitchCase": 1 }] - key-spacing: ["error", { "beforeColon": false, "afterColon": true }] - no-trailing-spaces: "error" - quotes: ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }] + # prettier/prettier: "error" + + # These are not disabled by eslint-config-prettier + spaced-comment: "off" + standard/object-curly-even-spacing: "off" + one-var: "off" # Shields additions. no-var: "error" diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000000..5852e09a2a083 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +server.js +server.spec.js +gh-badge.js +gh-badge.spec.js diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000000000..5a5e190e56812 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,3 @@ +singleQuote: true +trailingComma: es5 +bracketSpacing: true diff --git a/lib/badge.js b/lib/badge.js index 6d7c1c9965196..4b19ae70f725e 100644 --- a/lib/badge.js +++ b/lib/badge.js @@ -138,6 +138,7 @@ function makeImage(data, cb) { try { result = template(data); } catch(e) { + // eslint-disable-next-line standard/no-callback-literal cb('', e); return; } diff --git a/lib/github-provider.js b/lib/github-provider.js index 6bf1e18f77c7c..da115907cda55 100644 --- a/lib/github-provider.js +++ b/lib/github-provider.js @@ -75,7 +75,7 @@ function mapGithubCommitsSince(camp, githubApiUrl, githubAuth) { //Github Release & Pre-Release Date Integration release-date-pre (?:\/(all))? function mapGithubReleaseDate(camp, githubApiUrl, githubAuth) { - camp.route(/^\/github\/(release-date|release-date-pre)\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/, + camp.route(/^\/github\/(release-date|release-date-pre)\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/, cache(function (data, match, sendBadge, request) { const releaseType = match[1]; // eg, release-date-pre / release-date const user = match[2]; // eg, microsoft diff --git a/lib/request-handler.js b/lib/request-handler.js index 7bda73a266aa9..288400cd6ac63 100644 --- a/lib/request-handler.js +++ b/lib/request-handler.js @@ -1,5 +1,6 @@ 'use strict'; +// eslint-disable-next-line node/no-deprecated-api const domain = require('domain'); const request = require('request'); const badge = require('./badge'); diff --git a/lib/suggest.js b/lib/suggest.js index 40190bba420a1..0081b69304119 100644 --- a/lib/suggest.js +++ b/lib/suggest.js @@ -43,8 +43,10 @@ function findSuggestions (url, cb) { } promises.push(twitterPage(url)); Promise.all(promises).then(function(badges) { + // eslint-disable-next-line standard/no-callback-literal cb({badges: badges.filter(function(b) { return b != null; })}); }).catch(function(err) { + // eslint-disable-next-line standard/no-callback-literal cb({badges: [], err: err}); }); } diff --git a/package.json b/package.json index 2a17e1b554d1d..cbc4826e7903d 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,13 @@ "child-process-promise": "^2.2.1", "dejavu-fonts-ttf": "^2.37.3", "eslint": "^3.18.0", + "eslint-config-prettier": "^2.6.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-node": "^5.2.0", + "eslint-plugin-prettier": "^2.3.1", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", "glob": "^7.1.1", "icedfrisby": "^1.2.0", "icedfrisby-nock": "^1.0.0", @@ -81,6 +88,7 @@ "nock": "^9.0.13", "node-fetch": "^1.6.3", "opn-cli": "^3.1.0", + "prettier": "1.7.3", "read-all-stdin-sync": "^1.0.5", "sinon": "^2.1.0" }, diff --git a/service-tests/bower.js b/service-tests/bower.js index 1ee4de4a1d1ca..518c528a2f169 100644 --- a/service-tests/bower.js +++ b/service-tests/bower.js @@ -4,7 +4,7 @@ const Joi = require('joi'); const ServiceTester = require('./runner/service-tester'); const { isVPlusDottedVersionAtLeastOne } = require('./helpers/validators'); -const isBowerPrereleaseVersion = Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(\-?\w)+?$/); +const isBowerPrereleaseVersion = Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(-?\w)+?$/); const t = new ServiceTester({ id: 'bower', title: 'Bower' }); module.exports = t; diff --git a/service-tests/helpers/validators.js b/service-tests/helpers/validators.js index 681fc3017ea49..bd662a70b2dce 100644 --- a/service-tests/helpers/validators.js +++ b/service-tests/helpers/validators.js @@ -12,7 +12,7 @@ const isStarRating = withRegex(/^[\u2605\u2606]{5}$/); const isMetric = withRegex(/^[0-9]+[kMGTPEZY]?$/); -const isPercentage = withRegex(/^[0-9]+\%$/); +const isPercentage = withRegex(/^[0-9]+%$/); const isFileSize = withRegex(/^[0-9]*[.]?[0-9]+\s(B|kB|MB|GB|TB|PB|EB|ZB|YB)$/);