Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rules for leading spaces of binary operators #263

Merged
merged 9 commits into from
Aug 9, 2023
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ under the Developer Certificate of Origin <https://developercertificate.org/>.
- Andreas K. Berg (@akberg)
- Damien Pretet (@dpretet)
- Taichi Ishitani (@taichi-ishitani)
- Sosuke Hosokawa (@so298)
239 changes: 239 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9083,9 +9083,113 @@ In relation to Annex A of IEEE1800-2017, this rule applies to the specific
variants of `binary_operator` specified in Table 11-3.

See also:

- **style_operator_boolean** - Suggested companion rule.
- **style_operator_integer** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_arithmetic_leading_space** - Suggested companion rule. This is the rule for leading whitespace.



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

## Syntax Rule: `style_operator_arithmetic_leading_space`

### Hint

Put exactly one space before binary arithmetic operators.

### Reason

Consistent use of whitespace enhances readability by reducing visual noise.

### Pass Example (1 of 1)
```systemverilog
module M;
localparam int P2 = a + b; // Multiple spaces before `+`.

// One space before `*`.
localparam int P3 = a * b;

// One space before `**`.
localparam int P4 = a ** b;

// One space before `+`.
localparam int P5 = a + b;

// One space before `%`.
localparam int P6 = a % b;

// One space before `/`.
localparam int P7 = a / b;

// When the previous expression is (`expr`) type
localparam int P13 = (a + b) * c;
endmodule
```

### Fail Example (1 of 1)
```systemverilog
module M;
localparam int P2 = a + b; // Multiple spaces before `+`.

// No space before `*`.
localparam int P3 = a* b;

// No space before `**`.
localparam int P4 = a** b;

// No space before `+`.
localparam int P5 = a+ b;

// No space before `%`.
localparam int P6 = a% b;

// No space before `/`.
localparam int P7 = a/ b;

// Multiple spaces before `+`.
localparam int P8 = a + b;

// Multiple spaces before `*`.
localparam int P9 = a * b;

// Multiple spaces before `**`.
localparam int P10 = a ** b;

// Multiple spaces before `%`.
localparam int P11 = a % b;

// Multiple spaces before `/`.
localparam int P12 = a / b;

// When the previous expression is (`expr`) type
localparam int P13 = (a + b) * c;
endmodule
```

### Explanation

This rule checks the leading whitespace immediately following any arithmetic operator:
`+`
, `-`
, `*`
, `/`
, `%`
, and `**`.
Uses of these operators may have a single space between the
operator's symbol and the leading symbol or identifier, e.g.
`a + b`,
, or `a+b`.

In relation to Annex A of IEEE1800-2017, this rule applies to the specific
variants of `binary_operator` specified in Table 11-3.

See also:

- **style_operator_arithmetic** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_boolean_leading_space** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule.



Expand Down Expand Up @@ -9155,9 +9259,80 @@ In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_arithmetic** - Suggested companion rule.
- **style_operator_integer** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_boolean_leading_space** - Suggestions companion rule. This is the rule for leading whitespace.



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

## Syntax Rule: `style_operator_boolean_leading_space`

### Hint

Put exactly one space before binary boolean operators.

### Reason

Consistent use of whitespace enhances readability by reducing visual noise.

### Pass Example (1 of 1)
```systemverilog
module M;
localparam bit P1 = a && b; // One space before `&&`.

for (genvar i=0; i < 5; i++) begin // One space around `<`.
end
endmodule
```

### Fail Example (1 of 1)
```systemverilog
module M;
localparam bit P1 = a&&b; // No space before `&&`.

localparam bit P2 = a < b; // Multiple spaces after `<`.

for (genvar i=0; i<5; i++) begin // No space around `<`.
end
endmodule
```

### Explanation

This rule checks the whitespace immediately following any binary operator whose
operation returns a boolean:
`==`
, `!=`
, `===`
, `!==`
, `==?`
, `!=?`
, `&&`
, `||`
, `<`
, `<=`
, `>`
, `>=`
, `->`
, and `<->`.
Uses of these operators must have a single space between the operator's symbol
and the leading symbol or identifier, e.g.
`a && b`,
, `c !== d`
, or `0 < 5`.

In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_boolean** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_arithmetic_leading_space** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule.



Expand Down Expand Up @@ -9226,9 +9401,70 @@ In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_arithmetic** - Suggested companion rule.
- **style_operator_boolean** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule. This is the rule for leading whitespace.



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

## Syntax Rule: `style_operator_integer_leading_space`

### Hint

Put exactly one space before binary integer operators.

### Reason

Consistent use of whitespace enhances readability by reducing visual noise.

### Pass Example (1 of 1)
```systemverilog
module M;
localparam int P1 = a | b; // Single space around `|`.

localparam int P2 = a & aMask; // Single space before `&`.
endmodule
```

