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

refactor: port parse to typescript #764

Merged
merged 6 commits into from Sep 11, 2019
Merged

refactor: port parse to typescript #764

merged 6 commits into from Sep 11, 2019

Conversation

byCedric
Copy link
Member

Description

Part of #659.

Motivation and Context

Usage examples

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@byCedric
Copy link
Member Author

@marionebl I'm not really happy adding any as the return type to @commitlint/parse. As you can see in the tests, it forces us to add other explicit any types to everything that uses the output. I'll add another commit adding basic types based on the conventional commits parser. It would definitely be a huge benefit when porting the rules to TS.

@byCedric
Copy link
Member Author

Done, let me know what you think 😄 As I said, I think it's better adding types during the port-period in this instance. If we don't do this we have to add a lot of explicit types in all packages using this, especially the rules.

@marionebl marionebl mentioned this pull request Jul 27, 2019
18 tasks
@byCedric byCedric requested a review from marionebl July 27, 2019 11:15
@commitlint/parse/package.json Outdated Show resolved Hide resolved
const message = '#1 some subject PREFIX-2';
const {references} = await parse(message, undefined, {
issuePrefixes: ['PREFIX-']
});

t.falsy(references.find(ref => ref.issue === '1'));
t.deepEqual(references.find(ref => ref.issue === '2'), {
expect(references.find(ref => ref.issue === '1')).toBeFalsy();
Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't add types to the parser output, you can't use ref => ref.issue === '1' like this. You need to add some types for this, everytime you use it. That's why I added it in the second commit. So this has to change to:

expect(references.find((ref: any) => ref.issue === '1')).toBeFalsy();

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding an optional type parameter defaulting to unknown should do the trick. Further discussion at the signature of parse

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'm not sure if I understand this fully, do you want to add a different typing to the existing references property from interface Commit? Or did you mean something else? 😄

process.cwd(),
'./fixtures/parser-preset/conventional-changelog-custom'
const changelogOpts: any = await importFrom(
__dirname,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bit weird because we are running Jest from the root of the monorepo process.cwd seems to be set to that folder. In this case, we need to scope it from within this package. This works, but not sure if this is the best solution.

Copy link
Contributor

@marionebl marionebl Jul 29, 2019

Choose a reason for hiding this comment

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

I think it is fine. We might want to use fixturez for this kind of thing to decouple test files from exact relative fixture paths. If you feel eager you could give it a try here, otherwise let's go forward as is.

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 think this is important for @commitlint/load, was doing some work on that but did not finish in time. In this instance, it might be a bit of an overkill? 😬

Copy link
Contributor

@marionebl marionebl left a comment

Choose a reason for hiding this comment

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

Great work on porting parse! I have some comments regarding types, let me know what you think.

@byCedric
Copy link
Member Author

@marionebl They look great! I'll update the PR in a moment 😄

@byCedric
Copy link
Member Author

One thing that was on my mind is the naming of the interfaces. I can imagine renaming Commit to something like ParsedCommit, I think it would emphasize a bit better where "the value/interface comes from".

Copy link
Contributor

@marionebl marionebl left a comment

Choose a reason for hiding this comment

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

One minor comment, looks very good :)

@byCedric
Copy link
Member Author

Ok, I think I processed all the comments. I still have some "random thoughts" but they are not necessary for now. Let me know what you think, I might have some time left tomorrow 😄

@byCedric
Copy link
Member Author

@marionebl Are the changes I applied after your feedback good to go? Or does it still require some additional changes? 😄

@byCedric byCedric merged commit 756a333 into master Sep 11, 2019
@byCedric byCedric deleted the refactor/parse-to-ts branch September 11, 2019 14:46
@byCedric
Copy link
Member Author

I chatted with @marionebl, it was a go 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants