gajus / eslint-plugin-flowtype

Flow type linting rules for ESLint.
Other
1.08k stars 153 forks source link

Issues with generics and spacing #518

Closed hsimah closed 2 years ago

hsimah commented 2 years ago

Hello - thanks for the plugin. I know Flow is not as geared to developers as TS, so being able to use it at home with some success is great.

I have noticed two issues around type parameters:

  1. Function type parameters get spaces
  2. Utility functions such as $NonMaybeType

My .eslintrc image

Issue 1

When using a React state hook I want to explicitly type the state property useState<?string>(null). This is being formatted as useState < ?string > (null); by the plugin. This causes no linting warnings or errors based on recommended settings. image

Issue 2

When using $NonMaybeType with indexed types I get a trailing space added $NonMaybeType<SomeType['someNestedArray'][0]> comes out like $NonMaybeType<SomeType['someNestedArray'][0] >. This now throws a linting warning (recommended settings) that the generic parameter should not have trailing spaces. image

I would love to contribute, if I have time to take a look. Let me know if this is expected behaviour.

hsimah commented 2 years ago

I had a bit of a play with it and it looks like we would want to use the TypeParameterInstantiation to get any type params on a call expression and check the parent/callee.

I made a first pass you can check out here. Most of the tests are failing and there are a bunch of ironic linting errors. I haven't worked on the always option yet, just the never.

hsimah commented 2 years ago

I did some more work on this - [see my local PR)[https://github.com/hsimah/eslint-plugin-flowtype/pull/1]. It seems okay to fix the spacing both inside and outside the type parameters. I wrote comprehensive tests, which are failing. I'm going to move onto other things so if you want to work together to sort this out.

hsimah commented 2 years ago

After talking with some colleagues I'm going to use https://github.com/flow-typed/eslint-plugin-ft-flow instead as it's the official team release.