Skip to content

Commit

Permalink
Remove xtask formatting code
Browse files Browse the repository at this point in the history
Ported the TODO tests to the new linter, since they're handy reference.
Change-Id: If25aaaedf836393a49394ed0046c970ea6e7c30d
  • Loading branch information
jblebrun committed Jul 3, 2024
1 parent 3445d48 commit 0943e2d
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 585 deletions.
72 changes: 2 additions & 70 deletions .xtask_bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ _xtask() {
",$1")
cmd="xtask"
;;
xtask,check-format)
cmd="xtask__check__format"
;;
xtask,completion)
cmd="xtask__completion"
;;
xtask,format)
cmd="xtask__format"
;;
xtask,help)
cmd="xtask__help"
;;
Expand All @@ -39,15 +33,9 @@ _xtask() {
xtask,run-tests)
cmd="xtask__run__tests"
;;
xtask__help,check-format)
cmd="xtask__help__check__format"
;;
xtask__help,completion)
cmd="xtask__help__completion"
;;
xtask__help,format)
cmd="xtask__help__format"
;;
xtask__help,help)
cmd="xtask__help__help"
;;
Expand All @@ -73,7 +61,7 @@ _xtask() {

case "${cmd}" in
xtask)
opts="-h --dry-run --logs --keep-going --help format check-format run-tests run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help"
opts="-h --dry-run --logs --keep-going --help run-tests run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -86,20 +74,6 @@ _xtask() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__check__format)
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__completion)
opts="-h --file-name --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
Expand All @@ -118,22 +92,8 @@ _xtask() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__format)
opts="-h --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__help)
opts="format check-format run-tests run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help"
opts="run-tests run-cargo-clippy run-cargo-fuzz run-cargo-deny run-cargo-udeps completion help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -146,20 +106,6 @@ _xtask() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__help__check__format)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__help__completion)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand All @@ -174,20 +120,6 @@ _xtask() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__help__format)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
xtask__help__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion linter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")

package(
default_visibility = ["//visibility:public"],
Expand Down Expand Up @@ -67,3 +67,8 @@ rust_library(
"@oak_crates_index//:regex",
],
)

rust_test(
name = "tools_test",
crate = ":tools",
)
30 changes: 28 additions & 2 deletions linter/tools/bad_todos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ lazy_static! {
.expect("couldn't parse regex");
}

fn is_invalid_todo(line: &str) -> bool {
// Using \x54 = T to prevent triggering the lint here.
line.contains("\x54ODO") && !PATTERN.is_match(line)
}

impl linter::LinterTool for BadTodoTool {
// Using \x54 = T to prevent triggering the lint here.
const NAME: &'static str = "Bad \x54ODOs";
Expand All @@ -47,8 +52,7 @@ impl linter::LinterTool for BadTodoTool {
let mut results = Vec::<String>::new();
for (n, line) in reader.lines().enumerate() {
let line = line?;
// Using \x54 = T to prevent triggering the lint here.
if line.contains("\x54ODO") && !PATTERN.is_match(&line) {
if is_invalid_todo(&line) {
results.push(format!(" . Line {}: {}", n, line));
}
}
Expand All @@ -60,3 +64,25 @@ impl linter::LinterTool for BadTodoTool {
})
}
}

#[cfg(test)]
mod tests {
use super::is_invalid_todo;

#[test]
fn check_todos() {
// Using \x54 = T to prevent triggering the lint here.
assert!(is_invalid_todo("\x54ODO()"));
assert!(!is_invalid_todo("\x54ODO(#123)"));

assert!(!is_invalid_todo("\x54ODO: b/123 - do something."));
// Missing link separator.
assert!(is_invalid_todo("\x54ODO: do something."));
// Empty link.
assert!(is_invalid_todo("\x54ODO: - do something."));
assert!(is_invalid_todo("\x54ODO:-do something."));
// Empty description.
assert!(is_invalid_todo("\x54ODO: b/123 - ."));
assert!(is_invalid_todo("\x54ODO: b/123 -."));
}
}
1 change: 0 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ itertools = "*"
nix = { version = "*", features = ["signal"] }
once_cell = "*"
portpicker = "*"
regex = "*"
serde = { version = "*", features = ["derive"] }
tokio = { version = "*", features = [
"fs",
Expand Down
45 changes: 0 additions & 45 deletions xtask/src/check_build_licenses.rs

This file was deleted.

46 changes: 0 additions & 46 deletions xtask/src/check_license.rs

This file was deleted.

88 changes: 0 additions & 88 deletions xtask/src/check_todo.rs

This file was deleted.

Loading

0 comments on commit 0943e2d

Please sign in to comment.