Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Linters which are not language-specific:
| Markdown | [Prettier] | [Vale] |
| Protocol Buffer | [buf] | [buf lint] |
| Python | [ruff] | [flake8], [pylint], [ruff] |
| Ruby | | [RuboCop] |
| Rust | [rustfmt] | |
| SQL | [prettier-plugin-sql] | |
| Scala | [scalafmt] | |
Expand Down Expand Up @@ -83,6 +84,7 @@ Linters which are not language-specific:
[gofumpt]: https://github.com/mvdan/gofumpt
[jsonnetfmt]: https://github.com/google/go-jsonnet
[scalafmt]: https://scalameta.org/scalafmt
[rubocop]: https://docs.rubocop.org/
[ruff]: https://docs.astral.sh/ruff/
[pylint]: https://pylint.readthedocs.io/en/stable/
[shellcheck]: https://www.shellcheck.net/
Expand Down
2 changes: 1 addition & 1 deletion example/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import %workspace%/../tools/preset.bazelrc
import %workspace%/tools/java17.bazelrc
import %workspace%/tools/java21.bazelrc

# Automatically apply --config=linux, --config=windows etc
common --enable_platform_specific_config
Expand Down
24 changes: 24 additions & 0 deletions example/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# RuboCop configuration for rules_lint example

AllCops:
NewCops: enable
TargetRubyVersion: 3.0

# Configure line length
Layout/LineLength:
Max: 100

# Enable some common cops for demonstration
Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Lint/UselessAssignment:
Enabled: true

Style/DoubleNegation:
Enabled: true
1 change: 1 addition & 0 deletions example/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jruby-10.0.2.0
1 change: 1 addition & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports_files(
"checkstyle.xml",
"checkstyle-suppressions.xml",
".ruff.toml",
".rubocop.yml",
".shellcheckrc",
".scalafmt.conf",
".swcrc",
Expand Down
5 changes: 5 additions & 0 deletions example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop', '~> 1.50'
47 changes: 47 additions & 0 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
json (2.15.1)
json (2.15.1-java)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
parallel (1.27.0)
parser (3.3.9.0)
ast (~> 2.4.1)
racc
prism (1.5.2)
racc (1.8.1)
racc (1.8.1-java)
rainbow (3.1.1)
regexp_parser (2.11.3)
rubocop (1.81.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.47.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)

PLATFORMS
arm64-darwin-24
ruby
universal-java
universal-java-21

DEPENDENCIES
rubocop (~> 1.50)

BUNDLED WITH
2.6.9
34 changes: 34 additions & 0 deletions example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bazel_dep(name = "rules_go", version = "0.52.0", repo_name = "io_bazel_rules_go"
bazel_dep(name = "rules_proto", version = "6.0.0")
bazel_dep(name = "rules_python", version = "0.26.0")
bazel_dep(name = "rules_rust", version = "0.50.1")
bazel_dep(name = "rules_ruby", version = "0.21.1")
bazel_dep(name = "buildifier_prebuilt", version = "6.3.3")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_kotlin", version = "1.9.0")
Expand Down Expand Up @@ -128,3 +129,36 @@ rust.toolchain(
edition = "2021",
versions = ["1.75.0"],
)

ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version_file = "//:.ruby-version",
)
ruby.bundle_fetch(
name = "bundle",
gem_checksums = {
"ast-2.4.3": "954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383",
"json-2.15.1": "b1c1b2e7c116eb1903e0ce0c374783e6ead8747a0f9eca132d274018ebb80b89",
"json-2.15.1-java": "a6185eebe724a6937f60729e4998276d6b3de3ecc35be34f8e47c1eb40903ecf",
"language_server-protocol-3.17.0.5": "fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc",
"lint_roller-1.1.0": "2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87",
"parallel-1.27.0": "4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130",
"parser-3.3.9.0": "94d6929354b1a6e3e1f89d79d4d302cc8f5aa814431a6c9c7e0623335d7687f2",
"prism-1.5.2": "192741663a55af1ac1b987caa1092deb666e4ff46a30c5064ad5456acd05df1d",
"racc-1.8.1": "4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f",
"racc-1.8.1-java": "54f2e6d1e1b91c154013277d986f52a90e5ececbe91465d29172e49342732b98",
"rainbow-3.1.1": "039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a",
"regexp_parser-2.11.3": "ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4",
"rubocop-1.81.1": "352a9a6f314a4312f6c305f1f72bc466254d221c95445cd49e1b65d1f9411635",
"rubocop-ast-1.47.1": "592682017855408b046a8190689490763aecea175238232b1b526826349d01ae",
"ruby-progressbar-1.13.0": "80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33",
"unicode-display_width-3.2.0": "0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42",
"unicode-emoji-4.1.0": "4997d2d5df1ed4252f4830a9b6e86f932e2013fbff2182a9ce9ccabda4f325a5",
},
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle", "ruby", "ruby_toolchains")

register_toolchains("@ruby_toolchains//:all")
38 changes: 38 additions & 0 deletions example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,44 @@ register_sarif_parser_toolchains(
register = True,
)

http_archive(
name = "rules_ruby",
sha256 = "305d299056a586e24022651eccfe172ea1754121ea79c637e29fc1c42704ae3c",
strip_prefix = "rules_ruby-0.21.1",
url = "https://github.com/bazel-contrib/rules_ruby/releases/download/v0.21.1/rules_ruby-v0.21.1.tar.gz",
)

load("@rules_ruby//ruby:deps.bzl", "rb_bundle_fetch", "rb_register_toolchains")

rb_register_toolchains(
version_file = "//:.ruby-version",
)

rb_bundle_fetch(
name = "bundle",
gem_checksums = {
"ast-2.4.3": "954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383",
"json-2.15.1": "b1c1b2e7c116eb1903e0ce0c374783e6ead8747a0f9eca132d274018ebb80b89",
"json-2.15.1-java": "a6185eebe724a6937f60729e4998276d6b3de3ecc35be34f8e47c1eb40903ecf",
"language_server-protocol-3.17.0.5": "fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc",
"lint_roller-1.1.0": "2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87",
"parallel-1.27.0": "4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130",
"parser-3.3.9.0": "94d6929354b1a6e3e1f89d79d4d302cc8f5aa814431a6c9c7e0623335d7687f2",
"prism-1.5.2": "192741663a55af1ac1b987caa1092deb666e4ff46a30c5064ad5456acd05df1d",
"racc-1.8.1": "4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f",
"racc-1.8.1-java": "54f2e6d1e1b91c154013277d986f52a90e5ececbe91465d29172e49342732b98",
"rainbow-3.1.1": "039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a",
"regexp_parser-2.11.3": "ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4",
"rubocop-1.81.1": "352a9a6f314a4312f6c305f1f72bc466254d221c95445cd49e1b65d1f9411635",
"rubocop-ast-1.47.1": "592682017855408b046a8190689490763aecea175238232b1b526826349d01ae",
"ruby-progressbar-1.13.0": "80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33",
"unicode-display_width-3.2.0": "0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42",
"unicode-emoji-4.1.0": "4997d2d5df1ed4252f4830a9b6e86f932e2013fbff2182a9ce9ccabda4f325a5",
},
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)

#---SNIP--- Below here is re-used in the workspace snippet published on releases

load(
Expand Down
6 changes: 6 additions & 0 deletions example/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("@rules_shell//shell:sh_library.bzl", "sh_library")
load("//tools/lint:linters.bzl", "eslint_test")

Expand Down Expand Up @@ -40,6 +41,11 @@ filegroup(
tags = ["toml"],
)

rb_library(
name = "hello_ruby",
srcs = ["hello.rb"],
)

ts_project(
name = "ts_dep",
srcs = ["file-dep.ts"],
Expand Down
38 changes: 38 additions & 0 deletions example/src/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Demo file showing RuboCop violations

# Unused variable (will be caught by RuboCop)
unused_variable = "not used"

# Line too long - this is a demonstration of a line that exceeds the maximum line length configured in .rubocop.yml
def example_method_with_very_long_line
puts "This is an example of a line that is intentionally too long and should be flagged by RuboCop for exceeding the maximum line length"
end

# Missing frozen string literal comment (if configured)
class ExampleClass
def initialize(name)
@name = name
end

# Method with trailing whitespace and inconsistent indentation
def greet
puts "Hello, #{@name}!"
end

# Double negation (style issue)
def active?
!!@active
end
end

# Prefer single quotes over double quotes for static strings
message = "Hello world"

# Trailing comma missing in multi-line array
numbers = [
1,
2,
3
]

puts ExampleClass.new("World").greet
20 changes: 19 additions & 1 deletion example/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_shell//shell:sh_library.bzl", "sh_library")
load("//tools/lint:linters.bzl", "checkstyle_test", "eslint_test", "flake8_test", "pmd_test", "pylint_test", "ruff_test", "shellcheck_test")
load(
"//tools/lint:linters.bzl",
"checkstyle_test",
"eslint_test",
"flake8_test",
"pmd_test",
"pylint_test",
"rubocop_test",
"ruff_test",
"shellcheck_test",
)

write_file(
name = "ts_code_generator",
Expand Down Expand Up @@ -176,3 +186,11 @@ format_test(
srcs = [":generated_sh"],
tags = ["manual"],
)

rubocop_test(
name = "rubocop",
srcs = ["//src:hello_ruby"],
# Expected to fail based on current content of the file.
# Normally you'd fix the file instead of tagging this test.
tags = ["manual"],
)
7 changes: 7 additions & 0 deletions example/test/lint_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ EOF
first-person plural like 'We'.
EOF

# RuboCop
echo <<"EOF" | assert_output --partial
C: 1: 1: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
W: 4: 1: [Correctable] Lint/UselessAssignment: Useless assignment to variable - unused_variable.
C: 6:101: Layout/LineLength: Line is too long. [115/100]
EOF

# stylelint
echo <<"EOF" | assert_output --partial
src/hello.css
Expand Down
8 changes: 4 additions & 4 deletions example/tools/java17.bazelrc → example/tools/java21.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

# What version of Java are the source files in this repo?
# See https://bazel.build/docs/user-manual#java-language-version
common --java_language_version=17
common --java_language_version=21

# The Java language version used to build tools that are executed during a build
# See https://bazel.build/docs/user-manual#tool-java-language-version
common --tool_java_language_version=17
common --tool_java_language_version=21

# The version of JVM to use to execute the code and run the tests.
# NB: The default value is local_jdk which is non-hermetic.
# See https://bazel.build/docs/user-manual#java-runtime-version
common --java_runtime_version=remotejdk_17
common --java_runtime_version=remotejdk_21

# The version of JVM used to execute tools that are needed during a build.
# See https://bazel.build/docs/user-manual#tool-java-runtime-version
common --tool_java_runtime_version=remotejdk_17
common --tool_java_runtime_version=remotejdk_21
5 changes: 5 additions & 0 deletions example/tools/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ native_binary(
),
out = "clang_tidy",
)

alias(
name = "rubocop",
actual = "@bundle//bin:rubocop",
)
8 changes: 8 additions & 0 deletions example/tools/lint/linters.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load("@aspect_rules_lint//lint:keep_sorted.bzl", "lint_keep_sorted_aspect")
load("@aspect_rules_lint//lint:ktlint.bzl", "lint_ktlint_aspect")
load("@aspect_rules_lint//lint:lint_test.bzl", "lint_test")
load("@aspect_rules_lint//lint:pmd.bzl", "lint_pmd_aspect")
load("@aspect_rules_lint//lint:rubocop.bzl", "lint_rubocop_aspect")
load("@aspect_rules_lint//lint:ruff.bzl", "lint_ruff_aspect")
load("@aspect_rules_lint//lint:pylint.bzl", "lint_pylint_aspect")
load("@aspect_rules_lint//lint:shellcheck.bzl", "lint_shellcheck_aspect")
Expand Down Expand Up @@ -142,3 +143,10 @@ keep_sorted = lint_keep_sorted_aspect(
)

keep_sorted_test = lint_test(aspect = keep_sorted)

rubocop = lint_rubocop_aspect(
binary = Label("//tools/lint:rubocop"),
configs = [Label("//:.rubocop.yml")],
)

rubocop_test = lint_test(aspect = rubocop)
6 changes: 6 additions & 0 deletions lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ bzl_library(
],
)

bzl_library(
name = "rubocop",
srcs = ["rubocop.bzl"],
deps = ["//lint/private:lint_aspect"],
)

bzl_library(
name = "ruff",
srcs = ["ruff.bzl"],
Expand Down
Loading
Loading