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

newline-before-return: false positive #6090

Closed
ghost opened this issue May 4, 2016 · 11 comments
Closed

newline-before-return: false positive #6090

ghost opened this issue May 4, 2016 · 11 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Comments

@ghost
Copy link

ghost commented May 4, 2016

What version of ESLint are you using?
v2.9.0

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

module.exports = {
  "extends": "eslint:recommended",
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module"
  },
  "env": {
    "browser": false,
    "es6": true,
    "node": true,
    "mocha": true
  },
  "globals": {
  },
  "rules": {
    "accessor-pairs": "error",
    "array-bracket-spacing": [
      "error",
      "never"
    ],
    "array-callback-return": "error",
    "arrow-body-style": "error",
    "arrow-parens": "error",
    "arrow-spacing": "error",
    "block-scoped-var": "error",
    "block-spacing": [
      "error",
      "never"
    ],
    "brace-style": [
      "error",
      "1tbs",
      {
        "allowSingleLine": true
      }
    ],
    "callback-return": "error",
    "comma-spacing": [
      "error",
      {
        "after": true,
        "before": false
      }
    ],
    "comma-style": [
      "error",
      "last"
    ],
    "computed-property-spacing": [
      "error",
      "never"
    ],
    "consistent-this": [
      "error",
      "self"
    ],
    "curly": "error",
    "dot-location": [
      "error",
      "property"
    ],
    "eol-last": "error",
    "eqeqeq": "error",
    "generator-star-spacing": [
      "error",
      "both"
    ],
    "global-require": "off",
    "handle-callback-err": [
      "error",
      "^(err|error|anySpecificError)$"
    ],
    "indent": "error",
    "jsx-quotes": "error",
    "key-spacing": "error",
    "keyword-spacing": "error",
    "linebreak-style": [
      "error",
      "unix"
    ],
    "new-cap": [
      "error",
      {
        "newIsCap": true,
        "capIsNew": false
      }
    ],
    "new-parens": "error",
    "newline-after-var": "error",
    "newline-before-return": "error",
    "no-array-constructor": "error",
    "no-caller": "error",
    "no-catch-shadow": "error",
    "no-cond-assign": [
      "error",
      "always"
    ],
    "no-duplicate-imports": "error",
    "no-eq-null": "error",
    "no-eval": "error",
    "no-extend-native": "error",
    "no-extra-bind": "error",
    "no-extra-label": "error",
    "no-extra-parens": [
      "error",
      "functions"
    ],
    "no-floating-decimal": "error",
    "no-implicit-coercion": "error",
    "no-implicit-globals": "error",
    "no-implied-eval": "error",
    "no-iterator": "error",
    "no-label-var": "error",
    "no-labels": "error",
    "no-lone-blocks": "error",
    "no-lonely-if": "error",
    "no-mixed-requires": "error",
    "no-multi-spaces": "error",
    "no-multi-str": "error",
    "no-multiple-empty-lines": [
      "error",
      {
        "max": 1,
        "maxEOF": 0,
        "maxBOF": 0
      }
    ],
    "no-native-reassign": "error",
    "no-nested-ternary": "error",
    "no-new": "error",
    "no-new-func": "error",
    "no-new-object": "error",
    "no-new-require": "error",
    "no-new-wrappers": "error",
    "no-octal-escape": "error",
    "no-path-concat": "error",
    "no-proto": "error",
    "no-return-assign": "error",
    "no-self-compare": "error",
    "no-sequences": "error",
    "no-shadow-restricted-names": "error",
    "no-spaced-func": "error",
    "no-sync": "error",
    "no-throw-literal": "error",
    "no-trailing-spaces": "error",
    "no-undef-init": "error",
    "no-unmodified-loop-condition": "error",
    "no-unneeded-ternary": "error",
    "no-unused-expressions": "error",
    "no-unused-vars": [
      "error",
      {
        "vars": "all",
        "args": "none"
      }
    ],
    "no-useless-call": "error",
    "no-useless-concat": "error",
    "no-useless-constructor": "error",
    "no-void": "error",
    "no-whitespace-before-property": "error",
    "no-with": "error",
    "object-curly-spacing": "error",
    "object-shorthand": "off",
    "one-var": [
      "error",
      "never"
    ],
    "one-var-declaration-per-line": "error",
    "operator-linebreak": [
        "error",
        "after"
    ],
    "padded-blocks": [
      "error",
      {
        "blocks": "never",
        "switches": "never",
        "classes": "never"
      }
    ],
    "prefer-arrow-callback": "off",
    "prefer-const": "error",
    "prefer-reflect": "off",
    "prefer-rest-params": "off",
    "prefer-spread": "off",
    "prefer-template": "off",
    "quotes": [
      "error",
      "single",
      {
        "avoidEscape": true
      }
    ],
    "radix": "error",
    "require-jsdoc": "error",
    "require-yield": "error",
    "semi": "error",
    "semi-spacing": "error",
    "space-before-blocks": "error",
    "space-before-function-paren": "error",
    "space-in-parens": "error",
    "space-infix-ops": "error",
    "space-unary-ops": [
      "error",
      {
        "words": true,
        "nonwords": false
      }
    ],
    "spaced-comment": "error",
    "template-curly-spacing": "error",
    "vars-on-top": "error",
    "wrap-iife": "error",
    "yield-star-spacing": "error",
    "yoda": "error"
  }
};

