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

Missing space before keyword "function" when function is inside an array #387

Closed
capaj opened this issue Jan 15, 2016 · 3 comments

Comments

@capaj
Copy link
Contributor

commented Jan 15, 2016

this fails with: 3:23: Missing space before keyword "function".

module.exports = function (toExtend) {
  return Object.assign(toExtend, {
    queryMiddleware: [function (query, user) {
      if (user.privilege_level < 20) {
        query.where('owner').equals(user._id) // if not admin, the user can only query his documents
      }
    }]
  })
}

this has no errors:

module.exports = function (toExtend) {
  return Object.assign(toExtend, {
    queryMiddleware: [ function (query, user) {
      if (user.privilege_level < 20) {
        query.where('owner').equals(user._id) // if not admin, the user can only query his documents
      }
    }]
  })
}

So this essentially forces me to have one space at the beginning of an array. Is this a bug? I think so.

@dcousens dcousens added the bug label Jan 17, 2016

@dcousens

This comment has been minimized.

Copy link
Member

commented Jan 17, 2016

Looks like a bug.
Simplified test case:

var x = {
  y: [function () { // Missing space before keyword "function".
  }]
}

console.log(x)

Add the space before function and it works. Bug.

@kaicataldo

This comment has been minimized.

Copy link

commented Jan 28, 2016

This seems to be the intended behavior of ESLint's space-before-keywords rule: http://eslint.org/docs/rules/space-before-keywords.html

From the docs: "This rule will allow keywords to be preceded by an opening curly brace ({)." Nothing about square brackets though.

@feross

This comment has been minimized.

Copy link
Member

commented Feb 4, 2016

This issue is caused by the keyword spacing rules that we have enabled conflicting with other spacing rules that we have enabled.

Fortunately, the next version of eslint (v2) (which will ship in standard v6) has a new, better rule keyword-spacing which doesn't check conditions which are handled by other rules.

From the docs for keyword-spacing:

This rule is designed carefully to not conflict with other spacing rules. Basically this rule ignores usage of spacing at places that other rules are catching. So the following patterns are considered not problems.

This is fixed on the v6 branch and will be released as standard v6 soon.

@feross feross closed this Feb 4, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants
You can’t perform that action at this time.