Skip to content

Commit

Permalink
feat: use vale instead of shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTatasciore committed Aug 28, 2024
1 parent 64985b5 commit 3608e30
Show file tree
Hide file tree
Showing 19 changed files with 430 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .aspect/cli/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ configure:
protobuf: true
lint:
aspects:
- //tools/lint:linters.bzl%shellcheck
- //tools/lint:linters.bzl%vale
2 changes: 2 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
enable=quote-safe-variables
# Turn on warnings for unassigned uppercase variables
enable=check-unassigned-uppercase

#enable=require-variable-braces
19 changes: 19 additions & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Configuration for https://Vale.sh
# See https://vale.sh/docs/topics/config/

StylesPath = tools/lint/vale
IgnoredScopes = code

# Tell Vale to look in tools/lint/vale/config/vocabularies/engineering
Vocab = engineering

[*.md]
BlockIgnores = ```[a-z]*\n.*?\n```
BasedOnStyles = Vale, Google

# Reduce levels to make silo error-free.
# TODO(alex): consider promoting some to error
Google.Exclamation = warning
Google.Quotes = warning
Vale.Spelling = warning
Vale.Terms = warning
23 changes: 23 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load("//lib:tar.bzl", "mtree_spec")
load("//lib:testing.bzl", "assert_contains")
load("//lib:write_source_files.bzl", "write_source_files")
load("//lib:yq.bzl", "yq")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")

exports_files([".shellcheckrc"])

Expand Down Expand Up @@ -165,3 +166,25 @@ diff_test(
file1 = "tar_test13_mtree",
file2 = "//lib/tests/tar:expected13.mtree",
)

# Place the .vale.ini file in bazel-bin so the relative path it contains
# StylesPath = tools/lint/vale
# will work when it's run as an action.
copy_to_bin(
name = ".vale_ini",
srcs = [".vale.ini"],
visibility = ["//visibility:public"],
)

# genrule(
# name = "foo",
# srcs = ["foo.md"],
# outs = ["bar.md"],
# cmd = "cp $@ $<",
# )

filegroup(
name = "foo",
srcs = ["foo.md"],
tags = ["markdown"],
)
4 changes: 4 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ go_dependencies()
load("//.aspect/workflows:deps.bzl", "fetch_workflows_deps")

fetch_workflows_deps()

load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")

fetch_vale()
89 changes: 89 additions & 0 deletions foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"diagnostics": [
{
"message": "Vale.Spelling:Did you really mean 'esdwdsqafdfg'?",
"severity": 3,
"title": "Vale found an issue",
"source_content": {
"name": "foo.md"
},
"spans": [
{
"offset": 4
}
],
"baggage": {
"label": "//:foo"
},
"type": 1
},
{
"message": "Vale.Spelling:Did you really mean 'wqftqerwt'?",
"severity": 3,
"title": "Vale found an issue",
"source_content": {
"name": "foo.md"
},
"spans": [
{
"offset": 5
}
],
"baggage": {
"label": "//:foo"
},
"type": 1
},
{
"message": "Vale.Spelling:Did you really mean 'gertgerw'?",
"severity": 3,
"title": "Vale found an issue",
"source_content": {
"name": "foo.md"
},
"spans": [
{
"offset": 8
}
],
"baggage": {
"label": "//:foo"
},
"type": 1
},
{
"message": "Google.FirstPerson:Avoid first-person pronouns such as 'I '.",
"severity": 3,
"title": "Vale found an issue",
"source_content": {
"name": "foo.md"
},
"spans": [
{
"offset": 11
}
],
"baggage": {
"label": "//:foo"
},
"type": 1
},
{
"message": "Vale.Avoid:Avoid using 'bar'.",
"severity": 3,
"title": "Vale found an issue",
"source_content": {
"name": "foo.md"
},
"spans": [
{
"offset": 13
}
],
"baggage": {
"label": "//:foo"
},
"type": 1
}
]
}
14 changes: 14 additions & 0 deletions foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Hello world


esdwdsqafdfg

Check warning on line 4 in foo.md

View check run for this annotation

Aspect Workflows / Lint

Vale found an issue

Vale.Spelling:Did you really mean 'esdwdsqafdfg'?
wqftqerwt

Check warning on line 5 in foo.md

View check run for this annotation

Aspect Workflows / Lint

Vale found an issue

Vale.Spelling:Did you really mean 'wqftqerwt'?


gertgerw

Check warning on line 8 in foo.md

View check run for this annotation

Aspect Workflows / Lint

Vale found an issue

Vale.Spelling:Did you really mean 'gertgerw'?


I Am where would you LiKe to make an error

Check warning on line 11 in foo.md

View check run for this annotation

Aspect Workflows / Lint

Vale found an issue

Google.FirstPerson:Avoid first-person pronouns such as 'I '.

bar

Check warning on line 13 in foo.md

View check run for this annotation

Aspect Workflows / Lint

Vale found an issue

Vale.Avoid:Avoid using 'bar'.

13 changes: 13 additions & 0 deletions lib/tests/stamping/stamper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@ done < <(cat "${BAZEL_STABLE_STATUS_FILE:-/dev/null}" "${BAZEL_VOLATILE_STATUS_F

# A real program would do something useful with the stamp info, like pass it to a linker.
echo "${BUILD_USER:-unstamped}" >"$1"

function throwAwayFunc() {
local _array=();
}

function arraysFromArray() {
local i _id; _id=$1;
declare -n _array="${_id}";
# ***^-- SC2178 (warning): Variable was used as an array but is now assigned a string.***
for i in "${_array[@]}"; do
makeArr "$i";
done;
}
31 changes: 31 additions & 0 deletions platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
load("//platforms/config:defs.bzl", "linker_suffix", "platforms")

[platform(
name = "{}_{}{}".format(
p.os,
p.cpu,
linker_suffix(
"_",
p.linker,
),
),
constraint_values = [
"@platforms//os:{}".format(p.os),
"@platforms//cpu:{}".format(p.cpu),
"@//platforms/linkers:{}".format(p.linker),
],
visibility = ["//visibility:public"],
) for p in platforms]

alias(
name = "linux_amd64",
actual = ":linux_x86_64",
visibility = ["//visibility:public"],
)

alias(
name = "linux_arm64",
actual = ":linux_aarch64",
visibility = ["//visibility:public"],
)

platform(
name = "x86_64_linux_remote",
constraint_values = [
Expand Down
31 changes: 31 additions & 0 deletions platforms/config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load(":defs.bzl", "platforms")

config_setting(
name = "aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

[config_setting(
name = "{}_{}{}".format(
p.os,
p.cpu,
"_{}".format(p.linker) if p.linker != "unknown" else "",
),
constraint_values = [
"@platforms//os:{}".format(p.os),
"@platforms//cpu:{}".format(p.cpu),
"@//platforms/linkers:{}".format(p.linker),
],
visibility = ["//visibility:public"],
) for p in platforms]
19 changes: 19 additions & 0 deletions platforms/config/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""This module generated the platforms list for the build matrix."""

def linker_suffix(delimiter, linker):
if linker == "unknown":
return ""
return delimiter + linker

cpus = ["aarch64", "x86_64"]
os_to_linker = {
"linux": ["musl", "unknown"],
"macos": ["unknown"],
}

platforms = [
struct(os = os, cpu = cpu, linker = linker)
for os in os_to_linker
for linker in os_to_linker[os]
for cpu in cpus
]
19 changes: 19 additions & 0 deletions platforms/linkers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
constraint_setting(
name = "linker",
default_constraint_value = ":unknown",
visibility = ["//visibility:public"],
)

constraint_value(
name = "musl",
constraint_setting = ":linker",
visibility = ["//visibility:public"],
)

# Default linker for anyone not setting the linker to `musl`.
# You shouldn't ever need to set this value manually.
constraint_value(
name = "unknown",
constraint_setting = ":linker",
visibility = ["//visibility:public"],
)
25 changes: 25 additions & 0 deletions platforms/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load(":defs.bzl", "platforms")

[toolchain(
name = "{}_{}_{}_{}_llvm".format(
p.exe_os,
p.exe_cpu,
p.tgt_os,
p.tgt_cpu,
),
exec_compatible_with = [
"@platforms//os:{}".format(p.exe_os),
"@platforms//cpu:{}".format(p.exe_cpu),
],
target_compatible_with = [
"@platforms//os:{}".format(p.tgt_os),
"@platforms//cpu:{}".format(p.tgt_cpu),
"//platforms/linkers:unknown",
],
toolchain = "@llvm_toolchain//:cc-clang-{}-{}".format(
p.tgt_cpu,
p.tgt_os if p.tgt_os != "macos" else "darwin",
),
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
visibility = ["//visibility:public"],
) for p in platforms]
19 changes: 19 additions & 0 deletions platforms/toolchains/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""This module registers all the LLVM toolchains that we want to use."""

execution_oses = ["macos", "linux"]
execution_cpus = ["aarch64", "x86_64"]
target_oses = ["macos", "linux"]
target_cpus = ["aarch64", "x86_64"]

platforms = [
struct(exe_os = exe_os, exe_cpu = exe_cpu, tgt_os = tgt_os, tgt_cpu = tgt_cpu)
for exe_os in execution_oses
for exe_cpu in execution_cpus
for tgt_os in target_oses
for tgt_cpu in target_cpus
]

# buildifier: disable=unnamed-macro
def register_llvm_toolchains():
for p in platforms:
native.register_toolchains("//platforms/toolchains:{}_{}_{}_{}_llvm".format(p.exe_os, p.exe_cpu, p.tgt_os, p.tgt_cpu))
28 changes: 28 additions & 0 deletions tools/lint/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

package(default_visibility = ["//visibility:public"])

native_binary(
name = "vale_bin",
src = select({
"//platforms/config:linux_x86_64": "@vale_Linux_64-bit//:vale",
"//platforms/config:macos_aarch64": "@vale_macOS_arm64//:vale",
"//platforms/config:macos_x86_64": "@vale_macOS_64-bit//:vale",
}),
out = "vale_bin",
)

# Take care to keep the StylesPath entry in /.vale.ini working:
# - the editor sees tools/lint/vale in the source tree
# - the linting aspect sees bazel-bin/tools/lint/vale
copy_to_directory(
name = "vale_styles",
srcs = [
"vale",
"@vale_Google//:Google",
],
out = "vale",
include_external_repositories = ["vale_*"],
replace_prefixes = {"vale/": ""},
)
11 changes: 6 additions & 5 deletions tools/lint/linters.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"Define linter aspects"
"Create linter aspects, see https://github.com/aspect-build/rules_lint/blob/main/docs/linting.md#installation"

load("@aspect_rules_lint//lint:shellcheck.bzl", "lint_shellcheck_aspect")
load("@aspect_rules_lint//lint:vale.bzl", "lint_vale_aspect")

shellcheck = lint_shellcheck_aspect(
binary = "@multitool//tools/shellcheck",
config = "@@//:.shellcheckrc",
vale = lint_vale_aspect(
binary = "@@//tools/lint:vale_bin",
config = "@@//:.vale_ini",
styles = "@@//tools/lint:vale_styles",
)
Loading

0 comments on commit 3608e30

Please sign in to comment.