zed/tooling/lints/single-lint
Miguel Raz Guzmán Macedo 4b7369481d
Add dylint lint library for Zed-specific patterns (#58496)
Adds a dylint library under tooling/lints that flags Zed-specific
anti-patterns:

* shared_string_from_str_literal, 
* async_block_without_await, 
* entity_update_in_render, 
* notify_in_render, 
* owned_string_into_shared, 
* len_in_loop_condition, and 
* blocking_io_on_foreground. 

Includes UI tests, a single-lint helper, and workspace.metadata.dylint
registration so cargo dylint --all discovers it. The library pins its
own nightly toolchain (kept out of the main workspace) and tracks dylint
6.

Release Notes:

- N/A

Self-Review Checklist:

- [ ] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-07-03 22:05:34 +00:00

64 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Run a single lint from this dylint library against the Zed workspace.
#
# Usage: tooling/lints/single-lint <lint_name> [cargo check args...]
# Example: tooling/lints/single-lint blocking_io_on_foreground -p project_panel
#
# Dylint loads the whole library, so we silence every lint with `-A warnings`
# and force just the requested one back on with `--force-warn`. A plain
# `-W <lint>` is dropped for a driver-registered lint once the group is allowed,
# which is why `--force-warn` is required.
#
# `DYLINT_RUSTFLAGS` is not part of Cargo's fingerprint, so changing it does not
# invalidate already-checked crates. We therefore clean the targeted package(s)
# first so the filter actually applies instead of replaying a stale cache. When
# no package is named (a `--workspace` run) we drop the whole check cache.
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "usage: $(basename "$0") <lint_name> [cargo check args...]" >&2
exit 1
fi
lint="$1"
shift
if [ "$#" -eq 0 ]; then
set -- --workspace
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "$script_dir/../.." && pwd)"
toolchain="$(awk -F'"' '/^channel/ {print $2}' "$script_dir/rust-toolchain.toml")"
host="$(rustc -vV | awk '/^host:/ {print $2}')"
check_target="$repo_root/target/dylint/target/${toolchain}-${host}"
# Force a re-check of the requested package(s) so the lint filter takes effect.
cleaned_any=0
prev=""
for arg in "$@"; do
pkg=""
case "$arg" in
-p=* | --package=*)
pkg="${arg#*=}"
;;
*)
if [ "$prev" = "-p" ] || [ "$prev" = "--package" ]; then
pkg="$arg"
fi
;;
esac
if [ -n "$pkg" ]; then
cargo clean -p "$pkg" --target-dir "$check_target" 2>/dev/null || true
cleaned_any=1
fi
prev="$arg"
done
if [ "$cleaned_any" -eq 0 ]; then
rm -rf "$check_target"
fi
cd "$repo_root"
DYLINT_RUSTFLAGS="-A warnings --force-warn $lint" exec cargo dylint --all -- "$@"