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

chore: run gofmt as part of workflow #118

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ jobs:
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: stable

- name: Check formatting
run: |
gofmt -w -s .
if [[ -n $(git diff --exit-code) ]]; then
echo "Go files were not formatted correctly:"
git diff
exit 1
fi

- name: Build examples
working-directory: examples/go/
Expand Down
2 changes: 1 addition & 1 deletion examples/go/package_lock_licenses/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func main() {

// Traverse the dependency tree and find its set of unique package versions,
// including the root.
versions := map[Version]*VersionResponse{Version{pl.Name, pl.Version}: new(VersionResponse)}
versions := map[Version]*VersionResponse{{pl.Name, pl.Version}: new(VersionResponse)}
toVisit := []NPMDependency{{Version: pl.Version, Dependencies: pl.Dependencies}}
for len(toVisit) > 0 {
it := toVisit[0]
Expand Down
2 changes: 1 addition & 1 deletion examples/go/package_lock_licenses_batch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func main() {

// Traverse the dependency tree and find its set of unique package versions,
// including the root.
versions := map[Version]*Result{Version{pl.Name, pl.Version}: new(Result)}
versions := map[Version]*Result{{pl.Name, pl.Version}: new(Result)}
toVisit := []NPMDependency{{Version: pl.Version, Dependencies: pl.Dependencies}}
for len(toVisit) > 0 {
it := toVisit[0]
Expand Down
18 changes: 12 additions & 6 deletions util/semver/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ func (sys System) ParseConstraint(str string) (retC *Constraint, retErr error) {
// in the packaging system. The syntax is system-independent. Trimmed of leading
// and trailing spaces, the syntax is a list of comma-separated spans inside a
// braces:
//
// {span,span,...}
//
// There are no extraneous spaces. The string "{}" is the empty set and matches
// nothing.
// Spans are formatted according to their rank:
//
// An empty span: <empty>
// A single version: 1.2.3-alpha
// A span between two versions: [1.2.3:2.3.4]
//
// In the last case, a bracket will be ( or ) if the span is open on the
// corresponding side. On the right-hand side of a span, a number (major, minor,
// patch) may be replaced with ∞ to represent a value greater than all numeric
Expand Down Expand Up @@ -178,11 +182,13 @@ func (p *constraintParser) constraint() (*Constraint, error) {
}

/*
orList = span // See value method below.
| andList
| orList '||' andList // NPM, Default only.
| orList ',' andList // Maven and NuGet only.
span = VERSION ' ' '-' ' ' VERSION // NPM, Default only. Spaces required.
orList = span // See value method below.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment got changed for the worse, but I can't figure out how to make the new formatter accept it. Oh well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😿


| andList
| orList '||' andList // NPM, Default only.
| orList ',' andList // Maven and NuGet only.

span = VERSION ' ' '-' ' ' VERSION // NPM, Default only. Spaces required.
*/
func (p *constraintParser) orList() Set {
sys := p.Constraint.sys
Expand Down Expand Up @@ -231,7 +237,6 @@ func (p *constraintParser) orList() Set {
| andList value
| andList ',' value // If comma is supported for AND.


If the value is a span, it must be the only item in the list.
See the value method below.

Expand Down Expand Up @@ -424,6 +429,7 @@ func (p *constraintParser) value() (spans []span, hyphenated, valid bool) {

/*
setRange parses a version range in Maven/NuGet syntax for constraints.

range = VERSION
| '[' VERSION ']'
| lbra opVersion ',' opVersion rbra
Expand Down
2 changes: 1 addition & 1 deletion util/semver/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (s *Set) Intersect(t Set) error {
}
if len(out) == 0 {
// An empty list means everything, so we need an explicitly empty span.
out = []span{span{rank: empty}}
out = []span{{rank: empty}}
}
var err error
s.span, err = canon(out)
Expand Down
16 changes: 8 additions & 8 deletions util/semver/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var byteType = [...]uint8{
}

var operators = []map[string]tokType{
DefaultSystem: map[string]tokType{
DefaultSystem: {
"=": tokEqual,
">": tokGreater,
">=": tokGreaterEqual,
Expand All @@ -100,7 +100,7 @@ var operators = []map[string]tokType{
"-": tokHyphen,
},

Cargo: map[string]tokType{
Cargo: {
"=": tokEqual,
">": tokGreater,
">=": tokGreaterEqual,
Expand All @@ -111,7 +111,7 @@ var operators = []map[string]tokType{
",": tokComma,
},

NPM: map[string]tokType{
NPM: {
"=": tokEqual,
">": tokGreater,
">=": tokGreaterEqual,
Expand All @@ -124,17 +124,17 @@ var operators = []map[string]tokType{
"-": tokHyphen,
},

Go: map[string]tokType{},
Go: {},

Maven: map[string]tokType{
Maven: {
",": tokComma,
},

NuGet: map[string]tokType{
NuGet: {
",": tokComma,
},

PyPI: map[string]tokType{
PyPI: {
"==": tokEqual,
">": tokGreater,
">=": tokGreaterEqual,
Expand All @@ -145,7 +145,7 @@ var operators = []map[string]tokType{
",": tokComma,
},

RubyGems: map[string]tokType{
RubyGems: {
"=": tokEqual,
">": tokGreater,
">=": tokGreaterEqual,
Expand Down
Loading