Skip to content

Commit

Permalink
feat: Add support for arrowParens
Browse files Browse the repository at this point in the history
  • Loading branch information
zimme committed Dec 12, 2017
1 parent 9525dc2 commit 7c457e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} },
Expand All @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7c457e5

Please sign in to comment.