-
Notifications
You must be signed in to change notification settings - Fork 928
migrate Firestore to eslint #1859
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
Conversation
@@ -1116,7 +1116,7 @@ export class DocumentReference implements firestore.DocumentReference { | |||
options: ListenOptions, | |||
observer: PartialObserver<firestore.DocumentSnapshot> | |||
): Unsubscribe { | |||
let errHandler = (err: Error) => { | |||
let errHandler = (err: Error): void => { |
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.
Is there a way to turn off the return-type enforcement for very simple functions?
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.
The rule doesn't provide an option to do that currently.
An alternative is
type ErrorHandler = (err: Error) => void;
let errHandler: ErrorHandler = (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.
I vote option #1 then (leave as is in the current PR).
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.
The TSLint rule had an option to ignore arrow functions, which I was using in Messaging and Installations. If this rule has a similar option, I think it's safe to enable that.
): PersistencePromise<ProtoByteString> { | ||
return PersistencePromise.resolve(this.lastStreamToken); | ||
} | ||
|
||
setLastStreamToken( | ||
transaction: PersistenceTransaction, | ||
_transaction: PersistenceTransaction, |
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.
Can we enable after-used
? (see https://eslint.org/docs/rules/no-unused-vars#args). That would also make the Storage PR smaller, and the code prettier :)
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'd like to have _
prefixed to all unused parameters regardless of the position, because it's a nice visual cue to show it is unused, which improves the code readability.
@mikelehen Would you like to help us break the tie here? :)
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'm not in favor of after-used
since I do think it would end up with our code being inconsistent in a weird way (some unused parameters have _
and others don't, depending on the order). I want the code to be consistent.
That said, I'm on the fence of which way I want to be consistent (having underscores or no underscores for unused parameters). To be honest, scanning through the diff, I'm not sure how much it's adding. The vast majority of the violations are cases where we're just implementing a contract (an interface method or callback function) which leads to intentional "unused" parameters.
The _
makes it more visible that they're unused but VS Code actually colors unused variables differently already, so I'm not sure how much value the _
adds (and it becomes something we have to manually do / remember to undo if we use the variable).
I did notice that we had one case where the unused parameter caught by eslint was actually indicative of a coding mistake, though you missed it in your fixing. 😛 #1863
@schmidt-sebastian and @wilhuff have both gently pushed back on this (due to the noise and overloading how we use _
too much) and mostly the lint error seems to be triggering false-positives, and so I'm worried it may just be adding unnecessary visual noise to our code.
So at this point, I think I'm actually leaning towards disabling no-unused-vars
for parameters, at least in Firestore... Sorry. WDYT @Feiyang1
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 think there is value for _
even for intentional "unused" variables, that is _
makes the intention explicit.
_
is also helpful during code review since code review tools won't color unused variables differently like VSCode. Similarly It will work regardless of the IDE.
I agree it will add some cognitive and maintenance burden, and it sounds like Firestore use _
for other purpose as well, so I'm happy to disable this rule for Firestore if you think that works better for Firestore. Let me know :)
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.
Yeah, I think we want to disable it for Firestore. Thanks / sorry!
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.
Done. disabled no-unused-vars
for function params, but it still checks variables.
a44260f
to
84725bc
Compare
@mikelehen gentle ping :) |
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.
Thanks for tackling this and sorry for the super slow review... This mostly looks good, but I'm not sure why you disabled some of the lint checks in tests... I think we'll want to re-enable those and then revert a bunch of your suppression removals.
packages/firestore/src/util/error.ts
Outdated
@@ -24,7 +24,7 @@ import * as firestore from '@firebase/firestore-types'; | |||
export type Code = firestore.FirestoreErrorCode; | |||
|
|||
// TODO(mcg): Change to a string enum once we've upgraded to typescript 2.4. | |||
// tslint:disable-next-line:variable-name Intended to look like a TS 2.4 enum | |||
// Intended to look like a TS 2.4 enum |
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.
comment not necessary now.
packages/firestore/.eslintrc.json
Outdated
"**/test/**/*.ts" | ||
], | ||
"rules": { | ||
"no-console": "off" |
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.
why did you disable this? People often add console.log() statements while debugging tests and then accidentally forget to remove them.
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.
There is a few places where it seems we use console.log intentionally, so I decided to just allow it.
I will enable "no-console" for test related files and add suppression instead. If anything of them should actually be removed, let me know, then I can remove them.
84725bc
to
2204d79
Compare
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.
In addition to address comments, I also fixed issues flagged by import/no-duplicate
which was enabled after the PR was opened.
packages/firestore/.eslintrc.json
Outdated
"**/test/**/*.ts" | ||
], | ||
"rules": { | ||
"no-console": "off" |
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.
There is a few places where it seems we use console.log intentionally, so I decided to just allow it.
I will enable "no-console" for test related files and add suppression instead. If anything of them should actually be removed, let me know, then I can remove them.
integration/shared/validator.js
Outdated
// __expect(candidate.SDK_VERSION).to.equal( | ||
// require('../../packages/firebase/package.json').version | ||
// ); | ||
__expect(true).to.equal(true); |
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.
🤔
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.
😅
packages/firestore/package.json
Outdated
@@ -32,6 +32,8 @@ | |||
"@firebase/logger": "0.1.17", | |||
"@firebase/webchannel-wrapper": "0.2.21", | |||
"@grpc/proto-loader": "^0.5.0", | |||
"@firebase/util": "0.2.20", | |||
"protobufjs": "6.8.8", |
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.
Hrm. Technically I think a direct dependency on protobufjs is only needed for tests... what led you to move it?
As a sidenote: grpc and protobuf stuff are only relevant to node. I guess we rely on bundlers to drop the unused dependencies on web?
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.
This rule catches any import that's not in the right dependency list.
Yep, it won't affect the web bundle.
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 see... the actual code that uses the import is only called from tests though:
export function loadRawProtos(): ProtobufJS.Root { |
So maybe we should suppress the rule, perhaps with a TODO to try to clean things up (it's admittedly a bit hacky).
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.
Done. suppressed the rule with a comment.
d0ba151
to
2b50685
Compare
FYI- Please assign back to me when it's ready for a (hopefully) final pass... Though it looks like there's a merge conflict to resolve, so maybe do that first :) |
37729fb
to
0f25fdf
Compare
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.
LGTM with one nit (sorry!).
interface PendingTargetResponses { | ||
[targetId: string]: number; | ||
} | ||
/* eslint-enable @typescript-eslint/prefer-interface */ |
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.
leftover?
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.
Good catch! removed.
No description provided.