zed/tooling/lints/test_fixture/consumer/src/lib.rs
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

63 lines
1.8 KiB
Rust

use gpui_shared_string::SharedString;
// Should fire: `from` with a short literal (≤ 23 bytes).
pub fn from_short() -> SharedString {
SharedString::from("Favorites")
}
// Should fire at elevated severity: `from` with a long literal (> 23 bytes).
pub fn from_long() -> SharedString {
SharedString::from("Right-click for more options")
}
// Should fire: explicit `.into()` from a string literal.
pub fn into_short() -> SharedString {
"hello".into()
}
// Should fire: `SharedString::new("...")`.
pub fn new_short() -> SharedString {
SharedString::new("hi")
}
// Should NOT fire: the zero-cost constructor.
pub fn new_static_short() -> SharedString {
SharedString::new_static("Favorites")
}
// Should NOT fire: non-literal input.
pub fn from_variable(s: &str) -> SharedString {
SharedString::from(s)
}
// Should NOT fire: `.into()` on a non-literal.
pub fn into_variable(s: &str) -> SharedString {
s.into()
}
// Should fire: `.into()` on a string literal that exceeds the 23-byte cap.
pub fn into_long() -> SharedString {
"this literal is definitely longer than twenty three bytes".into()
}
// ---- owned_string_into_shared cases targeting `SharedString` ----
// Should fire (owned_string_into_shared): `String::from(<lit>).into()`.
pub fn shared_string_from_string_from() -> SharedString {
String::from("label").into()
}
// Should fire (owned_string_into_shared): `<lit>.to_string().into()`.
pub fn shared_string_from_to_string() -> SharedString {
"label".to_string().into()
}
// Should fire (owned_string_into_shared): `<lit>.to_owned().into()`.
pub fn shared_string_from_to_owned() -> SharedString {
"label".to_owned().into()
}
// Should NOT fire owned_string_into_shared: the source is a non-literal `String`.
pub fn shared_string_from_dynamic_string(s: String) -> SharedString {
s.into()
}