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

Allow non capturing groups #9

Merged
merged 1 commit into from
Jan 21, 2022
Merged

Conversation

tomfeigin
Copy link
Contributor

@tomfeigin tomfeigin commented Jan 6, 2022

Fix the flags parsing to accept regexes with non capturing groups

Changes

  • 🐛 Fix bug

/kind bug

Fixes #8
Regexs with non-capturing groups didn't work

Release Note


Docs


Copy link
Owner

@julz julz left a comment

Choose a reason for hiding this comment

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

thanks so much for the contribution!

flags.go Outdated
return errors.New("import flag must be of form path:alias")
}

v[spl[0]] = spl[1]
v[strings.Join(spl[:len(spl)-1], ":")] = spl[len(spl)-1]
Copy link
Owner

Choose a reason for hiding this comment

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

would it work to use strings.LastIndex here to avoid the join? something like:

i := strings.LastIndex(val, ":")
if i < 1 {
  return errors.New("import flag must be of form path:alias")
}
v[val[:i]] = val[i+1:]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

@tomfeigin
Copy link
Contributor Author

@julz anything I can do for this PR to be merged?

Copy link
Owner

@julz julz left a comment

Choose a reason for hiding this comment

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

oops! huge apologies @tomfeigin - this got completely lost in my GitHub notifications 😬

analyzer_test.go Outdated

a := makeAnalyzer()
flg := a.Flags.Lookup("alias")
assert.EqualError(t, flg.Value.Set(""), errWrongAlias.Error())
Copy link
Owner

Choose a reason for hiding this comment

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

could we avoid adding a dependency on testify here? I think just asserting that we get an error might be fine for this test

analyzer_test.go Outdated
}

t.Run("wrong usage", func(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

I'd either move this test to its own top-level function (e.g. TestIncorrectFlags), or add it to the existing table in this test (e.g. by adding an expectAliasFlagErr field to the rows). I'd also personally be fine if we exported the stringMap type and relied on a unit test (without constructing an analyser) for that to test this case.

Copy link
Owner

@julz julz left a comment

Choose a reason for hiding this comment

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

looks good to me, thanks! Just a couple tiny nits 🙏

analyzer_test.go Outdated
}

func TestIncorrectFlags(t *testing.T) {
t.Run("wrong usage", func(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

don't need the t.Run since there's only one test here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

your'e right

analyzer_test.go Outdated
t.Run("wrong usage", func(t *testing.T) {
t.Parallel()

assertWrongAliseErr := func(msg string, err error) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
assertWrongAliseErr := func(msg string, err error) {
assertWrongAliasErr := func(msg string, err error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops

Fix the flags parsing to accept regexes with non capturing groups

Signed-off-by: Tom <[email protected]>
@julz julz merged commit e921838 into julz:main Jan 21, 2022
@julz
Copy link
Owner

julz commented Jan 21, 2022

Thanks @tomfeigin!

@tomfeigin tomfeigin deleted the allow-non-capturing-groups branch January 21, 2022 11:59
@franklinkim
Copy link

hi, would you please be so kind as to make a new release including this. thx

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

Successfully merging this pull request may close these issues.

Can't use non capturing group in the alias
3 participants