Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

False positive for "!" in disallowSpaceAfterPrefixUnaryOperators #87

Closed
Krinkle opened this issue Dec 6, 2013 · 0 comments
Closed

False positive for "!" in disallowSpaceAfterPrefixUnaryOperators #87

Krinkle opened this issue Dec 6, 2013 · 0 comments

Comments

@Krinkle
Copy link
Contributor

Krinkle commented Dec 6, 2013

Warning "Operator ! should stick to operand at example.js" keeps popping up no matter what I do to the offending line.

It looks like a false positive to me (perhaps the code doesn't account for the possibility of parenthesis to appear in that location?).

Warning:

Operator ! should stick to operand at example.js :
     2 |/*global X */
     3 |function foo( a, b ) {
     4 | if ( !( b instanceof X.Blue ) && !X.Object.isPlainObject( b ) ){
--------------^
     5 |  return;
     6 | }
>> 1 code style errors found!

example.js:

/*jshint unused:false */
/*global X */
function foo( a, b ) {
    if ( !( b instanceof X.Blue ) && !X.Object.isPlainObject( b ) ){
        return;
    }

    return a;
}

.jscs.json:

{
    "requireCurlyBraces": ["if", "else", "for", "while", "do"],
    "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return"],
    "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"]
}

I've tried removing and adding all kinds of spaces to try and see if that satisfies it, but it seems impossible without changing anything other than whitespace.

@mdevils mdevils closed this as completed in 295de4e Jan 9, 2014
wmfgerrit pushed a commit to wikimedia/oojs-core that referenced this issue May 1, 2014
jshint:
* Update to grunt-contrib-jshint v0.10.0 (jshint v2.5.0).
* Remove coding style option "noempty" (already covered by jscs).
* Remove option "regexp".
* Enable new option "freeze" (prohibits changing native prototypes).
  http://www.jshint.com/blog/new-in-jshint-oct-2013/#option-freeze
* Re-order to match http://www.jshint.com/docs/options/

jscs:
* Update to grunt-contrib-jshint v0.4.2 (jscs v1.4.0).
* Format .jscsrc file in a more spaceious way and order the
  properties less arbitrarily (using the jscs's readme order).
* Enforce more details of our coding style:
  - requireCurlyBraces: Add more keywords that should have their
    code block wrapped in curly braces.
  - requireSpaceAfterKeywords: Add more keywords that should have
    a space after them.
  - requireMultipleVarDecl: Enable the new "onevar" checker
    (like jshint's "onevar"). Introduced in jscs v1.4.0.
  - disallowTrailingComma: Enable.
  - disallowKeywordsOnNewLine: Enable for "else".
  - requireSpaceBeforeBlockStatements: Enable.
  - requireBlocksOnNewline: Enable, but only when more than 1
    statement (this still will validate shorthand like the
    following, which we make use of at the moment):

    var noop = function () { return true; };

  - requireSpacesInFunctionExpression: Remove, this is already
    covered by requireSpaceAfterKeywords and requireSpaceBeforeBlockStatements,
    which enforce:

    x.noop = function () {};
    x.Foo = function Foo() {};

  - disallowSpacesInNamedFunctionExpression: Enable for the parenthesis.
    Disallows:

    x.Foo = function Foo () {};

  - disallowSpacesInFunctionDeclaration: Enable for parenthesis.
    Disallows:

    function noop () {}

  - disallowDanglingUnderscores: Enable (like jshint's "nomen").
  - disallowSpaceAfterPrefixUnaryOperators: Add "!" back, now that the
    bug where it conflicts with requireRightStickedOperators is fixed.
    jscs-dev/node-jscs#87
  - disallowMixedSpacesAndTabs: Enable.
  - disallowYodaConditions: Enable.

qunit:
* Update to node-qunit v0.6.2 (does not ship qunitjs itself).
  (mostly minor changes)

Change-Id: If46b94ce18a7084cf6b9a2223d770ea03386815e
wmfgerrit pushed a commit to wikimedia/VisualEditor that referenced this issue May 14, 2014
jshint:
* Update to grunt-contrib-jshint v0.10.0 (jshint v2.5.0).
* Remove coding style option "noempty" (already covered by jscs).
* Remove coding style option "curly" (already covered by jscs).
* Remove option "regexp".
* Enable new option "freeze" (prohibits changing native prototypes).
  http://www.jshint.com/blog/new-in-jshint-oct-2013/#option-freeze
* Re-order to match http://www.jshint.com/docs/options/

jscs:
* Update to grunt-contrib-jshint v0.4.2 (jscs v1.4.0).
* Format .jscsrc file in a more spaceious way and order the
  properties less arbitrarily (using the jscs's readme order).
* Enforce more details of our coding style:
  - requireCurlyBraces: Add more keywords that should have their
    code block wrapped in curly braces.
  - requireSpaceAfterKeywords: Add more keywords that should have
    a space after them.
  - requireMultipleVarDecl: Enable the new "onevar" checker
    (like jshint's "onevar"). Introduced in jscs v1.4.0.
  - disallowTrailingComma: Enable.
  - disallowKeywordsOnNewLine: Enable for "else".
  - requireSpaceBeforeBlockStatements: Enable.
  - requireBlocksOnNewline: Enable, but only when more than 1
    statement (this still will validate shorthand like the
    following, which we make use of at the moment):

    var noop = function () { return true; };

  - requireSpacesInFunctionExpression: Remove, this is already
    covered by requireSpaceAfterKeywords and requireSpaceBeforeBlockStatements,
    which enforce:

    x.noop = function () {};
    x.Foo = function Foo() {};

  - disallowSpacesInNamedFunctionExpression: Enable for the parenthesis.
    Disallows:

    x.Foo = function Foo () {};

  - disallowSpacesInFunctionDeclaration: Enable for parenthesis.
    Disallows:

    function noop () {}

  - disallowDanglingUnderscores: Enable (like jshint's "nomen").
  - disallowSpaceAfterPrefixUnaryOperators: Add "!" back, now that the
    bug where it conflicts with requireRightStickedOperators is fixed.
    jscs-dev/node-jscs#87
  - disallowMixedSpacesAndTabs: Enable.
  - disallowYodaConditions: Enable.
  - disallowRightStickedOperators: Remove, this is obsolete with
    requireSpace{Before,After}BinaryOperators and fixes a bug
    where the following would be considered invalid when it shouldn't:

    +!!constructor.static.matchFunction
    // Operator + should not stick to following expression

    This is a false positive due to the tricky nature of
    disallowRightStickedOperators and for that reason this rule
    has been deprecated and scheduled for removal in jscs 2.0.0

See also If46b94ce18a7084cf and Ib731f11b1184d in oojs/core.

Change-Id: Iccf3b461b8d01023dd698771183b0ad5816993b1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant