JSCS: Operator should stick to following expression
Asked Answered
S

1

5

I keep receiving the following error, and I am unable to find documentation on what it means. I know it involves strict javascript formatting, and I was wanting to resolve it by abiding by the formating.

JSCS: Operator / should stick to following expression.

//Slow Scroll
    if ( window.addEventListener ) window.addEventListener('DOMMouseScroll', wheel, false);
    window.onmousewheel = document.onmousewheel = wheel;

    function wheel(event) {

        var delta = 0;
        if ( event.wheelDelta ) delta = event.wheelDelta / 120;
        else if ( event.detail ) delta = -event.detail / 3;

        handle ( delta );
        if ( event.preventDefault ) event.preventDefault();
        event.returnValue = false;

    }

    function handle(delta) {

        var time = 500,
        distance = 300;

        $( 'html, body' ).stop().animate(
            {
            scrollTop: $( window ).scrollTop() - ( distance * delta )
            },
        time);

    }

JSCS Settings File

{
    "disallowCommaBeforeLineBreak": null,
    "disallowDanglingUnderscores": true,
    "disallowEmptyBlocks": true,
    "disallowImplicitTypeConversion": [ "string" ],
    "disallowKeywordsOnNewLine": [ "else" ],
    "disallowKeywords": [ "with" ],
    "disallowMixedSpacesAndTabs": true,
    "disallowMultipleLineBreaks": true,
    "disallowMultipleLineStrings": true,
    "disallowMultipleVarDecl": null,
    "disallowPaddingNewlinesInBlocks": null,
    "disallowQuotedKeysInObjects": true,
    "disallowSpaceAfterBinaryOperators": true,
    "disallowSpaceAfterKeywords": [ "for", "while", "do", "switch" ],
    "disallowSpaceAfterLineComment": true,
    "disallowSpaceAfterObjectKeys": null,
    "disallowSpaceAfterPrefixUnaryOperators": true,
    "disallowSpaceBeforeBinaryOperators": null,
    "disallowSpaceBeforeBlockStatements": null,
    "disallowSpaceBeforePostfixUnaryOperators": true,
    "disallowSpacesInAnonymousFunctionExpression": {
        "beforeOpeningCurlyBrace": true
    },
    "disallowSpacesInConditionalExpression": null,
    "disallowSpacesInFunctionDeclaration": null,
    "disallowSpacesInFunctionExpression": {
        "beforeOpeningRoundBrace": true
    },
    "disallowSpacesInNamedFunctionExpression": null,
    "disallowSpacesInsideArrayBrackets": null,
    "disallowSpacesInsideObjectBrackets": null,
    "disallowSpacesInsideParentheses": null,
    "disallowTrailingComma": null,
    "disallowTrailingWhitespace": true,
    "disallowYodaConditions": true,
    "maximumLineLength": 120,
    "requireAlignedObjectValues": "skipWithFunction",
    "requireBlocksOnNewline": true,
    "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
    "requireCapitalizedConstructors": true,
    "requireCommaBeforeLineBreak": true,
    "requireCurlyBraces": [ "if", "else", "for", "while", "do", "try", "catch" ],
    "requireDotNotation": true,
    "requireKeywordsOnNewLine": null,
    "requireLineFeedAtFileEnd": true,
    "requireMultipleVarDecl": true,
    "requireOperatorBeforeLineBreak": true,
    "requirePaddingNewlinesInBlocks": true,
    "requireParenthesesAroundIIFE": true,
    "requireSpaceAfterBinaryOperators": null,
    "requireSpaceAfterKeywords": [ "if", "else", "return", "try", "catch" ],
    "requireSpaceAfterLineComment": null,
    "requireSpaceAfterObjectKeys": true,
    "requireSpaceAfterPrefixUnaryOperators": null,
    "requireSpaceBeforeBinaryOperators": true,
    "requireSpaceBeforeBlockStatements": true,
    "requireSpaceBeforePostfixUnaryOperators": null,
    "requireSpacesInAnonymousFunctionExpression": {
        "beforeOpeningRoundBrace": true
    },
    "requireSpacesInConditionalExpression": true,
    "requireSpacesInFunctionDeclaration": {
        "beforeOpeningRoundBrace": true,
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInFunctionExpression": {
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInNamedFunctionExpression": {
        "beforeOpeningRoundBrace": true,
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInsideArrayBrackets": "all",
    "requireSpacesInsideObjectBrackets": "allButNested",
    "requireSpacesInsideParentheses": "all",
    "requireTrailingComma": true,
    "safeContextKeyword": true,
    "validateIndentation": 4,
    "validateJSDoc": {
        "checkParamNames": true,
        "requireParamTypes": true
    },
    "validateLineBreaks": "LF",
    "validateQuoteMarks": true
}
Stillmann answered 29/4, 2015 at 20:19 Comment(3)
How recent is the version of JSCS you're using? From their Github page it looks like those rules have been deprecated for a long time (a year).Zoes
I'm not sure. I'm using Web Essentials 2013 with Visual Studio 2013 Premium.Stillmann
Well the latest release of JSCS came out yesterday :) I have no idea how you update that in your editor environment unfortunately.Zoes
S
10

To abide by the rule, you'll just need to rewrite event.wheelDelta / 120 and the following line so that the / sticks to the following expression: event.wheelDelta /120.

    if ( event.wheelDelta ) delta = event.wheelDelta /120;
    else if ( event.detail ) delta = -event.detail /3;

The disallowSpaceAfterBinaryOperators: true line is causing this. You can see the docs here: disallowSpaceAfterBinaryOperators.

Shearer answered 30/4, 2015 at 0:26 Comment(3)
Thanks! Do you know if there is a reason for this rule? Some of the rules seem rather fickle.Stillmann
At it's core, JSCS is for enforcing your project's style guide. That style guide is defined by you, so as to keep your code clean, consistent, and readable. While there are many presets you can use, it really boils down to what you and your team agree on/think works best for your code base. Therefore, I can't tell you really why your project/Web Essentials has this specific rule enabled (except that they apparently think it to be the best style choice). They might have that info somewhere in their docs, but I couldn't find it at a quick glance.Shearer
Thanks Nick. I'm sure the default settings weren't picked out for any significant reason outside of preference.Stillmann

© 2022 - 2024 — McMap. All rights reserved.