From e73ccccbbf80d5f271f520a1baea4bfac27cabe5 Mon Sep 17 00:00:00 2001 From: Griffin Date: Sun, 25 Feb 2024 06:30:01 +0800 Subject: [PATCH] Update mixed_table warning message (#586) Closes: #572 It makes the error message for mixed tables more descriptive and explains why they're bad and should be _avoided_. --------- Co-authored-by: boyned//Kampfkarren Co-authored-by: Chris Chang <51393127+chriscerie@users.noreply.github.com> --- CHANGELOG.md | 3 +++ selene-lib/src/lints/mixed_table.rs | 2 +- selene-lib/src/lints/roblox_incorrect_roact_usage.rs | 2 +- .../tests/lints/mixed_table/mixed_table.stderr | 12 ++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61ec5fe2..6250d33a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Added `CFrame.lookAlong` to the Roblox standard library +### Changed +- Updated the warning message for the `mixed_table` lint to include why mixed tables should be avoided + ## [0.26.1](https://github.com/Kampfkarren/selene/releases/tag/0.26.1) - 2023-11-11 ### Fixed - Fixed `UDim2.new()` firing the [`roblox_suspicious_udim2_new` lint](https://kampfkarren.github.io/selene/lints/roblox_suspicious_udim2_new.html). diff --git a/selene-lib/src/lints/mixed_table.rs b/selene-lib/src/lints/mixed_table.rs index 4a588abf..249357a3 100644 --- a/selene-lib/src/lints/mixed_table.rs +++ b/selene-lib/src/lints/mixed_table.rs @@ -30,7 +30,7 @@ impl Lint for MixedTableLint { for mixed_table in visitor.mixed_tables { diagnostics.push(Diagnostic::new_complete( "mixed_table", - "mixed tables are not allowed".to_owned(), + "mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding".to_owned(), Label::new(mixed_table.range), vec!["help: change this table to either an array or dictionary".to_owned()], Vec::new(), diff --git a/selene-lib/src/lints/roblox_incorrect_roact_usage.rs b/selene-lib/src/lints/roblox_incorrect_roact_usage.rs index 94c02362..3917df9f 100644 --- a/selene-lib/src/lints/roblox_incorrect_roact_usage.rs +++ b/selene-lib/src/lints/roblox_incorrect_roact_usage.rs @@ -18,7 +18,7 @@ use if_chain::if_chain; pub struct IncorrectRoactUsageLint; // Assumes string includes quotes at start and end -fn is_lua_valid_table_key_identifier(string: &String) -> bool { +fn is_lua_valid_table_key_identifier(string: &str) -> bool { // Valid identifier cannot start with numbers let first_char = string.chars().nth(1).unwrap(); if !first_char.is_alphabetic() && first_char != '_' { diff --git a/selene-lib/tests/lints/mixed_table/mixed_table.stderr b/selene-lib/tests/lints/mixed_table/mixed_table.stderr index b557beaa..24ad2049 100644 --- a/selene-lib/tests/lints/mixed_table/mixed_table.stderr +++ b/selene-lib/tests/lints/mixed_table/mixed_table.stderr @@ -1,4 +1,4 @@ -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:2:5 │ 2 │ ╭ "", @@ -7,7 +7,7 @@ error[mixed_table]: mixed tables are not allowed │ = help: change this table to either an array or dictionary -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:7:5 │ 7 │ ╭ {}, @@ -16,7 +16,7 @@ error[mixed_table]: mixed tables are not allowed │ = help: change this table to either an array or dictionary -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:12:5 │ 12 │ ╭ a, @@ -25,7 +25,7 @@ error[mixed_table]: mixed tables are not allowed │ = help: change this table to either an array or dictionary -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:19:5 │ 19 │ ╭ 1, @@ -34,7 +34,7 @@ error[mixed_table]: mixed tables are not allowed │ = help: change this table to either an array or dictionary -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:25:5 │ 25 │ ╭ [c] = d, @@ -43,7 +43,7 @@ error[mixed_table]: mixed tables are not allowed │ = help: change this table to either an array or dictionary -error[mixed_table]: mixed tables are not allowed +error[mixed_table]: mixed tables should be avoided, as they can cause confusing and hard to debug issues such as during iteration or encoding ┌─ mixed_table.lua:30:5 │ 30 │ ╭ a = b,