Skip to content

Commit

Permalink
Add module option to lint and breaking rules
Browse files Browse the repository at this point in the history
  • Loading branch information
srikrsna-buf committed May 22, 2024
1 parent 35408b9 commit 11568c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions buf/internal/breaking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ _TOOLCHAIN = str(Label("//tools/protoc-gen-buf-breaking:toolchain_type"))

def _buf_breaking_test_impl(ctx):
proto_infos = [t[ProtoInfo] for t in ctx.attr.targets]
config = json.encode({
config_map = {
"against_input": ctx.file.against.short_path,
"limit_to_input_files": ctx.attr.limit_to_input_files,
"exclude_imports": ctx.attr.exclude_imports,
"input_config": ctx.file.config.short_path,
"error_format": ctx.attr.error_format,
})
}
if ctx.attr.module != "":
config_map["module"] = ctx.attr.module
config = json.encode(config_map)
files_to_include = [ctx.file.against]
if ctx.file.config != None:
files_to_include.append(ctx.file.config)
Expand Down Expand Up @@ -69,6 +72,10 @@ buf_breaking_test = rule(
allow_single_file = True,
doc = """The `buf.yaml` file""",
),
"module": attr.string(
default = "",
doc = "The module to use in v2 config",
),
"limit_to_input_files": attr.bool(
default = False,
doc = """Checks are limited to input files. If a file gets deleted that will not be caught. Please refer to https://docs.buf.build/breaking/protoc-plugin for more details""",
Expand Down
11 changes: 9 additions & 2 deletions buf/internal/lint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ _TOOLCHAIN = str(Label("//tools/protoc-gen-buf-lint:toolchain_type"))

def _buf_lint_test_impl(ctx):
proto_infos = [t[ProtoInfo] for t in ctx.attr.targets]
config = json.encode({
config_map = {
"input_config": "" if ctx.file.config == None else ctx.file.config.short_path,
"error_format": ctx.attr.error_format,
})
}
if ctx.attr.module != "":
config_map["module"] = ctx.attr.module
config = json.encode(config_map)
files_to_include = []
if ctx.file.config != None:
files_to_include.append(ctx.file.config)
Expand Down Expand Up @@ -62,6 +65,10 @@ buf_lint_test = rule(
allow_single_file = True,
doc = "The `buf.yaml` file",
),
"module": attr.string(
default = "",
doc = "The module to use in v2 config",
),
"error_format": attr.string(
default = "",
doc = "error-format flag for buf lint: https://buf.build/docs/reference/cli/buf/lint#error-format",
Expand Down

0 comments on commit 11568c4

Please sign in to comment.