Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSCS: Operator should stick to following expression

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
}
like image 705
Joseph Casey Avatar asked Apr 29 '15 20:04

Joseph Casey


1 Answers

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.

like image 51
Nick Bartlett Avatar answered Nov 07 '22 19:11

Nick Bartlett