Skip to content

Commit

Permalink
[eslint] change operator-linebreak option for ternary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Feb 22, 2020
1 parent 434b45f commit 6c96412
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -23,7 +23,7 @@
"ignoreTemplateLiterals": true,
"ignoreComments": true,
}],
"operator-linebreak": [2, "after"],
"operator-linebreak": [2, "after", {"overrides": {"?": "before", ":": "before" }}],
"consistent-return": 0,

"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/function-component-definition.js
Expand Up @@ -162,9 +162,9 @@ module.exports = {
fixerOptions: {
type: namedConfig,
template: NAMED_FUNCTION_TEMPLATES[namedConfig],
range: node.type === 'FunctionDeclaration' ?
node.range :
node.parent.parent.range
range: node.type === 'FunctionDeclaration'
? node.range
: node.parent.parent.range
}
});
}
Expand Down
24 changes: 12 additions & 12 deletions lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -64,9 +64,9 @@ module.exports = {
create(context) {
const HTML_ENTITY_REGEX = () => /&[A-Za-z\d#]+;/g;
const ruleOptions = context.options[0];
const userConfig = typeof ruleOptions === 'string' ?
{props: ruleOptions, children: ruleOptions} :
Object.assign({}, DEFAULT_CONFIG, ruleOptions);
const userConfig = typeof ruleOptions === 'string'
? {props: ruleOptions, children: ruleOptions}
: Object.assign({}, DEFAULT_CONFIG, ruleOptions);

function containsLineTerminators(rawStringValue) {
return /[\n\r\u2028\u2029]/.test(rawStringValue);
Expand Down Expand Up @@ -167,17 +167,17 @@ module.exports = {

let textToReplace;
if (parentType === 'JSXAttribute') {
textToReplace = `"${expressionType === 'TemplateLiteral' ?
expression.quasis[0].value.raw :
expression.raw.substring(1, expression.raw.length - 1)
textToReplace = `"${expressionType === 'TemplateLiteral'
? expression.quasis[0].value.raw
: expression.raw.substring(1, expression.raw.length - 1)
}"`;
} else if (jsxUtil.isJSX(expression)) {
const sourceCode = context.getSourceCode();

textToReplace = sourceCode.getText(expression);
} else {
textToReplace = expressionType === 'TemplateLiteral' ?
expression.quasis[0].value.cooked : expression.value;
textToReplace = expressionType === 'TemplateLiteral'
? expression.quasis[0].value.cooked : expression.value;
}

return fixer.replaceText(JSXExpressionNode, textToReplace);
Expand All @@ -201,11 +201,11 @@ module.exports = {
return null;
}

const expression = literalNode.parent.type === 'JSXAttribute' ?
`{"${escapeDoubleQuotes(escapeBackslashes(
const expression = literalNode.parent.type === 'JSXAttribute'
? `{"${escapeDoubleQuotes(escapeBackslashes(
literalNode.raw.substring(1, literalNode.raw.length - 1)
))}"}` :
wrapWithCurlyBraces(literalNode.raw);
))}"}`
: wrapWithCurlyBraces(literalNode.raw);

return fixer.replaceText(literalNode, expression);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/rules/jsx-curly-newline.js
Expand Up @@ -131,9 +131,9 @@ module.exports = {
return sourceCode
.getText()
.slice(leftCurly.range[1], tokenAfterLeftCurly.range[0])
.trim() ?
null : // If there is a comment between the { and the first element, don't do a fix.
fixer.removeRange([leftCurly.range[1], tokenAfterLeftCurly.range[0]]);
.trim()
? null // If there is a comment between the { and the first element, don't do a fix.
: fixer.removeRange([leftCurly.range[1], tokenAfterLeftCurly.range[0]]);
}
});
} else if (!hasLeftNewline && needsNewlines) {
Expand All @@ -152,9 +152,9 @@ module.exports = {
return sourceCode
.getText()
.slice(tokenBeforeRightCurly.range[1], rightCurly.range[0])
.trim() ?
null : // If there is a comment between the last element and the }, don't do a fix.
fixer.removeRange([
.trim()
? null // If there is a comment between the last element and the }, don't do a fix.
: fixer.removeRange([
tokenBeforeRightCurly.range[1],
rightCurly.range[0]
]);
Expand Down
24 changes: 12 additions & 12 deletions lib/rules/jsx-handler-names.js
Expand Up @@ -70,19 +70,19 @@ module.exports = {

const configuration = context.options[0] || {};

const eventHandlerPrefix = isPrefixDisabled(configuration.eventHandlerPrefix) ?
null :
configuration.eventHandlerPrefix || 'handle';
const eventHandlerPropPrefix = isPrefixDisabled(configuration.eventHandlerPropPrefix) ?
null :
configuration.eventHandlerPropPrefix || 'on';
const eventHandlerPrefix = isPrefixDisabled(configuration.eventHandlerPrefix)
? null
: configuration.eventHandlerPrefix || 'handle';
const eventHandlerPropPrefix = isPrefixDisabled(configuration.eventHandlerPropPrefix)
? null
: configuration.eventHandlerPropPrefix || 'on';

const EVENT_HANDLER_REGEX = !eventHandlerPrefix ?
null :
new RegExp(`^((props\\.${eventHandlerPropPrefix || ''})|((.*\\.)?${eventHandlerPrefix}))[A-Z].*$`);
const PROP_EVENT_HANDLER_REGEX = !eventHandlerPropPrefix ?
null :
new RegExp(`^(${eventHandlerPropPrefix}[A-Z].*|ref)$`);
const EVENT_HANDLER_REGEX = !eventHandlerPrefix
? null
: new RegExp(`^((props\\.${eventHandlerPropPrefix || ''})|((.*\\.)?${eventHandlerPrefix}))[A-Z].*$`);
const PROP_EVENT_HANDLER_REGEX = !eventHandlerPropPrefix
? null
: new RegExp(`^(${eventHandlerPropPrefix}[A-Z].*|ref)$`);

const checkLocal = !!configuration.checkLocalVariables;

Expand Down
6 changes: 3 additions & 3 deletions lib/rules/jsx-no-literals.js
Expand Up @@ -48,9 +48,9 @@ module.exports = {
const config = Object.assign({}, defaults, context.options[0] || {});
config.allowedStrings = new Set(config.allowedStrings.map(trimIfString));

const message = config.noStrings ?
'Strings not allowed in JSX files' :
'Missing JSX expression container around literal string';
const message = config.noStrings
? 'Strings not allowed in JSX files'
: 'Missing JSX expression container around literal string';

function reportLiteralNode(node) {
context.report({
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-array-index-key.js
Expand Up @@ -87,9 +87,9 @@ module.exports = {
return null;
}

const callbackArg = isUsingReactChildren(node) ?
node.arguments[1] :
node.arguments[0];
const callbackArg = isUsingReactChildren(node)
? node.arguments[1]
: node.arguments[0];

if (!callbackArg) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-typos.js
Expand Up @@ -134,9 +134,9 @@ module.exports = {
}
STATIC_CLASS_PROPERTIES.forEach((CLASS_PROP) => {
if (propertyName && CLASS_PROP.toLowerCase() === propertyName.toLowerCase() && CLASS_PROP !== propertyName) {
const message = isClassProperty ?
'Typo in static class property declaration' :
'Typo in property declaration';
const message = isClassProperty
? 'Typo in static class property declaration'
: 'Typo in property declaration';
context.report({
node: propertyKey,
message
Expand Down
12 changes: 6 additions & 6 deletions lib/util/Components.js
Expand Up @@ -53,9 +53,9 @@ function isReturnsConditionalJSX(node, property, strict) {
const returnsConditionalJSXAlternate = node[property] &&
node[property].type === 'ConditionalExpression' &&
jsxUtil.isJSX(node[property].alternate);
return strict ?
(returnsConditionalJSXConsequent && returnsConditionalJSXAlternate) :
(returnsConditionalJSXConsequent || returnsConditionalJSXAlternate);
return strict
? (returnsConditionalJSXConsequent && returnsConditionalJSXAlternate)
: (returnsConditionalJSXConsequent || returnsConditionalJSXAlternate);
}

function isReturnsLogicalJSX(node, property, strict) {
Expand All @@ -65,9 +65,9 @@ function isReturnsLogicalJSX(node, property, strict) {
const returnsLogicalJSXRight = node[property] &&
node[property].type === 'LogicalExpression' &&
jsxUtil.isJSX(node[property].right);
return strict ?
(returnsLogicalJSXLeft && returnsLogicalJSXRight) :
(returnsLogicalJSXLeft || returnsLogicalJSXRight);
return strict
? (returnsLogicalJSXLeft && returnsLogicalJSXRight)
: (returnsLogicalJSXLeft || returnsLogicalJSXRight);
}

const Lists = new WeakMap();
Expand Down
12 changes: 6 additions & 6 deletions lib/util/ast.js
Expand Up @@ -92,9 +92,9 @@ function getFirstNodeInLine(context, node) {
let lines;
do {
token = sourceCode.getTokenBefore(token);
lines = token.type === 'JSXText' ?
token.value.split('\n') :
null;
lines = token.type === 'JSXText'
? token.value.split('\n')
: null;
} while (
token.type === 'JSXText' &&
/^\s*$/.test(lines[lines.length - 1])
Expand Down Expand Up @@ -160,9 +160,9 @@ function stripQuotes(string) {
function getKeyValue(context, node) {
if (node.type === 'ObjectTypeProperty') {
const tokens = context.getFirstTokens(node, 2);
return (tokens[0].value === '+' || tokens[0].value === '-' ?
tokens[1].value :
stripQuotes(tokens[0].value)
return (tokens[0].value === '+' || tokens[0].value === '-'
? tokens[1].value
: stripQuotes(tokens[0].value)
);
}
if (node.type === 'GenericTypeAnnotation') {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/usedPropTypes.js
Expand Up @@ -330,9 +330,9 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
}
type = 'destructuring';
const propParam = isSetStateUpdater(node) ? node.params[1] : node.params[0];
properties = propParam.type === 'AssignmentPattern' ?
propParam.left.properties :
propParam.properties;
properties = propParam.type === 'AssignmentPattern'
? propParam.left.properties
: propParam.properties;
break;
}
case 'ObjectPattern':
Expand Down

0 comments on commit 6c96412

Please sign in to comment.