diff --git a/.bazelversion b/.bazelversion index 03f488b..643916c 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.3.0 +7.3.1 diff --git a/MODULE.bazel b/MODULE.bazel index 9c79ef4..2750b3b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,10 +1,11 @@ module( name = "apple_rules_lint", - version = "0.3.2", + version = "0.4.0", ) bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep(name = "stardoc", version = "0.5.3", repo_name = "io_bazel_stardoc", dev_dependency = True) + +bazel_dep(name = "stardoc", version = "0.7.0", dev_dependency = True, repo_name = "io_bazel_stardoc") linter = use_extension("//lint:extensions.bzl", "linter") use_repo(linter, "apple_linters") diff --git a/README.md b/README.md index 2f1ee3b..65356fd 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,11 @@ Alternatively, using Bzlmod: ```py # MODULE.bazel -bazel_dep(name = "apple_rules_lint", version = "0.1.1") +bazel_dep(name = "apple_rules_lint", version = "0.4.0") linter = use_extension("@apple_rules_lint//lint:extensions.bzl", "linter") linter.configure(name = "java-checkstyle", config = "//your:checkstyle-config") +use_repo(linter, "apple_linters") ``` You may override specific lint configurations on a per-package basis by: diff --git a/WORKSPACE b/WORKSPACE index f67877f..3f66dbd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,18 +7,3 @@ lint_deps() load("//lint:setup.bzl", "lint_setup") lint_setup() - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "io_bazel_stardoc", - sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", - "https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz", - ], -) - -load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") - -stardoc_repositories() diff --git a/api.md b/api.md index 22eba4d..a4a2d2a 100755 --- a/api.md +++ b/api.md @@ -7,14 +7,13 @@ ## LinterInfo
+load("@apple_rules_lint//lint:defs.bzl", "LinterInfo") + LinterInfo(language, name)- - **FIELDS** - | Name | Description | | :------------- | :------------- | | language | The language or kind of thing we are linting. | @@ -26,6 +25,8 @@ LinterInfo(language, linter_name, tags) @@ -42,8 +43,8 @@ for specific rules. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| linter_name | The "well known" name of the linter (eg.
java-checkstyle
) | none |
-| tags | The tags from the rule (eg. ctx.attr.tags
) | none |
+| linter_name | The "well known" name of the linter (eg. `java-checkstyle`) | none |
+| tags | The tags from the rule (eg. `ctx.attr.tags`) | none |
@@ -51,6 +52,8 @@ for specific rules.
## package_lint_config
+load("@apple_rules_lint//lint:defs.bzl", "package_lint_config") + package_lint_config(linters)diff --git a/example/MODULE.bazel b/example/MODULE.bazel new file mode 100644 index 0000000..0081a13 --- /dev/null +++ b/example/MODULE.bazel @@ -0,0 +1,18 @@ +module( + name = "lint_example", +) + +bazel_dep(name = "apple_rules_lint", version = "0.0.0") +local_path_override( + module_name = "apple_rules_lint", + path = "..", +) + +linter = use_extension("@apple_rules_lint//lint:extensions.bzl", "linter") +linter.register(name = "lint_example") + +#linter.configure( +# name = "lint_example", +# config = "//:default_config", +#) +use_repo(linter, "apple_linters") diff --git a/lint/private/get_lint_config.bzl b/lint/private/get_lint_config.bzl index 672a330..14537e1 100644 --- a/lint/private/get_lint_config.bzl +++ b/lint/private/get_lint_config.bzl @@ -1,6 +1,17 @@ load("@apple_linters//:defs.bzl", "configured_linters") load("//lint/private:package_lint_config.bzl", "OVERRIDE_RULE_NAME") +def get_repo_name(): + repo_name = getattr(native, "repo_name", None) + if not repo_name: + # We're using an old Bazel version (5.x), so this will be fine + return native.repository_name() + + # Are we using `bzlmod` or not? + is_bzlmod = str(Label("@does_not_exist_i_promise//:BUILD.bazel")).startswith("@@") + prefix = "@@" if is_bzlmod else "@" + return prefix + repo_name() + def get_lint_config(linter_name, tags): """Gets the lint config for a particular linter from the tags of a rule. @@ -25,7 +36,7 @@ def get_lint_config(linter_name, tags): return None if native.existing_rule("%s_%s" % (OVERRIDE_RULE_NAME, linter_name)) != None: - return Label("%s//%s:%s_%s" % (native.repository_name(), native.package_name(), OVERRIDE_RULE_NAME, linter_name)) + return Label("%s//%s:%s_%s" % (get_repo_name(), native.package_name(), OVERRIDE_RULE_NAME, linter_name)) if linter_name in configured_linters: return Label("@apple_linters//:%s_%s" % (OVERRIDE_RULE_NAME, linter_name))