-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
New Rule: no-callback-literal (fixes #12) #15
Conversation
@feross I'll mess around with |
ce77777
to
113747b
Compare
@@ -10,9 +10,10 @@ ESlint Rules for the Standard Linter | |||
```js | |||
{ | |||
rules: { | |||
'standard/object-curly-even-spacing': [2, "either"] | |||
'standard/object-curly-even-spacing': [, "either"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, we should progbably use the fancy new "error"
syntax here, but yes let me fix!
Nice -- I'm running the test suite with this enable right now. Will report the output in a few minutes. |
Here's what I get when i run the tests:
Let me highlight some of the examples: // /Users/jamuferguson/dev/standard/tmp/webtorrent-desktop/src/main/external-player.js
function checkInstall (playerPath, cb) {
// check for VLC if external player has not been specified by the user
// otherwise assume the player is installed
if (playerPath == null) return vlcCommand((err) => cb(!err))
process.nextTick(() => cb(true))
} // /Users/jamuferguson/dev/standard/tmp/bonjour/lib/registry.js
function done (exists) {
mdns.removeListener('response', onresponse)
clearTimeout(timer)
cb(!!exists)
} // /Users/jamuferguson/dev/standard/tmp/yargs/test/completion.js
yargs(['--get-yargs-completions'])
.completion('completion', function (current, argv, cb) {
setTimeout(function () {
cb(['apple', 'banana'])
}, 10)
}) // /Users/jamuferguson/dev/standard/tmp/socketeer/src/SessionManager.js
next({
isOkay: true,
token: token
}) // /Users/jamuferguson/dev/standard/tmp/couchdb-push/index.js
try {
db = nanoOption(db)
} catch (e) {
return callback({ error: 'invalid_db', reason: 'Not a valid database: ' + db })
} |
Yeah, the Any legit cases that we're failing on? |
I added a few more examples to comment above. I don't know the use cases very well. Certainly, in my experience always calling back with an error object has proven to be a really good way to do it. Seems like in very specific cases people kind of throw together a custom error format (sometimes as simple as |
Here's an interesting case: ...
.on('end', function () { cb(false, lines) }) Should Other than this one case, I think most of the errors this caused could be probably rewritten to be clearer. |
Any reason why |
The
It's not better, but it's used in a few places in the clone test suite. So the question is whether to allow it or not. |
If you allow |
Not necessarily. |
Yeah I'm fine adding |
I was just exploring the idea. Maybe we should keep it just as |
|
Okay, I'm fine with |
113747b
to
fa8f7e6
Compare
Updated the rule. |
fa8f7e6
to
6142777
Compare
ACK, but meh on |
I'm also okay with |
Maybe the next step is to open an issue on the main |
Yeah for sure, I'll do that. i think it's worth a discussino to figure this Thanks On Wed, Sep 14, 2016 at 9:27 AM, Feross Aboukhadijeh <
|
6142777
to
f18d810
Compare
Okay I fixed the typo in the docs. I think this should be okay to merge if it has enough 👍 |
Nice! I think we ought to keep this PR open until we're preparing to release |
I would also prefer not allowing |
This will be part of the standard v10 beta. Sorry that this didn't make it into v9. (The release just got too big so I had to stop merging rules!) |
Just sent a PR to remove the exception for |
Take it back. This disrupts some repos and I'm already including another big change in v10, so let's hold off on this til v11. But I want to do fewer, quicker, releases, so I don't think that it will be too much longer. |
👍🏼
…On Wed, Mar 1, 2017 at 10:18 PM Feross Aboukhadijeh < ***@***.***> wrote:
Take it back. This disrupts some repos and I'm already including another
big change in v10, so let's hold off on this til v11. But I want to do
fewer, quicker, releases, so I don't think that it will be too much longer.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPBf2Ho_m4yPzwcNZHawA4uvW8osXjgks5rhl9QgaJpZM4J75rn>
.
|
I take back the take-back. Let's ship it in v10. Impact is less than I originally thought. See: standard/standard#623 (comment) |
Released as 2.1.0 |
Tries to more strictly enforce the callback pattern. This will help people avoid the common mistake of calling back with an error message instead of an error object, which can lead to all sorts of weird bugs.
There is already this similar rule in ESLint:
http://eslint.org/docs/rules/no-throw-literal
There are probably some async patterns out there that this will wreck, so we need to test it with more than just my code base :)