-
Notifications
You must be signed in to change notification settings - Fork 35
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
8.7.5: go.mod: adds official support for "replace" directive #585
8.7.5: go.mod: adds official support for "replace" directive #585
Conversation
09ae6ac
to
41fc122
Compare
lib/bibliothecary/parsers/go.rb
Outdated
GOMOD_SINGLELINE_DEP_REGEX = /^(?<category>require|exclude|replace|retract)\s+#{GOMOD_DEP_REGEX}.*$/ | ||
GOMOD_MULTILINE_START_REGEX = /^(?<category>require|exclude|replace|retract)\s+\(/ | ||
GOMOD_MULTILINE_END_REGEX = /^\)/ | ||
GOMOD_MULTILINE_DEP_REGEX = /^#{GOMOD_DEP_REGEX}.*$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go.mod directives can be either singleline (require foo v1.0.0
) or multiline (require (\n foo v1.0.0\n)
) so this PR adds more intelligent parsing for both cases.
977f38c
to
b875d32
Compare
lib/bibliothecary/parsers/go.rb
Outdated
@@ -7,8 +7,12 @@ class Go | |||
include Bibliothecary::Analyser | |||
|
|||
GPM_REGEXP = /^(.+)\s+(.+)$/ | |||
GOMOD_REGEX = /^(require\s+)?(.+)\s+(.+)$/ | |||
GOMOD_IGNORABLE_REGEX = /^(\/\/|module\s|go\s|exclude\s|replace\s|require\s+\(|\))/m | |||
GOMOD_REPLACEMENT_SEPARATOR_REGEX = / => / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure what I was looking at initially. WDYT about using the %r
syntax here to make it more clear this is a regular expression rather than...two divisions with an arrow operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it'd be clear since the var is suffixed with _REGEX
, forward-slashes are the ubiquitous delimiter for regexes and it's listed above/below the other regexes, but I'm not opposed to using a different syntax here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I'm hesitant to start mixing syntaxes in bibliothecary, so I'll just replace the whitespaces with \s
to make it more obvious
lib/bibliothecary/parsers/go.rb
Outdated
@@ -163,6 +194,34 @@ def self.map_dependencies(manifest, attr_name, dep_attr_name, version_attr_name, | |||
} | |||
end | |||
end | |||
|
|||
def self.go_mod_category_relative_dep(category, line, match) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this use named parameters instead?
lib/bibliothecary/parsers/go.rb
Outdated
current_multiline_category = match[1] | ||
elsif (match = line.match(GOMOD_SINGLELINE_DEP_REGEX)) # or, detect a singleline dep | ||
categorized_deps[match[:category]] << go_mod_category_relative_dep(match[:category], line, match) | ||
elsif (current_multiline_category && match = line.gsub(/(\/\/(.*))/, "").match(GOMOD_MULTILINE_DEP_REGEX)) # otherwise, parse the multiline dep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gsub
is for removing comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I should probably extract that into a constant too
0a78675
to
6b446e5
Compare
6b446e5
to
5394610
Compare
…esio#585) * go.mod: adds official support for "replace" directive * 8.7.5
this should fix the
replace
parsing bugs, where we currently get{name: "foo -> bar", ...}
back for deps:require
,replace
,extract
, andretract
replace
results to replace any matching deps inrequire
resultsexclude
results for now, since they're not related torequire
results