Skip to content

Commit

Permalink
feat: add lint command to bazel
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Eagle <[email protected]>
  • Loading branch information
jbedard and alexeagle authored Oct 6, 2023
1 parent 0d7edfc commit 9d73060
Show file tree
Hide file tree
Showing 11 changed files with 964 additions and 7 deletions.
45 changes: 43 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("//release:release.bzl", "local_plugin")

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib_gazelle_plugin//bzl"],
languages = DEFAULT_LANGUAGES + [
"@bazel_skylib_gazelle_plugin//bzl",
],
)

gazelle(
name = "gazelle",
gazelle = "gazelle_bin",
)

# gazelle:prefix github.com/aspect-build/rules_lint
# Buildozer ships with BUILD files but doesn't follow our naming convention
# gazelle:resolve go github.com/bazelbuild/buildtools/edit @com_github_bazelbuild_buildtools//edit:go_default_library
go_library(
name = "lint-plugin_lib",
srcs = ["plugin.go"],
importpath = "github.com/aspect-build/rules_lint",
visibility = ["//:__subpackages__"],
deps = [
"@build_aspect_cli//bazel/buildeventstream",
"@build_aspect_cli//bazel/command_line",
"@build_aspect_cli//pkg/aspecterrors",
"@build_aspect_cli//pkg/bazel",
"@build_aspect_cli//pkg/ioutils",
"@build_aspect_cli//pkg/plugin/sdk/v1alpha4/config",
"@build_aspect_cli//pkg/plugin/sdk/v1alpha4/plugin",
"@com_github_hashicorp_go_plugin//:go-plugin",
"@com_github_manifoldco_promptui//:promptui",
],
)

# Only used for local development.
# Release binaries are created by the target in /release
go_binary(
name = "lint-plugin",
embed = [":lint-plugin_lib"],
visibility = ["//visibility:public"],
)

# Build this target to copy the plugin to bazel-bin/plugin and checksum it.
# Referenced by the .aspect/cli/config.yaml in the `From:` line.
local_plugin(
name = "dev",
binary = ":lint-plugin",
path = "plugin",
)
23 changes: 20 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@ module(
version = "0.0.0",
)

bazel_dep(name = "aspect_bazel_lib", version = "1.30.2")
bazel_dep(name = "aspect_bazel_lib", version = "1.31.2")
bazel_dep(name = "aspect_rules_js", version = "1.32.2")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "platforms", version = "0.0.7")

bazel_dep(name = "gazelle", version = "0.29.0", repo_name = "bazel_gazelle", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.39.1", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.31.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps", dev_dependency = True)
go_deps.from_file(go_mod = "//:go.mod")

go_deps.gazelle_override(
build_file_generation = "on",
path = "github.com/bazelbuild/bazelisk",
)

# All *direct* Go dependencies of the module have to be listed explicitly.
use_repo(
go_deps,
"build_aspect_cli",
"com_github_hashicorp_go_plugin",
"com_github_manifoldco_promptui",
)
5 changes: 5 additions & 0 deletions e2e/eslint/.aspect/cli/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins:
- name: lint-plugin
# For this to work, you must first `bazel build dev` in the root of the repo
from: ../../bazel-bin/plugin
log_level: warn
2 changes: 2 additions & 0 deletions e2e/eslint/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.7.2
4 changes: 2 additions & 2 deletions e2e/eslint/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Bazel dependencies"
bazel_dep(name = "aspect_rules_lint", dev_dependency = True, version = "0.0.0")
bazel_dep(name = "aspect_bazel_lib", version = "1.30.2")
bazel_dep(name = "aspect_rules_js", version = "1.25.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "1.31.2")
bazel_dep(name = "aspect_rules_js", version = "1.32.2", dev_dependency = True)
bazel_dep(name = "aspect_rules_ts", version = "1.3.3", dev_dependency = True)
bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.4.1")

Expand Down
47 changes: 47 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module github.com/aspect-build/rules_lint-aspect-cli-plugin

go 1.19

require (
aspect.build/cli v1.507.2
github.com/hashicorp/go-plugin v1.4.10
github.com/manifoldco/promptui v0.9.0
)

require (
github.com/bazelbuild/bazelisk v1.17.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 9d73060

Please sign in to comment.