Skip to content

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

Merged
merged 20 commits into from
Jun 26, 2019
Merged

migrate Firestore to eslint #1859

merged 20 commits into from
Jun 26, 2019

Conversation

Feiyang1
Copy link
Member

@Feiyang1 Feiyang1 commented Jun 8, 2019

No description provided.

@Feiyang1 Feiyang1 assigned mikelehen and Feiyang1 and unassigned mikelehen Jun 8, 2019
@Feiyang1 Feiyang1 changed the title migrate Firestore to eslint migrate Firestore to eslint (WIP) Jun 8, 2019
@@ -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 => {
Copy link
Contributor

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?

Copy link
Member Author

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) => {
...
}

Copy link
Contributor

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).

Copy link
Contributor

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,
Copy link
Contributor

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 :)

Copy link
Member Author

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? :)

Copy link
Contributor

@mikelehen mikelehen Jun 10, 2019

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

Copy link
Member Author

@Feiyang1 Feiyang1 Jun 11, 2019

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 :)

Copy link
Contributor

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!

Copy link
Member Author

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.

@Feiyang1 Feiyang1 changed the title migrate Firestore to eslint (WIP) migrate Firestore to eslint Jun 10, 2019
@Feiyang1 Feiyang1 force-pushed the fei-eslint-firestore branch from a44260f to 84725bc Compare June 11, 2019 18:59
@Feiyang1
Copy link
Member Author

@mikelehen gentle ping :)

@schmidt-sebastian schmidt-sebastian removed their assignment Jun 17, 2019
Copy link
Contributor

@mikelehen mikelehen left a 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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment not necessary now.

"**/test/**/*.ts"
],
"rules": {
"no-console": "off"
Copy link
Contributor

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.

Copy link
Member Author

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.

@mikelehen mikelehen assigned wilhuff and Feiyang1 and unassigned mikelehen and wilhuff Jun 18, 2019
@Feiyang1 Feiyang1 force-pushed the fei-eslint-firestore branch from 84725bc to 2204d79 Compare June 20, 2019 23:41
Copy link
Member Author

@Feiyang1 Feiyang1 left a 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.

"**/test/**/*.ts"
],
"rules": {
"no-console": "off"
Copy link
Member Author

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.

@Feiyang1 Feiyang1 assigned mikelehen and unassigned Feiyang1 Jun 21, 2019
// __expect(candidate.SDK_VERSION).to.equal(
// require('../../packages/firebase/package.json').version
// );
__expect(true).to.equal(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

@@ -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",
Copy link
Contributor

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?

Copy link
Member Author

@Feiyang1 Feiyang1 Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/platform_node/load_protos.ts#L21

This rule catches any import that's not in the right dependency list.

Yep, it won't affect the web bundle.

Copy link
Contributor

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).

Copy link
Member Author

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.

@mikelehen mikelehen assigned Feiyang1 and unassigned mikelehen Jun 21, 2019
@Feiyang1 Feiyang1 force-pushed the fei-eslint-firestore branch from d0ba151 to 2b50685 Compare June 22, 2019 00:02
@mikelehen
Copy link
Contributor

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 :)

@Feiyang1 Feiyang1 force-pushed the fei-eslint-firestore branch from 37729fb to 0f25fdf Compare June 26, 2019 00:07
@Feiyang1 Feiyang1 assigned mikelehen and unassigned Feiyang1 Jun 26, 2019
Copy link
Contributor

@mikelehen mikelehen left a 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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! removed.

@mikelehen mikelehen assigned Feiyang1 and unassigned mikelehen Jun 26, 2019
@Feiyang1 Feiyang1 merged commit 7043422 into master Jun 26, 2019
@Feiyang1 Feiyang1 deleted the fei-eslint-firestore branch June 26, 2019 18:28
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants