Skip to content
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

Increase type safety #89

Merged
merged 6 commits into from
Apr 20, 2022
Merged

Increase type safety #89

merged 6 commits into from
Apr 20, 2022

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Apr 12, 2022

What Changed

Added some types and removed obsolete "any" type assertions by replacing them through stronger types

Change Type

Indicate the type of change your pull request is:

  • maintenance
  • documentation
  • patch
  • minor
  • major
📦 Published PR as canary version: 0.5.11--canary.89.28723b8.0

✨ Test out this PR locally via:

npm install eslint-plugin-storybook@0.5.11--canary.89.28723b8.0
# or 
yarn add eslint-plugin-storybook@0.5.11--canary.89.28723b8.0

@yannbf
Copy link
Member

yannbf commented Apr 15, 2022

Hey @valentinpalkovic thank you so much for this contribution, I love this!!

There are still a couple issues in this PR, could you check them? It happens when running yarn update-all:

yarn update-all
yarn run v1.22.17
$ yarn update-configs && yarn update-docs
$ ts-node ./tools/update-configs
/Users/yannbraga/open-source/eslint-plugin-storybook/node_modules/ts-node/src/index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError:  Unable to compile TypeScript:
tools/update-configs.ts:8:28 - error TS7016: Could not find a declaration file for module '../.prettierrc'. '/Users/yannbraga/open-source/eslint-plugin-storybook/.prettierrc.js' implicitly has an 'any' type.

8 import prettierConfig from '../.prettierrc'
                             ~~~~~~~~~~~~~~~~
tools/update-configs.ts:10:16 - error TS2665: Invalid module name in augmentation. Module '../.prettierrc' resolves to an untyped module at '/Users/yannbraga/open-source/eslint-plugin-storybook/.prettierrc.js', which cannot be augmented.

10 declare module '../.prettierrc' {}
                  ~~~~~~~~~~~~~~~~
tools/update-configs.ts:27:7 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ 'import/no-anonymous-default-export': string; }'.
  No index signature with a parameter of type 'string' was found on type '{ 'import/no-anonymous-default-export': string; }'.

27       setting[rule.ruleId] = rule.meta.docs.recommended || 'error'
         ~~~~~~~~~~~~~~~~~~~~
tools/update-configs.ts:43:29 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ csf: null; recommended: null; 'csf-strict': string; }'.
  No index signature with a parameter of type 'string' was found on type '{ csf: null; recommended: null; 'csf-strict': string; }'.

43   const extendsCategoryId = extendsCategories[category.categoryId]

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Also, would you like to edit your author email from your commit? Seems as if it's not set and I think this might end up not adding you as a contributor to this project as a result.

@valentinpalkovic
Copy link
Contributor Author

Hey @yannbf

I will take care of it directly after The Easter holidays. :) Have a nice holiday time!

@yannbf yannbf added the patch Increment the patch version when merged label Apr 15, 2022
@yannbf
Copy link
Member

yannbf commented Apr 15, 2022

Hey @yannbf

I will take care of it directly after The Easter holidays. :) Have a nice holiday time!

Thank you so much! I wish you an incredible holiday!!

Added some types and removed obosolete any type assertions
It seems, that ts-node does a different kind of type checking than executing
`tsc --noEmit`. While the first one outputs errors, the second one doesn't.
Therefore, the type checking will be disabled while executing ts-node,
but a further step in `yarn test:ci` is introduced to check the types explicitly.
@valentinpalkovic
Copy link
Contributor Author

valentinpalkovic commented Apr 19, 2022

@yannbf Please take another look.

It seems that ts-node does a different kind of type checking in the background than tsc --noEmit does. It complains about strict-mode specific restrictions, although it shouldn't complain. Therefore, I have disabled type-checking for ts-node and introduced a further step in the CI pipeline to check Typescript types explicitly via tsc (fa20d86)

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Thank you so much for making these changes @valentinpalkovic ! I added a couple more comments. Kinda interesting to know about ts-node, I think I might be experiencing a similar issue in another project for something completely different!

lib/rules/use-storybook-expect.ts Outdated Show resolved Hide resolved
lib/rules/prefer-pascal-case.ts Outdated Show resolved Hide resolved
tools/update-rules-list.ts Show resolved Hide resolved
lib/utils/index.ts Show resolved Hide resolved
@yannbf yannbf added the linear label Apr 19, 2022
@valentinpalkovic
Copy link
Contributor Author

@yannbf Could you take another look? :)

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Hey @valentinpalkovic sorry for the delay, I've been sick.

It all looks really good, thank you so much for improving this codebase! Now it's much better for new contributors and I'm sure they'll all appreciate your work. Cheers!

@valentinpalkovic
Copy link
Contributor Author

Hey @yannbf thank you for the review!

If everything looks fine, should I merge it? :) I'm just asking because normally I haven't triggered any merges in storybookjs repos so far and I want to make sure if it is ok to do so.

@yannbf
Copy link
Member

yannbf commented Apr 20, 2022

Hey @yannbf thank you for the review!

If everything looks fine, should I merge it? :) I'm just asking because normally I haven't triggered any merges in storybookjs repos so far and I want to make sure if it is ok to do so.

Sure, go ahead!

@valentinpalkovic valentinpalkovic merged commit e6ad0d8 into main Apr 20, 2022
@valentinpalkovic valentinpalkovic deleted the increase-type-safety branch April 20, 2022 20:11
@github-actions
Copy link

🚀 PR was released in v0.5.11 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear patch Increment the patch version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants