Skip to content

Commit

Permalink
fix: Infer trailingComma properly
Browse files Browse the repository at this point in the history
This should fix #105.
  • Loading branch information
zimme committed Dec 12, 2017
1 parent a5f3d98 commit 3316f12
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const OPTION_GETTERS = {
ruleValueToPrettierOption: getSingleQuote
},
trailingComma: {
ruleValue: rules => getRuleValue(rules, "comma-dangle"),
ruleValue: rules => getRuleValue(rules, "comma-dangle", []),
ruleValueToPrettierOption: getTrailingComma
},
bracketSpacing: {
Expand Down Expand Up @@ -197,16 +197,18 @@ function getSingleQuote(eslintValue, fallbacks) {
return makePrettierOption("singleQuote", prettierValue, fallbacks);
}

function getTrailingComma(value, fallbacks, rules) {
function getTrailingComma(eslintValue, fallbacks) {
let prettierValue;
const actualValue = rules["comma-dangle"];

if (value === "never") {
if (eslintValue === "never") {
prettierValue = "none";
} else if (typeof value === "string" && value.indexOf("always") === 0) {
} else if (
typeof eslintValue === "string" &&
eslintValue.indexOf("always") === 0
) {
prettierValue = "es5";
} else if (typeof actualValue === "object") {
prettierValue = getValFromTrailingCommaConfig(actualValue);
} else if (typeof eslintValue === "object") {
prettierValue = getValFromTrailingCommaConfig(eslintValue);
} else {
prettierValue = RULE_NOT_CONFIGURED;
}
Expand All @@ -215,7 +217,7 @@ function getTrailingComma(value, fallbacks, rules) {
}

function getValFromTrailingCommaConfig(objectConfig) {
const [, { arrays = "", objects = "", functions = "" }] = objectConfig;
const { arrays = "", objects = "", functions = "" } = objectConfig;
const fns = isAlways(functions);
const es5 = [arrays, objects].some(isAlways);

Expand Down

0 comments on commit 3316f12

Please sign in to comment.