Exclude - palantir/godel GitHub Wiki
Summary
The exclude block in godel/config/godel.yml specifies patterns for paths and names that should be ignored.
Tutorial start state
${GOPATH}/src/${PROJECT_PATH}exists, is the working directory and is initialized as a Git repository and Go module- Project contains
godelandgodelw - Project contains
main.go - Project contains
.gitignorethat ignores GoLand files - Project contains
echo/echo.go,echo/echo_test.goandecho/echoer.go godel/config/dist-plugin.ymlis configured to buildechgo2- Project is tagged as 0.0.1
godel/config/dist-plugin.ymlis configured to create distributions forechgo- Project is tagged as 0.0.2
dockerctxdirectory exists andgodel/config/dist-plugin.ymlis configured to build Docker images for the product- Go files have license headers
godel/config/godel.ymlis configured to add the go-generate plugingodel/config/generate-plugin.ymlis configured to generate string function
Exclude names/paths
In the previous step of the tutorial, we updated the exclude section of godel/config/godel.yml configuration file to
specify that a generated source file should be excluded from checks. This portion of the tutorial examines the file in
more detail.
Examine the current state of godel/config/godel.yml:
➜ cat godel/config/godel.yml
plugins:
resolvers:
- "https://github.com/{{index GroupParts 1}}/{{index GroupParts 2}}/releases/download/v{{Version}}/{{Product}}-{{Version}}-{{OS}}-{{Arch}}.tgz"
plugins:
- locator:
id: "com.palantir.godel-generate-plugin:generate-plugin:1.2.0"
exclude:
names:
- "\\..+"
- "vendor"
paths:
- "godel"
- "echo/type_string.go"
As seen in the previous section, specifying echo/type_string.go as an exclude path caused this file to be ignored for
all checks and operations. However, listing individual paths like this can be cumbersome and fragile -- for example, if
we wanted to use stringer for other types or in other packages, this approach would require us to manually add each
new entry.
We can make this approach more general by excluding all files that end in _string.go instead. Run the following to
update the configuration:
➜ echo 'plugins:
resolvers:
- "https://github.com/{{index GroupParts 1}}/{{index GroupParts 2}}/releases/download/v{{Version}}/{{Product}}-{{Version}}-{{OS}}-{{Arch}}.tgz"
plugins:
- locator:
id: "com.palantir.godel-generate-plugin:generate-plugin:1.2.0"
exclude:
names:
- "\\\\..+"
- "vendor"
- ".+_string.go"
paths:
- "godel"' > godel/config/godel.yml
Verify that the golint check still succeeds:
➜ ./godelw check golint
Running golint...
Finished golint
Check in the changes:
➜ git add godel/config/godel.yml
➜ git commit -m "Update exclude configuration in godel.yml"
[master caab74f] Update exclude configuration in godel.yml
1 file changed, 1 insertion(+), 1 deletion(-)
Tutorial end state
${GOPATH}/src/${PROJECT_PATH}exists, is the working directory and is initialized as a Git repository and Go module- Project contains
godelandgodelw - Project contains
main.go - Project contains
.gitignorethat ignores GoLand files - Project contains
echo/echo.go,echo/echo_test.goandecho/echoer.go godel/config/dist-plugin.ymlis configured to buildechgo2- Project is tagged as 0.0.1
godel/config/dist-plugin.ymlis configured to create distributions forechgo- Project is tagged as 0.0.2
dockerctxdirectory exists andgodel/config/dist-plugin.ymlis configured to build Docker images for the product- Go files have license headers
godel/config/godel.ymlis configured to add the go-generate plugingodel/config/generate-plugin.ymlis configured to generate string functiongodel/config/godel.ymlis configured to ignore all.+_string.gofiles
Tutorial next step
More
Names, paths and default configuration
godel/config/godel.yml starts with the following defaults:
exclude:
names:
- "\\..+"
- "vendor"
paths:
- "godel"
The names configuration specifies a list of names that should be ignored. The values can be literals or regular
expressions. In either case, the value must fully match the name to be a match -- for regular expressions, this means
that a name is considered a match only if the entire name matches the regular expression. The names configuration is
useful for ignoring classes of files -- for example, .*\\.pb\\.go can be used to ignore all files that end in
.pb.go.
The default configuration for names ignores all hidden files (names that start with .) and all vendor directories.
vendor is specified as a name rather than a path so that vendor directories are ignored in all directories.
The paths configuration specifies a list of paths that should be ignored. Paths can be specified as literal values or
as globs. The paths configuration is useful for ignoring specific files or directories that should be ignored.
The default configuration for paths ignores the godel directory in the root level of the project.
In the case of both names and paths, if the configuration matches a file, that file is ignored, while if it matches
a directory, then that directory (and all of its contents) is ignored.