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

Adopt no-callback-literal rule #178

Closed
feross opened this issue Aug 14, 2019 · 3 comments · Fixed by #179
Closed

Adopt no-callback-literal rule #178

feross opened this issue Aug 14, 2019 · 3 comments · Fixed by #179

Comments

@feross
Copy link
Contributor

feross commented Aug 14, 2019

Hi there!

I'd like to deprecate eslint-plugin-standard. We currently have four rules, three of which are no longer used by us since ESLint core now has suitable alternatives built-in.

The fourth rule is quite useful.

no-callback-literal - Ensures the Node.js error-first callback pattern is followed. Specifically, when a function is named cb or callback, then it must be called with undefined, null or an Error object as the first function argument.

// okay
cb(undefined)
cb(null, 5)
callback(new Error('some error'))
callback(someVariable)

// error
cb('this is an error string')
cb({ a: 1 })
callback(0)

We have code and tests for the implementation (https://github.com/standard/eslint-plugin-standard/blob/master/rules/no-callback-literal.js).

Ideally, we'd be able to just deprecate eslint-plugin-standard since we're currently maintaining a whole ESLint plugin just for a single rule.

So, my question is – would eslint-plugin-node like to adopt this rule? It seems like a good fit. Let me know what you think!

@feross
Copy link
Contributor Author

feross commented Aug 14, 2019

I should note that the rule has one bug that we are aware of. We falsely report an error when the spread operator is used. This is probably an easy fix.

function a (cb) {
  cb(...[new Error(''), 1, 2]) // Unexpected literal in error position of callback.
}

@mysticatea
Copy link
Owner

I'm fine if this plugin hosts that rule. But I'm not sure if plugin:node/recommended will not include the rule because of false positive.

@feross
Copy link
Contributor Author

feross commented Aug 14, 2019

@mysticatea Great! I sent a PR: #179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants