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
}
Community
  • 1
  • 1
Joseph Casey
  • 1,283
  • 1
  • 14
  • 34
  • 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). – Pointy Apr 29 '15 at 20:23
  • I'm not sure. I'm using Web Essentials 2013 with Visual Studio 2013 Premium. – Joseph Casey Apr 29 '15 at 20:26
  • 1
    Well the latest release of JSCS came out yesterday :) I have no idea how you update that in your editor environment unfortunately. – Pointy Apr 29 '15 at 20:30

1 Answers1

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.

Nick Bartlett
  • 4,865
  • 2
  • 24
  • 37
  • Thanks! Do you know if there is a reason for this rule? Some of the rules seem rather fickle. – Joseph Casey Apr 30 '15 at 03:55
  • 1
    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](http://jscs.info/overview.html#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. – Nick Bartlett Apr 30 '15 at 12:46
  • Thanks Nick. I'm sure the default settings weren't picked out for any significant reason outside of preference. – Joseph Casey Apr 30 '15 at 14:08