Skip to content

Commit

Permalink
option to block all replace
Browse files Browse the repository at this point in the history
In addition to the existing block.local_replace_directives, this change
allows checking for the addition of any replace clauses.
  • Loading branch information
carnott-snap committed Mar 4, 2021
1 parent 1fc898b commit 21aae6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d h1:CdDQnGF8Nq9oc
github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
7 changes: 7 additions & 0 deletions gomodguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ type Blocked struct {
Modules BlockedModules `yaml:"modules"`
Versions BlockedVersions `yaml:"versions"`
LocalReplaceDirectives bool `yaml:"local_replace_directives"`
Replace bool `yaml:"replace"`
}

// Configuration of gomodguard allow and block lists.
Expand Down Expand Up @@ -405,6 +406,12 @@ func (p *Processor) SetBlockedModules() { //nolint:gocognit
}
}

if p.Config.Blocked.Replace {
for _, r := range p.Modfile.Replace {
p.Result = append(p.Result, Result{FileName: p.Modfile.Syntax.Name, LineNumber: r.Syntax.Start.Line, Reason: "replace directive not allowed"})
}
}

// Replace directives with local paths are blocked.
// Filesystem paths found in "replace" directives are represented by a path with an empty version.
// https://github.com/golang/mod/blob/bc388b264a244501debfb9caea700c6dcaff10e2/module/module.go#L122-L124
Expand Down

0 comments on commit 21aae6d

Please sign in to comment.