Skip to content

Commit

Permalink
fix(eslint-plugin): remove unneeded conditional check
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 11, 2020
1 parent 30e0c02 commit 41b637b
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions packages/eslint-plugin/src/rules/class-literals-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,35 @@ export default util.createRule<Options, MessageIds>({
};
}

if (style === 'getters') {
return {
ClassProperty(node: TSESTree.ClassProperty): void {
if (!node.readonly || node.declare) {
return;
}

const { value } = node;

if (!value || !isSupportedLiteral(value)) {
return;
}

context.report({
node: node.key,
messageId: 'preferGetterStyle',
fix(fixer) {
const sourceCode = context.getSourceCode();
const name = sourceCode.getText(node.key);

let text = '';

text += printNodeModifiers(node, 'get');
text += node.computed ? `[${name}]` : name;
text += `() { return ${sourceCode.getText(value)}; }`;

return fixer.replaceText(node, text);
},
});
},
};
}

return {};
return {
ClassProperty(node: TSESTree.ClassProperty): void {
if (!node.readonly || node.declare) {
return;
}

const { value } = node;

if (!value || !isSupportedLiteral(value)) {
return;
}

context.report({
node: node.key,
messageId: 'preferGetterStyle',
fix(fixer) {
const sourceCode = context.getSourceCode();
const name = sourceCode.getText(node.key);

let text = '';

text += printNodeModifiers(node, 'get');
text += node.computed ? `[${name}]` : name;
text += `() { return ${sourceCode.getText(value)}; }`;

return fixer.replaceText(node, text);
},
});
},
};
},
});

0 comments on commit 41b637b

Please sign in to comment.