phetsims / chipper

Tools for developing and building PhET interactive simulations.
MIT License
11 stars 14 forks source link

`bad-typescript-text` custom lint rule #1224

Closed zepumph closed 2 years ago

zepumph commented 2 years ago

We would like @public, @private, and @protected to be forbidden in typescript files. I think a bad text rule just in the ts overrides section will work here.

zepumph commented 2 years ago

There were 1000 lint errors when I turned this rule on. Let's chip away at this!

jessegreenberg commented 2 years ago

What do we do for mixin/trait with this?

/* eslint-disable bad-typescript-text */

at the top of the file?

zepumph commented 2 years ago

I think just a line directive at every comment where we have those texts.

pixelzoom commented 2 years ago

Should @returns be added to this rule?

EDIT: The answer is no, because we want to be able to optionally document the return type, like in CarouselButton.ts:

/**
...
 * @returns the pointer area, null if no dilation is necessary, i.e. x === 0 && y === 0
 */
function computePointerArea( button: CarouselButton, arrowDirection: ArrowDirection, x: number, y: number ): Bounds2 | null {

EDIT: How about making @returns by itself (no additional doc) an error?

zepumph commented 2 years ago

Yes good plan. Commit coming soon.

zepumph commented 2 years ago

Alright. I liked this regex best to allow for extra doc:

/(@returns \{)|(@returns$)/

There were something like 250 lint errors. So it isn't on right now.

chrisklus commented 2 years ago

From 5/9 supplemental TypeScript meeting:

PSA delivered that this is a chip-away for everyone to work on.

For the lint rule preventing instanceof or typeof asserts, we think that most of the offending cases are likely redundant and leftover from JS, but looked at some good usages. Those should be able to pass by opting out of lint for that line.

@zepumph is going to make a commit to allow for disabling by line.

zepumph commented 2 years ago

You can now opt out of rules like // eslint-disable-line bad-typescript-text as needed. @pixelzoom mentioned multiple good reasons to allow checking instanceof or typeof assertions in TypeScript files, so we can disable that line accordingly.

samreid commented 2 years ago

You can now opt out of rules like // eslint-disable-line bad-typescript-text as needed.

Excellent, nice work @zepumph !

pixelzoom commented 2 years ago

geometric-optics and vegas are passing all bad-typescript-text. sun and scenery-phet are close, not a problem in code that I've converted. Self unassigning.

jessegreenberg commented 2 years ago

We are down to 143 of these errors. For those coming back to this issue the way to enable this rule is to uncomment https://github.com/phetsims/chipper/blob/f7e06eea7ddb40dde8a8ba010a236566f634ac0b/eslint/rules/bad-typescript-text.js#L25

and

https://github.com/phetsims/chipper/blob/f7e06eea7ddb40dde8a8ba010a236566f634ac0b/eslint/rules/bad-typescript-text.js#L42-L46

Rules blocking @public and @protected have since been enabled in master.

pixelzoom commented 2 years ago

I fixed a bunch of the @private problems in the above commits. @samreid note that the majority of these were in bending-light and circuit-construction-kit-common. See also https://github.com/phetsims/chipper/issues/1258.

pixelzoom commented 2 years ago

I've fixed most of the @private problems, with these exceptions:

@zepumph volunteered to handle these. Then @private can be turned on in bad-typescript-text.js.

pixelzoom commented 2 years ago

@private has been enabled in bad-typescript-text.js, so it's no longer relevant for ts-status. Tracking removal of @private from ts-status in https://github.com/phetsims/chipper/issues/1259.

zepumph commented 2 years ago

There are 141 usages of @returns with no extra doc afterwards, we can work on this next.

zepumph commented 2 years ago

I also was able to add @param { as bad text, since we shouldn't be providing type info via jsdoc. There are still two commented out rules:

pixelzoom commented 2 years ago

After converting a few merges in the above commits... I'm seeing mostly conversions of merge to optionize that have been "deferred", no real legitimate need to use merge. So I think we should definitely address this by adding merge to bad-typescript-text.

Here's the status of merge:

chrisklus commented 2 years ago

From 6/16/22 dev meeting:

We checked in on this issue.

zepumph commented 2 years ago

Today we decided that we want to turn on the useless assert instanceof/typeof check for all repos but scenery. Here is the current chip-away for it. Basically 2/3rds are in scenery, and javascript files will use this code for long enough that it isn't worth removing these assertions. This will involve moving this particular rule out of bad-typescript-text so that scenery can opt out of it.

zepumph commented 2 years ago

I felt the same way about kite and dot as I did for scenery, I also made the regex more specific, only testing an exact, single type check. Commit coming soon.

zepumph commented 2 years ago

Alright, no-simple-type-checking-assertions is now on, and a separate rule in which kite, dot, and scenery opt out. I ended up putting ~10 eslint-disable-lines in place because they seemed good and important.

zepumph commented 2 years ago

All that is left for this issue is to get merge out of our options in typescript.

We are down to 69 merge issues:

✖ 54 problems (54 errors, 0 warnings)

zepumph commented 2 years ago

I updated the comment above, just 54 conversions left.

zepumph commented 2 years ago

I assigned the remaining repos to responsible devs

pixelzoom commented 2 years ago

In the above commits, I replaced so more occurrences of merge in sun. The remaining cases are more involved.

samreid commented 2 years ago

Here's a chip-away report of the remaining parts:

jonathanolson commented 2 years ago

Handled all merges in density-buoyancy-common.

samreid commented 2 years ago

Updated chip-away result:

Results from chipAway:

samreid commented 2 years ago

We have good progress on this issue. Everything seems complete except:

zepumph commented 2 years ago

@pixelzoom or @jbphet, I went for the ButtonModel usages, can you please review my commit https://github.com/phetsims/sun/commit/0d543c76d7256e1cfc3694ff45c1be3fe9716f93

pixelzoom commented 2 years ago

https://github.com/phetsims/sun/commit/0d543c76d7256e1cfc3694ff45c1be3fe9716f93 looks good to me.

pixelzoom commented 2 years ago

Back to @zepumph because I'm not sure where this issue is at.

zepumph commented 2 years ago

All that is left is ~20 usages of merge in greenhouse.

jbphet commented 2 years ago

The greenhouse-effect usages have now all been addressed, and I've turned the rule on. I think we can close this!