@calystral/prettier-plugin-solidity
Version:
prettier plugin for solidity
29 lines (27 loc) • 703 B
JavaScript
const {
doc: {
builders: { group, concat, ifBreak, indent, softline }
}
} = require('prettier/standalone');
module.exports = {
match: (op) => op === '**',
print: (node, path, print) => {
const right = concat([
ifBreak(' ', ''),
node.operator,
softline,
path.call(print, 'right')
]);
// If it's a single binary operation, avoid having a small right
// operand like - 1 on its own line
const shouldGroup =
node.left.type !== 'BinaryOperation' &&
path.getParentNode().type !== 'BinaryOperation';
return group(
concat([
path.call(print, 'left'),
indent(shouldGroup ? group(right) : right)
])
);
}
};