Plus .eslintrc:

{
    "extends": "isi",
    "globals": {
        "Ext": true,
        "Ext3": true,
        "Q": true,
        "Isilon": true,
        "i18n": true,
        "expect": true,
        "sinon": true,
        "breeze": true
    },
    "env": {
        "browser": true
    },
    "rules": {
        "consistent-this": [
            "error",
            "me"
        ],
        "fix-spaced-comment": [
        "error",
            "always"
        ],
    "newline-after-var": "error",
        "newline-before-return": "error",
        "no-lonely-if": "off"
    }
}

What did you do? Please include the actual source code causing the issue.

    getFolderHierarchy: function () {
        var folderHierarchy = [];
        var comboPath = this.currentLocation;

        while (comboPath.length) {
            folderHierarchy.unshift(comboPath);
            comboPath = comboPath.split('/');
            comboPath = comboPath.splice(0, comboPath.length - 1).join('/');   // remove last token
        }

        return folderHierarchy;     // <-- It errors on this line.
    }

also, here:

    determineValidity: function () {
        var validity = true;
        var andWidget;
        var j;
        var mainWidget = this.down('container[andWidgets]');
        var andWidgetLen = mainWidget.andWidgets.length;

        for (j = 0; j < andWidgetLen; j++) {
            andWidget = mainWidget.andWidgets[j];
            validity = andWidget.determineValidity();
            if (validity === false) {
                break;  // j loop
            }
        }

        return validity;  // <--- errors here
    },

What did you expect to happen?
I would expect that newline-before-return would think I had a newline before the return, as the code above shows.

What actually happened? Please include the actual, raw output from ESLint.

/static/v2/scripts/uilib/form/field/FiltersField.js
  118:9  error  Expected newline before return statement  newline-before-return

/static/v2/scripts/uilib/window/FileBrowser.js
  406:9  error  Expected newline before return statement  newline-before-return

✖ 2 problems (2 errors, 0 warnings)
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 4, 2016
@qfox qfox added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 5, 2016
@qfox
Copy link

qfox commented May 5, 2016

Here is the minimal code sample reporting this error:

a=function() {
{// dummy
}

return}

Going to fix it.

@qfox
Copy link

qfox commented May 5, 2016

It looks like a bug in espree. For some reason there is leading comment for return statement. Didn't find why there it is atm.

@platinumazure
Copy link
Member

Pinging @kaicataldo: Didn't you fix something similar to this in espree recently?

@kaicataldo
Copy link
Member

kaicataldo commented May 5, 2016

Yes - thought I had finally found a solution that covered all cases in Espree. Will take a look at this ASAP - thanks for investigating, @zxqfox!

@kaicataldo kaicataldo added the blocked This change can't be completed until another issue is resolved label May 5, 2016
@qfox
Copy link

qfox commented May 5, 2016

Thank you for finishing this ;-)

@kaicataldo
Copy link
Member

kaicataldo commented May 5, 2016

@zxqfox Actually, did you confirm that this issue occurs with Espree? I'm noticing the issue creator is using babel-eslint, which uses Babel's Babylon parser. Babylon uses essentially the same algorithm as Espree for comment attachment, and the changes I made to Espree that fix this haven't been ported over yet.

It's a known issue: babel/babel-eslint#289
And there's already an open PR to Babylon to fix it: babel/babylon#23

@qfox
Copy link

qfox commented May 5, 2016

@kaicataldo My bad. I should run npm i before investigating. With the last version of espree all is fine.

What you think about tests? Do we need them?

@kaicataldo
Copy link
Member

I added tests when I bumped the Espree version in ESLint, I'm always for more test coverage if there are cases we aren't testing already :D I don't remember there being tests for the cases in the original post - i.e. comments inside and at the end of 'while' and 'for' loops. The bug in question would happen when a block would end with a comment inside it - it would then get attached as a leading comment to the next node.

Sorry, not at my computer right now or I'd check!

@kaicataldo
Copy link
Member

@justineakehurst Would you mind checking if this happens with the default parser? If not, this is unfortunately out of our hands, but it does look like the babel-eslint is aware of the issue (see comment above)

@qfox qfox added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed accepted There is consensus among the team that this change meets the criteria for inclusion labels May 5, 2016
@kaicataldo kaicataldo removed the blocked This change can't be completed until another issue is resolved label May 5, 2016
@ghost
Copy link
Author

ghost commented May 5, 2016

@kaicataldo I confirmed that when I switch the parser to 'espree' from 'babel-eslint', the problem goes away.

@kaicataldo
Copy link
Member

@justineakehurst Thanks! I'm going to close this now for the reasons above.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants