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

Rule for +/- (prefix) unary operator #280

Closed
kevinresol opened this issue Sep 2, 2016 · 2 comments
Closed

Rule for +/- (prefix) unary operator #280

kevinresol opened this issue Sep 2, 2016 · 2 comments
Assignees

Comments

@kevinresol
Copy link

kevinresol commented Sep 2, 2016

Mainly for negative numbers such as -1. It should be differentiated from the arithmetic operator which is a binary operator.

{
    "type": "OperatorWhitespace",
    "props": {
        "severity": "WARNING",
        "assignOpPolicy": "around",
        "unaryOpPolicy": "none",
        "ternaryOpPolicy": "around",
        "arithmeticOpPolicy": "around",
        "compareOpPolicy": "around",
        "bitwiseOpPolicy": "around",
        "boolOpPolicy": "around",
        "intervalOpPolicy": "none",
        "arrowPolicy": "around",
        "functionArgPolicy": "none"
    }
}
@AlexHaxe
Copy link
Member

AlexHaxe commented Sep 3, 2016

Negative numbers are constants with a negative value, so OperatorWhitespace does not apply.
It also skips negative prefixes of variables / expressions, because technically those would show up as arithmetic operators, but applying arithmeticOpPolicy doesn't make sense for them.

It's possible to expand unaryOpPolicy to work on those prefixes, but that would only enforce "inner" spacing.

@kevinresol
Copy link
Author

kevinresol commented Sep 3, 2016

Well maybe this is a bug then:

class Main {
  static function main() {
    switch int() {
      case -1:
      default:
    }
  }
  static function int() return 123;
}
{
    "type": "OperatorWhitespace",
    "props": {
        "severity": "WARNING",
        "assignOpPolicy": "around",
        "unaryOpPolicy": "none",
        "ternaryOpPolicy": "around",
        "arithmeticOpPolicy": "around",
        "compareOpPolicy": "around",
        "bitwiseOpPolicy": "around",
        "boolOpPolicy": "around",
        "intervalOpPolicy": "none",
        "arrowPolicy": "around",
        "functionArgPolicy": "none"
    }
}

src/Main.hx:4: characters 11-12 : Warning: OperatorWhitespace policy "around" violated by "-"

AlexHaxe added a commit to AlexHaxe/haxe-checkstyle that referenced this issue Sep 3, 2016
@AlexHaxe AlexHaxe added the bug label Sep 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants