question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fat arrow + implicit return, no-return-assign bug

See original GitHub issue

array.filter(a => a.test = value) does not trigger an error with no-return-assign activated.

eslint version : v1.10.3

.eslintrc.js

module.exports = {
    "ecmaFeatures": {
        "modules": true,
        "experimentalObjectRestSpread": true,
        "jsx": true
    },
    "env": {
        "browser": true,
        "es6": true,
        "node": true
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "accessor-pairs": 2,
        "arrow-spacing": [2, { "before": true, "after": true }],
        "block-spacing": [2, "always"],
        "brace-style": [2, "1tbs", { "allowSingleLine": true }],
        "comma-dangle": [2, "never"],
        "comma-spacing": [2, { "before": false, "after": true }],
        "comma-style": [2, "last"],
        "constructor-super": 2,
        "curly": [2, "multi-line"],
        "dot-location": [2, "property"],
        "eol-last": 2,
        "eqeqeq": [1, "allow-null"],
        "generator-star-spacing": [2, { "before": true, "after": true }],
        "handle-callback-err": [2, "^(err|error)$" ],
        "indent": 2,
        "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
        "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
        "new-parens": 2,
        "no-array-constructor": 2,
        "no-caller": 2,
        "no-class-assign": 2,
        "no-cond-assign": 2,
        "no-const-assign": 2,
        "no-control-regex": 0,
        "no-debugger": 2,
        "no-delete-var": 2,
        "no-dupe-args": 2,
        "no-dupe-class-members": 2,
        "no-dupe-keys": 2,
        "no-duplicate-case": 2,
        "no-empty-character-class": 2,
        "no-empty-label": 2,
        "no-eval": 2,
        "no-ex-assign": 2,
        "no-extend-native": 2,
        "no-extra-bind": 2,
        "no-extra-boolean-cast": 2,
        "no-extra-parens": [2, "functions"],
        "no-fallthrough": 2,
        "no-floating-decimal": 2,
        "no-func-assign": 2,
        "no-implied-eval": 2,
        "no-inner-declarations": [2, "functions"],
        "no-invalid-regexp": 2,
        "no-irregular-whitespace": 2,
        "no-iterator": 2,
        "no-label-var": 2,
        "no-labels": 2,
        "no-lone-blocks": 2,
        "no-mixed-spaces-and-tabs": [2, "smart-tabs"],
        "no-multi-spaces": 2,
        "no-multi-str": 2,
        "no-multiple-empty-lines": [2, { "max": 1 }],
        "no-native-reassign": 2,
        "no-negated-in-lhs": 2,
        "no-new": 2,
        "no-new-func": 2,
        "no-new-object": 2,
        "no-new-require": 2,
        "no-new-wrappers": 2,
        "no-obj-calls": 2,
        "no-octal": 2,
        "no-octal-escape": 2,
        "no-proto": 2,
        "no-redeclare": 2,
        "no-regex-spaces": 2,
        "no-return-assign": 2,
        "no-self-compare": 2,
        "no-sequences": 2,
        "no-shadow-restricted-names": 2,
        "no-spaced-func": 2,
        "no-sparse-arrays": 2,
        "no-this-before-super": 2,
        "no-throw-literal": 2,
        "no-trailing-spaces": 2,
        "no-undef": 2,
        "no-undef-init": 2,
        "no-unexpected-multiline": 2,
        "no-unneeded-ternary": [2, { "defaultAssignment": false }],
        "no-unreachable": 2,
        "no-unused-vars": [2, { "vars": "all", "args": "none" }],
        "no-useless-call": 2,
        "no-with": 2,
        "one-var": [2, { "initialized": "never" }],
        "operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
        "padded-blocks": [2, "never"],
        "quotes": [2, "double", "avoid-escape"],
        "radix": 2,
        "semi": [2, "never"],
        "semi-spacing": [2, { "before": false, "after": true }],
        "space-after-keywords": [2, "always"],
        "space-before-blocks": [2, "always"],
        "space-before-function-paren": [2, "always"],
        "space-before-keywords": [2, "always"],
        "space-in-parens": 0,
        "space-infix-ops": 2,
        "space-return-throw-case": 2,
        "space-unary-ops": [2, { "words": true, "nonwords": false }],
        "spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
        "use-isnan": 2,
        "valid-typeof": 2,
        "wrap-iife": [2, "any"],
        "yoda": [2, "never"],
        "react/display-name": 0,
        "react/forbid-prop-types": [1, {"forbid": ["any", "array"]}],
        "react/jsx-boolean-value": 0,
        "react/jsx-closing-bracket-location": 2,
        "react/jsx-curly-spacing": [2, "never"],
        "react/jsx-handler-names": 1,
        "react/jsx-indent-props": [2, 4],
        "react/jsx-key": 0,
        "react/jsx-max-props-per-line": 0,
        "react/jsx-no-bind": 1,
        "react/jsx-no-duplicate-props": 1,
        "react/jsx-no-literals": 0,
        "react/jsx-no-undef": 1,
        "react/jsx-pascal-case": 1,
        "react/jsx-quotes": 1,
        "react/jsx-sort-prop-types": 0,
        "react/jsx-sort-props": 0,
        "react/jsx-uses-react": 2,
        "react/jsx-uses-vars": 1,
        "react/no-danger": 0,
        "react/no-did-mount-set-state": 1,
        "react/no-did-update-set-state": 1,
        "react/no-direct-mutation-state": 1,
        "react/no-multi-comp": 0,
        "react/no-set-state": 0,
        "react/no-unknown-property": 1,
        "react/prefer-es6-class": 0,
        "react/prop-types": 1,
        "react/react-in-jsx-scope": 1,
        "react/require-extension": 1,
        "react/self-closing-comp": 1,
        "react/sort-comp": 1,
        "react/wrap-multilines": 1
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
pvdzcommented, Apr 7, 2016

Food for thought?

arr.forEach(obj => obj.foo = i);

now must be

arr.forEach(obj => (obj.foo = i));

to satisfy this rule with the paren exception, or

arr.forEach(obj => { obj.foo = i; });

with the strict rule in place. Unless you disable the rule altogether, of course.

The counter case is:

arr.filter(obj => obj.foo = i);

but the distinction between a forEach and filter (etc) is only checkable under certain assumptions, with hard edge cases.

Still, the initial case had me scratching my head and led me here.

0reactions
nzakascommented, Dec 21, 2015

Now it is

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions cannot guess what or when you want to return. ... You can also assign the arrow function to a variable so...
Read more >
Arrow function with return assignment not working even with ...
To clarify. I am trying to filter out elements of an array which attribute members is different than 3 , and also I...
Read more >
Arrow Functions in JavaScript: Fat & Concise Syntax - SitePoint
Learn how to use JavaScript arrow functions, understand fat and ... Also, as you're using curly braces, an implicit return is not an...
Read more >
arrow-body-style - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
JavaScript Arrow Functions: How, Why, and Why Not?
Because arrow functions use curly brackets, {} you cannot implicitly return an object. To return an object using an arrow function, you must ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found