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

no-else-return rule issue #9486

Closed
zakhar-gulchak opened this issue Oct 20, 2017 · 15 comments
Closed

no-else-return rule issue #9486

zakhar-gulchak opened this issue Oct 20, 2017 · 15 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion needs info Not enough information has been provided to triage this issue triage An ESLint team member will look at this issue soon

Comments

@zakhar-gulchak
Copy link

Tell us about your environment

  • ESLint Version: 4.9.0
  • Node Version: 8.6.0
  • npm Version: 5.4.2

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

Please show your full configuration:

Configuration
{
  "extends": [
    "airbnb"
  ],
  "globals": {
    "fetch": false
  },
  "rules": {
    "indent": ["error", 4, {"SwitchCase": 1}],
    "react/jsx-indent": ["error", 4],
    "quote-props": "off",
    "react/sort-comp": 1,
    "func-names": 1,
    "object-shorthand": 1,
    "object-curly-newline": 1,
    "arrow-parens": 1,
    "default-case": 0,
    "prefer-const": 1,
    "space-before-function-paren": 1,
    "max-len": ["warn", 100],
    "prefer-template": 1,
    "consistent-return": 1,
    "global-require": 1,
    "vars-on-top": 1,
    "function-paren-newline": 1,
    "prefer-arrow-callback": 1,
    "spaced-comment": 1,
    "prefer-destructuring": 1,
    "prefer-promise-reject-errors": 1,
    "prefer-spread": 1,
    "radix": 1,
    "dot-notation": 1,
    "one-var": 1,
    "one-var-declaration-per-line": 1,
    "operator-assignment": 1,
    "array-callback-return": 1,
    "wrap-iife": 1,
    "guard-for-in": 1,
    "strict": 1,
    "lines-around-directive": 1,
    "no-prototype-builtins": 1,
    "no-useless-concat": 1,
    "no-restricted-syntax": 1,
    "no-restricted-globals": 1,
    "no-multi-assign": 1,
    "no-confusing-arrow": ["warn", {"allowParens": true}],
    "no-use-before-define": 1,
    "no-empty": 1,
    "no-mixed-operators": 1,
    "no-var": 1,
    "no-unused-vars": 1,
    "no-unused-expressions": 1,
    "no-param-reassign": 1,
    "no-useless-return": 1,
    "no-nested-ternary": 1,
    "no-shadow": 1,
    "no-lonely-if": 1,
    "no-undef": 1,
    "no-case-declarations": 1,
    "no-underscore-dangle": 1,
    "no-plusplus": 1,
    "no-else-return": 1,
    "no-bitwise": 1,
    "class-methods-use-this": ["warn", {"exceptMethods": []}],
    "array-bracket-spacing": ["warn", "never"],
    "arrow-body-style": ["warn", "as-needed"],
    "linebreak-style": ["warn", "unix"],
    "import/extensions": [1, "never", {"js": "never", "jsx": "never"}],
    "import/no-extraneous-dependencies": 1,
    "import/no-unresolved": 1,
    "import/no-mutable-exports": 1,
    "import/first": 1,
    "import/newline-after-import": 1,
    "import/prefer-default-export": 1,
    "jsx-quotes": ["warn", "prefer-single"],
    "react/react-in-jsx-scope": 1,
    "react/jsx-indent-props": ["error", 4],
    "react/jsx-first-prop-new-line": ["warn", "multiline-multidrop"],
    "react/jsx-closing-bracket-location": ["warn", "line-aligned"],
    "react/jsx-closing-tag-location": 1,
    "react/no-string-refs": 1,
    "react/no-unused-prop-types": 1,
    "react/no-children-prop": 1,
    "react/no-find-dom-node": 1,
    "react/no-array-index": 1,
    "react/require-default-props": 1,
    "react/jsx-no-bind": 1,
    "react/jsx-curly-brace-presence": ["warn", {"props": "never", "children": "never"}],
    "react/forbid-prop-types": ["warn", {"forbid": ["any", "array", "object"]}],
    "react/no-unescaped-entities": 1,
    "react/no-unused-state": 1,
    "react/no-array-index-key": 1,
    "react/no-did-mount-set-state": 1,
    "react/no-did-update-set-state": 1,
    "react/jsx-no-target-blank": 1,
    "react/jsx-wrap-multilines": 1,
    "jsx-a11y/no-noninteractive-element-interactions": 1,
    "jsx-a11y/click-events-have-key-events": 1,
    "jsx-a11y/label-has-for": 1,
    "jsx-a11y/alt-text": 1,
    "jsx-a11y/no-static-element-interactions": 1,
    "jsx-a11y/anchor-is-valid": 1,
    "jsx-a11y/no-redundant-roles": 1,
    "jsx-a11y/scope": 1,
    "jsx-a11y/interactive-supports-focus": 1,
    "comma-dangle": 0
  }
}

What did you do? Please include the actual source code causing the issue.
Issue caused by eslint-config-airbnb-base@12.1.0
node_modules/eslint-config-airbnb-base/rules/best-practices.js:62

'no-else-return': ['error', { allowElseIf: true }],

What did you expect to happen?
Run without error

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

events.js:182
throw er; // Unhandled 'error' event
^
Error: /home/zakhargulchak/WebstormProjects/application-ngo2/node_modules/eslint-config-airbnb-base/rules/best-practices.js:
Configuration for rule "no-else-return" is invalid:
Value "[object Object]" should NOT have more than 0 items.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Oct 20, 2017
@platinumazure platinumazure added the needs info Not enough information has been provided to triage this issue label Oct 20, 2017
@eslintbot
Copy link

eslintbot commented Oct 20, 2017

Hi @zahar-g, thanks for the issue. It looks like there's not enough information for us to know how to help you.

If you're reporting a bug, please be sure to include:

1. The version of ESLint you are using (run eslint -v)
2. What you did (the source code and ESLint configuration)
3. The actual ESLint output complete with numbers
4. What you expected to happen instead

(edited by @platinumazure)

@zakhar-gulchak
Copy link
Author

zakhar-gulchak commented Oct 23, 2017

  1. what you did? source code:
    package.json:
  "scripts": {
    ...
    "lint": "gulp lint",
    ...
  },
...
    "eslint": "^4.9.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-formatter-pretty": "^1.1.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-react": "^7.4.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
...

.eslintrc

{
  "extends": [
    "airbnb"
  ],
  "globals": {
    "fetch": false
  },
  "rules": {
    "indent": ["error", 4, {"SwitchCase": 1}],
    "react/jsx-indent": ["error", 4],
    "quote-props": "off",
    "react/sort-comp": 1,
    "func-names": 1,
    "object-shorthand": [2, "properties"],
    "object-curly-newline": 1,
    "arrow-parens": [2, "always"],
    "default-case": 0,
    "prefer-const": 1,
    "space-before-function-paren": 1,
    "max-len": ["warn", 100],
    "prefer-template": 1,
    "consistent-return": 1,
    "global-require": 1,
    "vars-on-top": 1,
    "function-paren-newline": 1,
    "prefer-arrow-callback": 1,
    "spaced-comment": 1,
    "prefer-destructuring": 1,
    "prefer-promise-reject-errors": 1,
    "prefer-spread": 1,
    "radix": 1,
    "dot-notation": 1,
    "one-var": 1,
    "one-var-declaration-per-line": 1,
    "operator-assignment": 1,
    "array-callback-return": 1,
    "wrap-iife": 1,
    "guard-for-in": 1,
    "strict": 1,
    "lines-around-directive": 1,
    "no-prototype-builtins": 1,
    "no-useless-concat": 1,
    "no-restricted-syntax": 1,
    "no-restricted-globals": 1,
    "no-multi-assign": 1,
    "no-confusing-arrow": ["warn", {"allowParens": true}],
    "no-use-before-define": 1,
    "no-empty": 1,
    "no-mixed-operators": 1,
    "no-var": 1,
    "no-unused-vars": 1,
    "no-unused-expressions": 1,
    "no-param-reassign": 1,
    "no-useless-return": 1,
    "no-nested-ternary": 1,
    "no-shadow": 1,
    "no-lonely-if": 1,
    "no-undef": 1,
    "no-case-declarations": 1,
    "no-underscore-dangle": 1,
    "no-plusplus": 1,
    "no-else-return": 1,
    "no-bitwise": 1,
    "class-methods-use-this": ["warn", {"exceptMethods": []}],
    "array-bracket-spacing": ["warn", "never"],
    "arrow-body-style": ["warn", "as-needed"],
    "linebreak-style": ["warn", "unix"],
    "import/extensions": [1, "never", {"js": "never", "jsx": "never"}],
    "import/no-extraneous-dependencies": 1,
    "import/no-unresolved": 1,
    "import/no-mutable-exports": 1,
    "import/first": 1,
    "import/newline-after-import": 1,
    "import/prefer-default-export": 1,
    "jsx-quotes": ["warn", "prefer-single"],
    "react/react-in-jsx-scope": 1,
    "react/jsx-indent-props": ["error", 4],
    "react/jsx-first-prop-new-line": ["warn", "multiline-multidrop"],
    "react/jsx-closing-bracket-location": ["warn", "line-aligned"],
    "react/jsx-closing-tag-location": 1,
    "react/no-string-refs": 1,
    "react/no-unused-prop-types": 1,
    "react/no-children-prop": 1,
    "react/no-find-dom-node": 1,
    "react/no-array-index": 1,
    "react/require-default-props": 1,
    "react/jsx-no-bind": 1,
    "react/jsx-curly-brace-presence": ["warn", {"props": "never", "children": "never"}],
    "react/forbid-prop-types": ["warn", {"forbid": ["any", "array", "object"]}],
    "react/no-unescaped-entities": 1,
    "react/no-unused-state": 1,
    "react/no-array-index-key": 1,
    "react/no-did-mount-set-state": 1,
    "react/no-did-update-set-state": 1,
    "react/jsx-no-target-blank": 1,
    "react/jsx-wrap-multilines": 1,
    "react/sort-prop-types": [1, { "ignoreCase": true }],
    "jsx-a11y/no-noninteractive-element-interactions": 1,
    "jsx-a11y/click-events-have-key-events": 1,
    "jsx-a11y/label-has-for": 1,
    "jsx-a11y/alt-text": 1,
    "jsx-a11y/no-static-element-interactions": 1,
    "jsx-a11y/anchor-is-valid": 1,
    "jsx-a11y/no-redundant-roles": 1,
    "jsx-a11y/scope": 1,
    "jsx-a11y/interactive-supports-focus": 1,
    "comma-dangle": [2, "always-multiline"]
  }
}

gulp lint task

gulp.task('lint', () => {
    execSync('mkdir -p reports');
    return gulp.src([
        `${dirs.source}/scripts/**/*.js`,
        `${dirs.source}/scripts/**/*.jsx`,
        'gulpfile.js',
        '!node_modules/**',
    ])
        .pipe(eslint())
        .pipe(eslint.format('node_modules/eslint-formatter-pretty'))
        .pipe(eslint.format('checkstyle', fs.createWriteStream(`${dirs.reports}/eslint.xml`)))
        .pipe(eslint.failAfterError());
});

I'm running

npm run lint

@platinumazure
Copy link
Member

platinumazure commented Oct 23, 2017

Hi @zahar-g, we're still missing the source code-- in other words, the code was being linted which resulted in this unhandled exception.

If you're having trouble finding that (maybe you're running ESLint on a large number of files and so you don't know which file might be causing the rule to crash?), I would recommend running ESLint with the --debug flag, and then you can look at the debug output to see what was the last file that was loaded. Then you can hopefully work with that file to create a minimal reproducible example.

Until we see the source code you were trying to lint, we will be unable to help any further. Thanks for your understanding.

Never mind, I see now that this is a schema issue. Sorry about this. I'll analyze that shortly...

@platinumazure
Copy link
Member

@zahar-g Your schema looks valid according to the rule docs. Can you try running ESLint with the -v flag and see if you're actually getting a different version than you think? (It's possible that you're running an old ESLint version behind the scenes, and then it's trying to work with the airbnb config which is using rule configurations available in recent ESLint versions.)

@zakhar-gulchak
Copy link
Author

@platinumazure
I'm not sure it's related with source code. Yes, I'm checking huge amount of files, but error appears in the very begining (I believe on reading config). Please check my first comment - error mentioned

events.js:182
throw er; // Unhandled 'error' event
^
Error: /home/zakhargulchak/WebstormProjects/application-ngo2/node_modules/eslint-config-airbnb-base/rules/best-practices.js:
Configuration for rule "no-else-return" is invalid:
Value "[object Object]" should NOT have more than 0 items.

@zakhar-gulchak
Copy link
Author

With previous version of airbnb config I haven't such error.
In latest one they introduced 'no-else-return' rule at the same time it was done here.

@zakhar-gulchak
Copy link
Author

zakhar-gulchak commented Oct 23, 2017

Downgraded airbnb plugin to stable one. And updated my own .eslintrc to: (changed no-else-return rule)
/home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc

{
  "extends": [
    "airbnb"
  ],
  "globals": {
    "fetch": false
  },
  "rules": {
    "indent": ["error", 4, {"SwitchCase": 1}],
    "react/jsx-indent": ["error", 4],
    "quote-props": "off",
    "react/sort-comp": 1,
    "func-names": 1,
    "object-shorthand": [2, "properties"],
    "object-curly-newline": 1,
    "arrow-parens": [2, "always"],
    "default-case": 0,
    "prefer-const": 1,
    "space-before-function-paren": 1,
    "max-len": ["warn", 100],
    "prefer-template": 1,
    "consistent-return": 1,
    "global-require": 1,
    "vars-on-top": 1,
    "function-paren-newline": 1,
    "prefer-arrow-callback": 1,
    "spaced-comment": 1,
    "prefer-destructuring": 1,
    "prefer-promise-reject-errors": 1,
    "prefer-spread": 1,
    "radix": 1,
    "dot-notation": 1,
    "one-var": 1,
    "one-var-declaration-per-line": 1,
    "operator-assignment": 1,
    "array-callback-return": 1,
    "wrap-iife": 1,
    "guard-for-in": 1,
    "strict": 1,
    "lines-around-directive": 1,
    "no-prototype-builtins": 1,
    "no-useless-concat": 1,
    "no-restricted-syntax": 1,
    "no-restricted-globals": 1,
    "no-multi-assign": 1,
    "no-confusing-arrow": ["warn", {"allowParens": true}],
    "no-use-before-define": 1,
    "no-empty": 1,
    "no-mixed-operators": 1,
    "no-var": 1,
    "no-unused-vars": 1,
    "no-unused-expressions": 1,
    "no-param-reassign": 1,
    "no-useless-return": 1,
    "no-nested-ternary": 1,
    "no-shadow": 1,
    "no-lonely-if": 1,
    "no-undef": 1,
    "no-case-declarations": 1,
    "no-underscore-dangle": 1,
    "no-plusplus": 1,
    "no-else-return": ["error", { "allowElseIf": true }],
    "no-bitwise": 1,
    "class-methods-use-this": ["warn", {"exceptMethods": []}],
    "array-bracket-spacing": ["warn", "never"],
    "arrow-body-style": ["warn", "as-needed"],
    "linebreak-style": ["warn", "unix"],
    "import/extensions": [1, "never", {"js": "never", "jsx": "never"}],
    "import/no-extraneous-dependencies": 1,
    "import/no-unresolved": 1,
    "import/no-mutable-exports": 1,
    "import/first": 1,
    "import/newline-after-import": 1,
    "import/prefer-default-export": 1,
    "jsx-quotes": ["warn", "prefer-single"],
    "react/react-in-jsx-scope": 1,
    "react/jsx-indent-props": ["error", 4],
    "react/jsx-first-prop-new-line": ["warn", "multiline-multidrop"],
    "react/jsx-closing-bracket-location": ["warn", "line-aligned"],
    "react/jsx-closing-tag-location": 1,
    "react/no-string-refs": 1,
    "react/no-unused-prop-types": 1,
    "react/no-children-prop": 1,
    "react/no-find-dom-node": 1,
    "react/no-array-index": 1,
    "react/require-default-props": 1,
    "react/jsx-no-bind": 1,
    "react/jsx-curly-brace-presence": ["warn", {"props": "never", "children": "never"}],
    "react/forbid-prop-types": ["warn", {"forbid": ["any", "array", "object"]}],
    "react/no-unescaped-entities": 1,
    "react/no-unused-state": 1,
    "react/no-array-index-key": 1,
    "react/no-did-mount-set-state": 1,
    "react/no-did-update-set-state": 1,
    "react/jsx-no-target-blank": 1,
    "react/jsx-wrap-multilines": 1,
    "react/sort-prop-types": [1, { "ignoreCase": true }],
    "jsx-a11y/no-noninteractive-element-interactions": 1,
    "jsx-a11y/click-events-have-key-events": 1,
    "jsx-a11y/label-has-for": 1,
    "jsx-a11y/alt-text": 1,
    "jsx-a11y/no-static-element-interactions": 1,
    "jsx-a11y/anchor-is-valid": 1,
    "jsx-a11y/no-redundant-roles": 1,
    "jsx-a11y/scope": 1,
    "jsx-a11y/interactive-supports-focus": 1,
    "comma-dangle": [2, "always-multiline"]
  }
}

and got error

Error: /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc:
        Configuration for rule "no-else-return" is invalid:
        Value "[object Object]" should NOT have more than 0 items.

@zakhar-gulchak
Copy link
Author

zakhar-gulchak commented Oct 23, 2017

@platinumazure
I've ran command

eslint --debug './src/scripts/**/*.js'

Here is full output with debug

  eslint:cli Running on files +0ms
  eslint:glob-util Creating list of files to process. +0ms
  eslint:ignored-paths Looking for ignore file in /home/zakhargulchak/WebstormProjects/application-ngo2 +0ms
  eslint:ignored-paths Loaded ignore file /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintignore +0ms
  eslint:ignored-paths Adding /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintignore +0ms
  eslint:cli-engine Processing /home/zakhargulchak/WebstormProjects/application-ngo2/src/scripts/__mocks__/audience-data.js +0ms
  eslint:cli-engine Linting /home/zakhargulchak/WebstormProjects/application-ngo2/src/scripts/__mocks__/audience-data.js +0ms
  eslint:config Constructing config file hierarchy for /home/zakhargulchak/WebstormProjects/application-ngo2/src/scripts/__mocks__ +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc +1ms
  eslint:config-file Loading config file: /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc +0ms
/home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc:
        Configuration for rule "no-else-return" is invalid:
        Value "[object Object]" should NOT have more than 0 items.

Error: /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc:
        Configuration for rule "no-else-return" is invalid:
        Value "[object Object]" should NOT have more than 0 items.

    at validateRuleOptions (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-validator.js:113:15)
    at Object.keys.forEach.id (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-validator.js:153:9)
    at Array.forEach (<anonymous>)
    at validateRules (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-validator.js:152:30)
    at Object.validate (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-validator.js:230:5)
    at loadFromDisk (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-file.js:549:19)
    at Object.load (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config/config-file.js:592:20)
    at Config.getLocalConfigHierarchy (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config.js:226:44)
    at Config.getConfigHierarchy (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config.js:180:43)
    at Config.getConfigVector (/home/zakhargulchak/.nvm/versions/node/v8.6.0/lib/node_modules/eslint/lib/config.js:285:21)

@aladdin-add
Copy link
Member

I guess the rule no-else-return config got something wrong in /home/zakhargulchak/WebstormProjects/application-ngo2/.eslintrc, could you post it?

@zakhar-gulchak
Copy link
Author

@aladdin-add
Already done. Take a look above

@aladdin-add
Copy link
Member

aladdin-add commented Oct 23, 2017

I see. allowElseIf was introduced in ESLint v4.9.0, so I guess you are using <4.9. upgrade to latest should work~
refs: https://eslint.org/blog/2017/10/eslint-v4.9.0-released#enhancements

@zakhar-gulchak
Copy link
Author

@aladdin-add
It's very close to true. But even now when I've deleted globally installed (somehow?? but not on my own) eslint@4.8.0, have the same error. BUT when running

 ./node_modules/.bin/eslint --debug './src/scripts/**/*.js'

it's reading rules ok.
But gulp task not. Probably thing with gulp-eslint. :(
Think that issue can be closed, because not related to the eslint.

@zakhar-gulchak
Copy link
Author

Found problem.

├─┬ gulp-eslint@4.0.0
│ ├── eslint@4.8.0

Gulp-eslint is using own dependency. And not the latest version.

@aladdin-add
Copy link
Member

aladdin-add commented Oct 24, 2017

we have added eslint version to error output (#9071), but seems not ideal. I was wondering adding version before every eslint running.

thanks for the reporting!

@yves-s
Copy link

yves-s commented Feb 26, 2018

What did you do @zahar-g to resolve the issue? Currently gulp-eslint has a dependency to eslint@^4.0.0:

├─ gulp-eslint@4.0.2
│  ├─ eslint@^4.0.0

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 22, 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 Apr 22, 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 needs info Not enough information has been provided to triage this issue triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

5 participants