ESLint Q&A
jrobeson opened this issue · 25 comments
I'm not familiar with the code base so I wanna use this as placeholder to ask some questions to guide me.
I'll use the results to submit a set of focused PRs.
What's up with this if (1) {
? https://github.com/sidorares/node-dbus/blob/master/test/utils/tester.js#L35
Is there a point to the tester.js
at all anymore? It doesn't seem pulled in from anywhere.
can't remember really.
Initially I had a lot of issues with calculating alignment correctly ( depending on the type and offset from the beginning of the message one need to skip 1 to 7 bytes ) so often had to proxy real dbus session & save output and try to deserialise it until bug is fixed. tester.js and other similar tools there are leftovers from those times (helpers to proxy & visualise & dump & reply dbus traffic )
I'll leave it for now and just fix the eslint errors. Which name do you like to use for error callback param? e
or err
?
Which name do you like to use for error callback param? e or err?
err
I realize that such things would conflict with a future use of eslint no-shadow
if you ever wanted that.
To avoid that though would require making all callback args way more specific to their args. I'd actually be inclined to make such changes in the future if that was ok.
yes, in case of nested callback prob better to use more specific name, like upstreamCallError
etc
what do you want to for unused callback params?
what do you want to for unused callback params?
can you give example?
foo.bar(function(baz, quux) {
});
Of course an unused err
should be used.
just don't have them in the function definition if not used
I'm not trying to ask silly questions. I just see the code like that so I wondered if it was on purpose or not.
I'm not trying to ask silly questions. I just see the code like that so I wondered if it was on purpose or not.
all good, they are not silly at all (sorry if my answers have this impression)
Nah, you didn't give that impression. I'm just not confident that I know what's standard here in node land just yet.
Also some of this is down to persona preference.
For example:
These `var word? cause a redeclare eslint error.
case 'x': //signed
this.align(3);
var word0 = this.readInt32();
var word1 = this.readInt32();
var data = Long.fromBits(word0, word1, false);
if (this.options.ReturnLongjs) return data;
return data.toNumber(); // convert to number (good up to 53 bits)
I could move the var declarations outside the switch
or I could scope them by adding {}
like case 'whatever': { ... }
or I could inline them into the this.read*()
. I'm not sure if I could inline all places where this is the case though.
{}
won't scope them unless changed to let
well yeah, I'd definitely have to do that. So is that what you'd prefer? I've been playing with lebab to transform the vars to lets and consts, but it wasn't useful yet while there were actual errors.
Id probably suggest to {} + let/const - this way you don't need to think about what logic is there
Can you tell me what's going on here? https://github.com/sidorares/dbus-native/blob/master/lib/marshall.js#L106 and https://github.com/sidorares/dbus-native/blob/master/lib/marshall.js#L116 . I'm not sure what's going on with this buffer
vs buf
and why buf
is there.
So here's most of what's left.
src/node-dbus/lib/dbuffer.js
118:10 error 'isHash' is defined but never used no-unused-vars
lib/marshall.js
104:37 error 'buffer' is not defined no-undef
115:7 error 'buff' is defined but never used no-unused-vars
lib/stdifaces.js
11:10 error 'respondError' is defined but never used no-unused-vars
lib/unmarshall.js
3:10 error 'isValidBoolean' is defined but never used no-unused-vars
21:10 error 'isValidObjectPath' is defined but never used no-unused-vars
So it's mostly unused functions, plus the earlier mentioned issue with buf
. I think isValidBoolean
and isValidObjectPath
should be used in the code, not sure about respondError
. I could silence them with an inline comment temporarily.
lib/marshall.js
I'm pretty sure intention is 'if we are going to serialise string or object path check input is string or Buffer. If it's buffer, convert to string'
change
Line 105 in c035936
if (Buffer.isBuffer(data)) data = data.toString();
and remove var buf
src/node-dbus/lib/dbuffer.js
remove
Line 118 in c035936
stdifaces
remove
Line 118 in c035936
unmarshall
remove
Lines 3 to 23 in c035936
K, got it. I assume you're ok with deleting respondError
too?
I see that node-mysql2 installs eslint-plugin-prettier
, but it doesn't seem used. https://github.com/sidorares/node-mysql2/blob/master/.eslintrc
I assume you're ok with deleting respondError too?
yeah, it'll be still in git history
I see that node-mysql2 installs eslint-plugin-prettier, but it doesn't seem used.
maybe we don't need it now?
PR in #182