Skip to content

Commit

Permalink
Remove ability to handle quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyho112 committed Aug 16, 2017
1 parent c299551 commit b180919
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,12 @@
const OPTION_ALWAYS = 'always';
const OPTION_NEVER = 'never';
const OPTION_IGNORE = 'ignore';
const OPTION_SINGLE_QUOTE = 'single';
const OPTION_DOUBLE_QUOTE = 'double';
const DEAULT_QUOTE_OPTION = OPTION_DOUBLE_QUOTE;
const OPTION_ORIGINAL_QUOTE = 'original';

const OPTION_VALUES = [
OPTION_ALWAYS,
`${OPTION_ALWAYS},${OPTION_SINGLE_QUOTE}`,
`${OPTION_ALWAYS},${OPTION_DOUBLE_QUOTE}`,
`${OPTION_ALWAYS},${OPTION_ORIGINAL_QUOTE}`,
OPTION_NEVER,
OPTION_IGNORE
];
const QUOTE_OPTON_VALUE_STORE = {
[OPTION_SINGLE_QUOTE]: '\'',
[OPTION_DOUBLE_QUOTE]: '"',
[OPTION_ORIGINAL_QUOTE]: '"' // Defaults to double if no orignal quote
};
const DEFAULT_CONFIG = {props: OPTION_NEVER, children: OPTION_NEVER};

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,19 +101,8 @@ module.exports = {
const value = literalNode.value;
const valueContainsQuote = containsQuote(value);
let text = raw;
let userSetQuoteOption;

if (parentType === 'JSXAttribute') {
userSetQuoteOption = userConfig.props.split(',')[1];
text = raw.substring(1, raw.length - 1);
} else if (parentType === 'JSXElement') {
userSetQuoteOption = userConfig.children.split(',')[1];
}

if (
parentType === 'JSXAttribute' &&
(userSetQuoteOption === OPTION_ORIGINAL_QUOTE || valueContainsQuote)
) {
if (parentType === 'JSXAttribute' && valueContainsQuote) {
return fixer.replaceText(literalNode, `{${raw}}`);
}

Expand All @@ -137,13 +114,7 @@ module.exports = {
return fixer.replaceText(literalNode, `{${JSON.stringify(value)}}`);
}

const quoteStyle = QUOTE_OPTON_VALUE_STORE[
userSetQuoteOption || DEAULT_QUOTE_OPTION
];
return fixer.replaceText(
literalNode,
`{${quoteStyle}${text}${quoteStyle}}`
);
return fixer.replaceText(literalNode, `{"${text}"}`);
}

function reportMissingCurly(literalNode) {
Expand Down

0 comments on commit b180919

Please sign in to comment.