### Fail Example (1 of 1)
```systemverilog
module M;
localparam int P1 = a|b; // No space around `|`.

localparam int P2 = a & aMask; // Multiple spaces before `&`.
endmodule
```

### Explanation

This rule checks the whitespace immediately following any binary operator whose
operation returns an integer (except arithmetic operators):
`&`
, `|`
, `^`
, `^~`
, `~^`
, `>>`
, `<<`
, `>>>`
, and `<<<`.
Uses of these operators must have single space between the
operator's symbol and the leading symbol or identifier, e.g.
`1 << 5`,
, or `8'hAA | 8'h55`.

In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_integer** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_arithmetic_leading_space** - Suggested companion rule.
- **style_operator_boolean_leading_space** - Suggested companion rule.



Expand Down Expand Up @@ -11099,6 +11335,9 @@ syntaxrules.style_operator_arithmetic = true
syntaxrules.style_operator_boolean = true
syntaxrules.style_operator_integer = true
syntaxrules.style_operator_unary = true
syntaxrules.style_operator_arithmetic_leading_space = true
syntaxrules.style_operator_boolean_leading_space = true
syntaxrules.style_operator_integer_leading_space = true

syntaxrules.style_keyword_0or1space = true
syntaxrules.style_keyword_0space = true
Expand Down
3 changes: 3 additions & 0 deletions md/ruleset-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ syntaxrules.style_operator_arithmetic = true
syntaxrules.style_operator_boolean = true
syntaxrules.style_operator_integer = true
syntaxrules.style_operator_unary = true
syntaxrules.style_operator_arithmetic_leading_space = true
syntaxrules.style_operator_boolean_leading_space = true
syntaxrules.style_operator_integer_leading_space = true

syntaxrules.style_keyword_0or1space = true
syntaxrules.style_keyword_0space = true
Expand Down
2 changes: 2 additions & 0 deletions md/syntaxrules-explanation-style_operator_arithmetic.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ In relation to Annex A of IEEE1800-2017, this rule applies to the specific
variants of `binary_operator` specified in Table 11-3.

See also:

- **style_operator_boolean** - Suggested companion rule.
- **style_operator_integer** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_arithmetic_leading_space** - Suggested companion rule. This is the rule for leading whitespace.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This rule checks the leading whitespace immediately following any arithmetic operator:
`+`
, `-`
, `*`
, `/`
, `%`
, and `**`.
Uses of these operators may have a single space between the
operator's symbol and the leading symbol or identifier, e.g.
`a + b`,
, or `a+b`.

In relation to Annex A of IEEE1800-2017, this rule applies to the specific
variants of `binary_operator` specified in Table 11-3.

See also:

- **style_operator_arithmetic** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_boolean_leading_space** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule.
2 changes: 2 additions & 0 deletions md/syntaxrules-explanation-style_operator_boolean.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_arithmetic** - Suggested companion rule.
- **style_operator_integer** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_boolean_leading_space** - Suggestions companion rule. This is the rule for leading whitespace.
30 changes: 30 additions & 0 deletions md/syntaxrules-explanation-style_operator_boolean_leading_space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This rule checks the whitespace immediately following any binary operator whose
operation returns a boolean:
`==`
, `!=`
, `===`
, `!==`
, `==?`
, `!=?`
, `&&`
, `||`
, `<`
, `<=`
, `>`
, `>=`
, `->`
, and `<->`.
Uses of these operators must have a single space between the operator's symbol
and the leading symbol or identifier, e.g.
`a && b`,
, `c !== d`
, or `0 < 5`.

In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_boolean** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_arithmetic_leading_space** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule.
2 changes: 2 additions & 0 deletions md/syntaxrules-explanation-style_operator_integer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_arithmetic** - Suggested companion rule.
- **style_operator_boolean** - Suggested companion rule.
- **style_operator_unary** - Suggested companion rule.
- **style_operator_integer_leading_space** - Suggested companion rule. This is the rule for leading whitespace.
24 changes: 24 additions & 0 deletions md/syntaxrules-explanation-style_operator_integer_leading_space.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This rule checks the whitespace immediately following any binary operator whose
operation returns an integer (except arithmetic operators):
`&`
, `|`
, `^`
, `^~`
, `~^`
, `>>`
, `<<`
, `>>>`
, and `<<<`.
Uses of these operators must have single space between the
operator's symbol and the leading symbol or identifier, e.g.
`1 << 5`,
, or `8'hAA | 8'h55`.

In relation to Annex A of IEEE1800-2017, this rule applies to specific variants
of `binary_operator` and `binary_module_path_operator`.

See also:

- **style_operator_integer** - Suggested companion rule. This is the rule for trailing whitespace.
- **style_operator_arithmetic_leading_space** - Suggested companion rule.
- **style_operator_boolean_leading_space** - Suggested companion rule.
Loading