-
Notifications
You must be signed in to change notification settings - Fork 81
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
refactor: align with eslint rules #2 #520
Conversation
Signed-off-by: fatadel <[email protected]>
Thanks @fatadel ! |
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.
Small changes, but it looks good!
@@ -344,6 +346,9 @@ export default class CoapServer implements ProtocolServer { | |||
res.write(content.body); | |||
|
|||
res.on("finish", function (err: Error) { | |||
if (err) { | |||
console.error(err); |
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.
For logging we need to use our convention, I am wondering if we can enforce it somehow with eslint 🤔
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.
What do you mean by "our convention"?
I hope you've understood that I've added that code because of this rule - https://eslint.org/docs/rules/handle-callback-err.
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.
If you take a look at our packages and the console logs you will notice that we add a prefix to the error so that we can easily detect from which binding the error came from...
e.g.,
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.
yes exactly, can you add that prefix, please? :)
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.
Aah okay, sure! I thought you mean there is some kind of convention for the way we handle callback errors.
Will be fixed now 😊
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.
I don't think so. It is used elsewhere in the file also. Or do I miss anything?
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.
I've fixed it. But a short question - won't there be a problem with referencing this?
Actually, he might be right, cause the whole code is wrapped inside function
in this case if I recall correctly this points to the function
object. @fatadel can you do a couple of tests with a small script reproducing the situation? Then we can merge this! 😃
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.
while I was here I did the test myself 😄 :
class Test {
constructor() {
this.title = "Test";
}
testMeFunction(){
setInterval( function () {
console.log("function", this.title);
}, 1000);
}
testMeArrow() {
setInterval( () => {
console.log("arrow",this.title);
}, 1000);
}
}
new Test().testMeFunction();
new Test().testMeArrow();
output:
function undefined
arrow Test
function undefined
arrow Test
function undefined
arrow Test
Consequently, I'd ask @fatadel to change function
into an arrow function :)
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.
Note: I guess we need to check other places than also...
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.
@relu91, done!
Should I also check for this
inside functions in other places or let's leave it for a separate PR?
Didn't know about this, thank you! |
Signed-off-by: fatadel <[email protected]>
Done ✅ |
Signed-off-by: fatadel <[email protected]>
Signed-off-by: fatadel <[email protected]>
c121b68
to
ca1e2a1
Compare
@relu91 do you see any more issues to be resolved? |
Signed-off-by: fatadel <[email protected]>
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.
Looks good let's move on.
The second portion of eslint alignments (previous one - #511).
Signed-off-by: fatadel [email protected]