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

Make operator_usage_whitespace Rule Configurable #1013

Closed
ghost opened this issue Dec 21, 2016 · 7 comments
Closed

Make operator_usage_whitespace Rule Configurable #1013

ghost opened this issue Dec 21, 2016 · 7 comments
Labels
enhancement Ideas for improvements of existing features and rules. wontfix Issues that became stale and were auto-closed by a bot.

Comments

@ghost
Copy link

ghost commented Dec 21, 2016

It would be nice to make operator_usage_whitespace rule configurable so that you can include or exclude specific operators.

As an example, I prefer to vertically align my assignments and therefore would like to exclude the = operator. But I would like to keep all of my arithmetic nicely spaced and continue to be linted.

@marcelofabri marcelofabri added the enhancement Ideas for improvements of existing features and rules. label Dec 21, 2016
@peterprokop
Copy link

We really need this for exactly the same reason (= operator)

@jpsim
Copy link
Collaborator

jpsim commented May 23, 2017

I'd rather just see SwiftLint support vertically aligning operators instead.

@cennydavidsson
Copy link

I would like to config so it accepts the formatting that can be found in Clean Code by Uncle Bob about precedence of operators.

Another use for white space is to accentuate the precedence of operators.

public class Quadratic {
  private static double determinant(double a, double b, double c) { 
    return b*b - 4*a*c;
  } 
}

Notice how nicely the equations read. The factors have no white space between them because they are high precedence. The terms are separated by white space because addi- tion and subtraction are lower precedence.

@jpsim
Copy link
Collaborator

jpsim commented Apr 7, 2019

@cennydavidsson I agree that case reads more nicely than a single spaces. What about this case can we detect and make an exception for, without also losing some of the valuable violations that the rule would currently catch?

For example, longer variable names would reduce the readability of that code:

return b*b - 4*a*c
// vs
return variableB*variableB - 4*variableA*variableC

@cennydavidsson
Copy link

@jpsim I'm not sure I understand what you are asking.

I would like to configure the rule to have no whitespace for operators * and / basically. If we can do this then this rule can be more flexible. I don't see any downside with this feature as it is just additive.

operator_usage_whitespace:
  no_white_space: 
    - "*"
    - "/"

@jpsim
Copy link
Collaborator

jpsim commented Apr 29, 2019

I was saying that return variableB*variableB - 4*variableA*variableC becomes less readable, so I'm asking what heuristics are you suggesting we apply so that avoid cases like these? Or are you saying that it would be up to the user to configure the rule based on their preferences regardless of if it applies well in all cases?

@stale
Copy link

stale bot commented Nov 8, 2020

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Nov 8, 2020
@stale stale bot closed this as completed Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules. wontfix Issues that became stale and were auto-closed by a bot.
Projects
None yet
Development

No branches or pull requests

4 participants