From 7c457e5d5d7f805f1d60088b22c901a1e3c9310d Mon Sep 17 00:00:00 2001 From: Simon Fridlund Date: Wed, 13 Dec 2017 00:20:00 +0100 Subject: [PATCH] feat: Add support for arrowParens --- package.json | 2 +- src/__tests__/utils.js | 15 ++++++++++++++- src/utils.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 182c1023..aa9bc654 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "indent-string": "^3.2.0", "lodash.merge": "^4.6.0", "loglevel-colored-level-prefix": "^1.0.0", - "prettier": "^1.7.1", + "prettier": "^1.9.0", "pretty-format": "^21.2.1", "require-relative": "^0.8.7", "typescript": "^2.5.1", diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index 4ed1123a..2f21c0a8 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -134,6 +134,18 @@ const getPrettierOptionsFromESLintRulesTests = [ }, options: { jsxBracketSameLine: true } }, + { + rules: { + "arrow-parens": [2, "always"] + }, + options: { arrowParens: "always" } + }, + { + rules: { + "arrow-parens": [2, "as-needed"] + }, + options: { arrowParens: "avoid" } + }, // If an ESLint rule is disabled fall back to prettier defaults. { rules: { "max-len": [0, { code: 120 }] }, options: {} }, @@ -152,7 +164,8 @@ const getPrettierOptionsFromESLintRulesTests = [ { rules: { indent: ["warn", 4] }, options: { tabWidth: 4 } }, { rules: { indent: ["error", "tab"] }, options: { useTabs: true } }, { rules: { indent: [2, "tab"] }, options: { useTabs: true } }, - { rules: { "react/jsx-closing-bracket-location": [0] }, options: {} } + { rules: { "react/jsx-closing-bracket-location": [0] }, options: {} }, + { rules: { "arrow-parens": [0] }, options: {} } ]; getPrettierOptionsFromESLintRulesTests.forEach( diff --git a/src/utils.js b/src/utils.js index 6e9e7e16..d0db63b0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -48,6 +48,10 @@ const OPTION_GETTERS = { ruleValue: rules => getRuleValue(rules, "react/jsx-closing-bracket-location", "nonEmpty"), ruleValueToPrettierOption: getJsxBracketSameLine + }, + arrowParens: { + ruleValue: rules => getRuleValue(rules, "arrow-parens"), + ruleValueToPrettierOption: getArrowParens } }; @@ -285,9 +289,22 @@ function getJsxBracketSameLine(eslintValue, fallbacks) { } else { prettierValue = eslintValue; } + return makePrettierOption("jsxBracketSameLine", prettierValue, fallbacks); } +function getArrowParens(eslintValue, fallbacks) { + let prettierValue; + + if (eslintValue === "as-needed") { + prettierValue = "avoid"; + } else { + prettierValue = eslintValue; + } + + return makePrettierOption("arrowParens", prettierValue, fallbacks); +} + function extractRuleValue(objPath, name, value) { if (objPath) { logger.trace(