We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a8bb692 commit a7d2c61Copy full SHA for a7d2c61
7 files changed
package-lock.json
package.json
@@ -88,16 +88,16 @@
88
"@eslint/js": "^9.28.0",
89
"@types/jest": "^29.5.14",
90
"@types/semver": "^7.7.0",
91
- "@typescript-eslint/eslint-plugin": "^8.33.1",
92
- "@typescript-eslint/parser": "^8.33.1",
+ "@typescript-eslint/eslint-plugin": "^8.34.0",
+ "@typescript-eslint/parser": "^8.34.0",
93
"c8": "^10.1.3",
94
"cross-env": "^7.0.3",
95
"eslint": "^9.28.0",
96
"eslint-config-prettier": "^10.1.5",
97
"esm-utils": "^4.4.2",
98
"globals": "^16.2.0",
99
"jest": "^29.7.0",
100
- "jest-light-runner": "^0.7.8",
+ "jest-light-runner": "^0.7.9",
101
"jest-snapshot-serializer-ansi": "^2.2.1",
102
"jest-snapshot-serializer-raw": "^2.0.0",
103
"jest-watch-typeahead": "^2.2.2",
src/binary-operator-printers/printers/create-binary-operation-printer.js
@@ -3,8 +3,11 @@ import { assignment } from '../assignment.js';
3
4
const { group, line } = doc.builders;
5
6
-const rightOperandPrinter = (node, path, print) => {
7
- const right = [' ', node.operator, line, path.call(print, 'right')];
+const rightOperandPrinter = (node, path, print, options) => {
+ const right =
8
+ options.experimentalOperatorPosition === 'end'
9
+ ? [' ', node.operator, line, path.call(print, 'right')]
10
+ : [line, node.operator, ' ', path.call(print, 'right')];
11
12
// If it's a single binary operation, avoid having a small right
13
// operand like - 1 on its own line
@@ -23,6 +26,6 @@ export const createBinaryOperationPrinter =
23
26
24
27
return groupIfNecessary([
25
28
path.call(print, 'left'),
- indentIfNecessary(rightOperandPrinter(node, path, print))
29
+ indentIfNecessary(rightOperandPrinter(node, path, print, options))
30
]);
31
};
src/options.ts
@@ -48,6 +48,22 @@ const options: SupportOptions = {
48
oppositeDescription:
49
'Default behavior of ternaries; keep question marks on the same line as the consequent.'
50
},
51
+ experimentalOperatorPosition: {
52
+ category: CATEGORY_JAVASCRIPT,
53
+ type: 'choice',
54
+ default: 'end',
55
+ description: 'Where to print operators when binary expressions wrap lines.',
56
+ choices: [
57
+ {
58
+ value: 'start',
59
+ description: 'Print operators at the start of new lines.'
60
+ },
61
62
+ value: 'end',
63
+ description: 'Print operators at the end of previous lines.'
64
+ }
65
+ ]
66
67
compiler: {
68
category: CATEGORY_SOLIDITY,
69
type: 'string',
src/slang-printers/create-binary-operation-printer.ts
@@ -15,13 +15,14 @@ const { group, line } = doc.builders;
15
function rightOperandPrint(
16
node: BinaryOperation,
17
path: AstPath<BinaryOperation>,
18
- print: PrintFunction
+ print: PrintFunction,
19
+ options: ParserOptions<AstNode>
20
): Doc {
- const rightOperand = [
21
- ` ${node.operator}`,
22
- line,
- path.call(print, 'rightOperand')
- ];
+ const rightOperand =
+ ? [` ${node.operator}`, line, path.call(print, 'rightOperand')]
+ : [line, `${node.operator} `, path.call(print, 'rightOperand')];
+
const leftOperand = node.leftOperand.variant;
@@ -58,6 +59,6 @@ export const createBinaryOperationPrinter =
return groupRules([
path.call(print, 'leftOperand'),
- indentRules(rightOperandPrint(node, path, print))
+ indentRules(rightOperandPrint(node, path, print, options))
0 commit comments