From 5f6c2be747eb53b4f83fe045325c3b488e7145ac Mon Sep 17 00:00:00 2001 From: Chris Chang <51393127+chriscerie@users.noreply.github.com> Date: Mon, 11 Sep 2023 21:52:06 -0700 Subject: [PATCH 1/9] Add mixed table lint (#535) Closes #534. This might false positive when working with an external library that expects a mixed table as it also warns against mixed tables passed into function calls. Disabling it in these cases would also disable similar cases where the user's application owns the expecting function. --- CHANGELOG.md | 1 + docs/src/SUMMARY.md | 1 + docs/src/lints/mixed_table.md | 14 +++ selene-lib/src/lib.rs | 1 + selene-lib/src/lints.rs | 1 + selene-lib/src/lints/mixed_table.rs | 92 +++++++++++++++++++ .../tests/lints/mixed_table/mixed_table.lua | 53 +++++++++++ .../lints/mixed_table/mixed_table.stderr | 54 +++++++++++ 8 files changed, 217 insertions(+) create mode 100644 docs/src/lints/mixed_table.md create mode 100644 selene-lib/src/lints/mixed_table.rs create mode 100644 selene-lib/tests/lints/mixed_table/mixed_table.lua create mode 100644 selene-lib/tests/lints/mixed_table/mixed_table.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index d985a1b0..bd5f5c35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Excludes are now respected for single files. - Added `no-exclude` cli flag to disable excludes. - When given in standard library format, additional information now shows up in `incorrect_standard_library_use` missing required parameter errors. +- Added new [`mixed_table` lint](https://kampfkarren.github.io/selene/lints/mixed_table.html), which will warn against mixed tables. ### Fixed - `string.pack` and `string.unpack` now have proper function signatures in the Lua 5.3 standard library. diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 7d0d0618..51fcca18 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -27,6 +27,7 @@ - [incorrect_standard_library_use](./lints/incorrect_standard_library_use.md) - [manual_table_clone](./lints/manual_table_clone.md) - [mismatched_arg_count](./lints/mismatched_arg_count.md) + - [mixed_table](./lints/mixed_table.md) - [multiple_statements](./lints/multiple_statements.md) - [must_use](./lints/must_use.md) - [parenthese_conditions](./lints/parenthese_conditions.md) diff --git a/docs/src/lints/mixed_table.md b/docs/src/lints/mixed_table.md new file mode 100644 index 00000000..71e633d9 --- /dev/null +++ b/docs/src/lints/mixed_table.md @@ -0,0 +1,14 @@ +# mixed_table +## What it does +Checks for mixed tables (tables that act as both an array and dictionary). + +## Why this is bad +Mixed tables harms readability and are prone to bugs. There is almost always a better alternative. + +## Example +```lua +local foo = { + "array field", + bar = "dictionary field", +} +``` diff --git a/selene-lib/src/lib.rs b/selene-lib/src/lib.rs index 64d0c40c..77bb09c3 100644 --- a/selene-lib/src/lib.rs +++ b/selene-lib/src/lib.rs @@ -312,6 +312,7 @@ use_lints! { invalid_lint_filter: lints::invalid_lint_filter::InvalidLintFilterLint, manual_table_clone: lints::manual_table_clone::ManualTableCloneLint, mismatched_arg_count: lints::mismatched_arg_count::MismatchedArgCountLint, + mixed_table: lints::mixed_table::MixedTableLint, multiple_statements: lints::multiple_statements::MultipleStatementsLint, must_use: lints::must_use::MustUseLint, parenthese_conditions: lints::parenthese_conditions::ParentheseConditionsLint, diff --git a/selene-lib/src/lints.rs b/selene-lib/src/lints.rs index 27c30c09..fa42553c 100644 --- a/selene-lib/src/lints.rs +++ b/selene-lib/src/lints.rs @@ -23,6 +23,7 @@ pub mod ifs_same_cond; pub mod invalid_lint_filter; pub mod manual_table_clone; pub mod mismatched_arg_count; +pub mod mixed_table; pub mod multiple_statements; pub mod must_use; pub mod parenthese_conditions; diff --git a/selene-lib/src/lints/mixed_table.rs b/selene-lib/src/lints/mixed_table.rs new file mode 100644 index 00000000..4a588abf --- /dev/null +++ b/selene-lib/src/lints/mixed_table.rs @@ -0,0 +1,92 @@ +use super::*; +use crate::ast_util::range; +use std::convert::Infallible; + +use full_moon::{ + ast::{self, Ast}, + visitors::Visitor, +}; + +pub struct MixedTableLint; + +impl Lint for MixedTableLint { + type Config = (); + type Error = Infallible; + + const SEVERITY: Severity = Severity::Warning; + const LINT_TYPE: LintType = LintType::Correctness; + + fn new(_: Self::Config) -> Result { + Ok(MixedTableLint) + } + + fn pass(&self, ast: &Ast, _: &Context, _: &AstContext) -> Vec { + let mut visitor = MixedTableVisitor::default(); + + visitor.visit_ast(ast); + + let mut diagnostics = Vec::new(); + + for mixed_table in visitor.mixed_tables { + diagnostics.push(Diagnostic::new_complete( + "mixed_table", + "mixed tables are not allowed".to_owned(), + Label::new(mixed_table.range), + vec!["help: change this table to either an array or dictionary".to_owned()], + Vec::new(), + )); + } + + diagnostics + } +} + +#[derive(Default)] +struct MixedTableVisitor { + mixed_tables: Vec, +} + +struct MixedTable { + range: (usize, usize), +} + +impl Visitor for MixedTableVisitor { + fn visit_table_constructor(&mut self, node: &ast::TableConstructor) { + let mut last_key_field_starting_range = 0; + let mut last_no_key_field_starting_range = 0; + + for field in node.fields() { + if let ast::Field::NoKey(_) = field { + if last_key_field_starting_range > 0 { + self.mixed_tables.push(MixedTable { + range: (last_key_field_starting_range, range(field).1), + }); + return; + } + last_no_key_field_starting_range = range(field).0; + } else { + if last_no_key_field_starting_range > 0 { + self.mixed_tables.push(MixedTable { + range: (last_no_key_field_starting_range, range(field).1), + }); + return; + } + last_key_field_starting_range = range(field).0; + } + } + } +} + +#[cfg(test)] +mod tests { + use super::{super::test_util::test_lint, *}; + + #[test] + fn test_mixed_table() { + test_lint( + MixedTableLint::new(()).unwrap(), + "mixed_table", + "mixed_table", + ); + } +} diff --git a/selene-lib/tests/lints/mixed_table/mixed_table.lua b/selene-lib/tests/lints/mixed_table/mixed_table.lua new file mode 100644 index 00000000..54217795 --- /dev/null +++ b/selene-lib/tests/lints/mixed_table/mixed_table.lua @@ -0,0 +1,53 @@ +local bad = { + "", + a = b, +} + +bad = { + {}, + [a] = b, +} + +bad = { + a, + [""] = b, +} + +-- This is technically not a mixed table, but it's formatted like it harming readability +-- so it should still be linted +bad = { + 1, + [2] = b, +} + +bad = { + [a] = b, + [c] = d, + "", +} + +bad({ + a = b, + "", + c = d, +}) + +local good = { + a = b, + c = d, +} + +good = { + "", + a, +} + +good = { + [1] = a, + [3] = b, +} + +good({ + a = b, + c = d, +}) diff --git a/selene-lib/tests/lints/mixed_table/mixed_table.stderr b/selene-lib/tests/lints/mixed_table/mixed_table.stderr new file mode 100644 index 00000000..b557beaa --- /dev/null +++ b/selene-lib/tests/lints/mixed_table/mixed_table.stderr @@ -0,0 +1,54 @@ +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:2:5 + │ +2 │ ╭ "", +3 │ │ a = b, + │ ╰─────────^ + │ + = help: change this table to either an array or dictionary + +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:7:5 + │ +7 │ ╭ {}, +8 │ │ [a] = b, + │ ╰───────────^ + │ + = help: change this table to either an array or dictionary + +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:12:5 + │ +12 │ ╭ a, +13 │ │ [""] = b, + │ ╰────────────^ + │ + = help: change this table to either an array or dictionary + +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:19:5 + │ +19 │ ╭ 1, +20 │ │ [2] = b, + │ ╰───────────^ + │ + = help: change this table to either an array or dictionary + +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:25:5 + │ +25 │ ╭ [c] = d, +26 │ │ "", + │ ╰──────^ + │ + = help: change this table to either an array or dictionary + +error[mixed_table]: mixed tables are not allowed + ┌─ mixed_table.lua:30:5 + │ +30 │ ╭ a = b, +31 │ │ "", + │ ╰──────^ + │ + = help: change this table to either an array or dictionary + From 3ebc0b34c29226d59f2e69503803525c6ea5e25b Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 29 Sep 2023 06:19:13 +0200 Subject: [PATCH 2/9] Fix spelling of superseded (#554) Noticed this when checking up the docs, figured I'd open a PR :) --- docs/src/usage/std.md | 2 +- selene-lib/default_std/lua51.yml | 2 +- selene-lib/default_std/roblox_base.yml | 4 ++-- selene-lib/tests/lints/deprecated/deprecated_functions.stderr | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/usage/std.md b/docs/src/usage/std.md index 19e97f3c..cc221491 100644 --- a/docs/src/usage/std.md +++ b/docs/src/usage/std.md @@ -150,7 +150,7 @@ globals: - type: table - type: number deprecated: - message: "`table.getn` has been superceded by #." + message: "`table.getn` has been superseded by #." replace: - "#%1" ``` diff --git a/selene-lib/default_std/lua51.yml b/selene-lib/default_std/lua51.yml index 387aacea..b0098ac1 100644 --- a/selene-lib/default_std/lua51.yml +++ b/selene-lib/default_std/lua51.yml @@ -593,7 +593,7 @@ globals: - type: table - type: number deprecated: - message: "`table.getn` has been superceded by #." + message: "`table.getn` has been superseded by #." replace: - "#%1" must_use: true diff --git a/selene-lib/default_std/roblox_base.yml b/selene-lib/default_std/roblox_base.yml index 07e46fa5..4fa75387 100644 --- a/selene-lib/default_std/roblox_base.yml +++ b/selene-lib/default_std/roblox_base.yml @@ -611,7 +611,7 @@ structs: method: true connect: deprecated: - message: "lowercase methods have been superceded by uppercase ones" + message: "lowercase methods have been superseded by uppercase ones" replace: - "Connect(%1)" args: @@ -626,7 +626,7 @@ structs: method: true wait: deprecated: - message: "lowercase methods have been superceded by uppercase ones" + message: "lowercase methods have been superseded by uppercase ones" replace: - "Wait(%1)" args: diff --git a/selene-lib/tests/lints/deprecated/deprecated_functions.stderr b/selene-lib/tests/lints/deprecated/deprecated_functions.stderr index a1864d6b..724687ff 100644 --- a/selene-lib/tests/lints/deprecated/deprecated_functions.stderr +++ b/selene-lib/tests/lints/deprecated/deprecated_functions.stderr @@ -12,7 +12,7 @@ error[deprecated]: standard library function `table.getn` is deprecated 2 │ print(table.getn(x)) │ ^^^^^^^^^^^^^ │ - = `table.getn` has been superceded by #. + = `table.getn` has been superseded by #. = try: #x error[deprecated]: standard library function `table.foreach` is deprecated From a6c7a1e6aed3c8a18d48fd1492c48973f66fb991 Mon Sep 17 00:00:00 2001 From: Benedikt Rips Date: Fri, 29 Sep 2023 06:21:27 +0200 Subject: [PATCH 3/9] Remove version constraints on container images (#549) This fixes errors during the build of this image, occuring due to non-existent version tags. --- Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index dea4aae4..5e3abffa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,22 @@ -FROM rust:1.64-bullseye AS selene-builder +ARG RUST_VERSION="1" + +FROM rust:${RUST_VERSION}-bullseye AS selene-builder RUN apt-get update && \ apt-get upgrade -y && \ apt-get install g++ && \ cargo install --branch main --git https://github.com/Kampfkarren/selene selene -FROM rust:1.64-bullseye AS selene-light-builder +FROM rust:${RUST_VERSION}-bullseye AS selene-light-builder RUN apt-get update && \ apt-get upgrade -y && \ apt-get install g++ && \ cargo install --no-default-features --branch main --git https://github.com/Kampfkarren/selene selene -FROM rust:1.64-alpine3.14 AS selene-musl-builder +FROM rust:${RUST_VERSION}-alpine AS selene-musl-builder RUN apk add g++ && \ cargo install --branch main --git https://github.com/Kampfkarren/selene selene -FROM rust:1.64-alpine3.14 AS selene-light-musl-builder +FROM rust:${RUST_VERSION}-alpine AS selene-light-musl-builder RUN apk add g++ && \ cargo install --no-default-features --branch main --git https://github.com/Kampfkarren/selene selene @@ -32,4 +34,4 @@ CMD ["/selene"] FROM bash AS selene-light-musl COPY --from=selene-light-musl-builder /usr/local/cargo/bin/selene / -CMD ["/selene"] +CMD ["/selene"] \ No newline at end of file From 8f4716805f3dc7d0fe98d0d6db50b4f1dbee3ee4 Mon Sep 17 00:00:00 2001 From: Chris Chang <51393127+chriscerie@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:25:49 -0700 Subject: [PATCH 4/9] Allow suspected manual table clone when variable and loop are defined at different depths (#546) Closes #502. --- CHANGELOG.md | 1 + docs/src/lints/manual_table_clone.md | 1 + selene-lib/src/ast_util/loop_tracker.rs | 3 ++ selene-lib/src/lints/manual_table_clone.rs | 34 ++++++++++++------- .../manual_table_clone/false_positive.lua | 28 +++++++++++++++ .../manual_table_clone/false_positive.stderr | 22 ++++++------ 6 files changed, 65 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd5f5c35..b6015620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Moved `math.log` second argument addition from Lua 5.3 std lib to 5.2 std lib - `undefined_variable` now correctly errors when defining multiple methods in undefined tables - Corrected `os.exit` definition in Lua 5.2 standard library +- Fixed `manual_table_clone` incorrectly warning when loop and table are defined at different depths ## [0.25.0](https://github.com/Kampfkarren/selene/releases/tag/0.25.0) - 2023-03-12 ### Added diff --git a/docs/src/lints/manual_table_clone.md b/docs/src/lints/manual_table_clone.md index 52559832..0c88d5da 100644 --- a/docs/src/lints/manual_table_clone.md +++ b/docs/src/lints/manual_table_clone.md @@ -27,6 +27,7 @@ Very little outside this exact pattern is matched. This is the list of circumsta - Any usage of the output variable in between the definition and the loop (as determined by position in code). - If the input variable is not a plain locally initialized variable. For example, `self.state[key] = value` will not lint. - If the input variable is not defined as a completely empty table. +- If the loop and input variable are defined at different depths. --- diff --git a/selene-lib/src/ast_util/loop_tracker.rs b/selene-lib/src/ast_util/loop_tracker.rs index de35f4b3..dde70c92 100644 --- a/selene-lib/src/ast_util/loop_tracker.rs +++ b/selene-lib/src/ast_util/loop_tracker.rs @@ -1,3 +1,6 @@ +// Remove this once loop_tracker is used again +#![allow(dead_code)] + use full_moon::{ast, node::Node, visitors::Visitor}; #[derive(Debug, Clone, Copy)] diff --git a/selene-lib/src/lints/manual_table_clone.rs b/selene-lib/src/lints/manual_table_clone.rs index 731fa8ca..73b0b198 100644 --- a/selene-lib/src/lints/manual_table_clone.rs +++ b/selene-lib/src/lints/manual_table_clone.rs @@ -3,12 +3,10 @@ use full_moon::{ visitors::Visitor, }; -use crate::ast_util::{ - expression_to_ident, range, scopes::AssignedValue, strip_parentheses, LoopTracker, -}; +use crate::ast_util::{expression_to_ident, range, scopes::AssignedValue, strip_parentheses}; use super::*; -use std::convert::Infallible; +use std::{collections::HashSet, convert::Infallible}; pub struct ManualTableCloneLint; @@ -34,9 +32,9 @@ impl Lint for ManualTableCloneLint { let mut visitor = ManualTableCloneVisitor { matches: Vec::new(), - loop_tracker: LoopTracker::new(ast), scope_manager: &ast_context.scope_manager, - stmt_begins: Vec::new(), + completed_stmt_begins: Vec::new(), + inside_stmt_begins: HashSet::new(), }; visitor.visit_ast(ast); @@ -92,9 +90,9 @@ impl ManualTableCloneMatch { struct ManualTableCloneVisitor<'ast> { matches: Vec, - loop_tracker: LoopTracker, scope_manager: &'ast ScopeManager, - stmt_begins: Vec, + completed_stmt_begins: Vec, + inside_stmt_begins: HashSet, } #[derive(Debug)] @@ -214,7 +212,7 @@ impl ManualTableCloneVisitor<'_> { ) -> bool { debug_assert!(assigment_start > definition_end); - for &stmt_begin in self.stmt_begins.iter() { + for &stmt_begin in self.completed_stmt_begins.iter() { if stmt_begin > definition_end { return true; } else if stmt_begin > assigment_start { @@ -224,6 +222,13 @@ impl ManualTableCloneVisitor<'_> { false } + + fn get_depth_at_byte(&self, byte: usize) -> usize { + self.inside_stmt_begins + .iter() + .filter(|&&start| start < byte) + .count() + } } fn has_filter_comment(for_loop: &ast::GenericFor) -> bool { @@ -374,9 +379,7 @@ impl Visitor for ManualTableCloneVisitor<'_> { let (position_start, position_end) = range(node); - if self.loop_tracker.depth_at_byte(position_start) - != self.loop_tracker.depth_at_byte(*definition_start) - { + if self.get_depth_at_byte(*definition_start) != self.get_depth_at_byte(position_start) { return; } @@ -401,8 +404,13 @@ impl Visitor for ManualTableCloneVisitor<'_> { }); } + fn visit_stmt(&mut self, stmt: &ast::Stmt) { + self.inside_stmt_begins.insert(range(stmt).0); + } + fn visit_stmt_end(&mut self, stmt: &ast::Stmt) { - self.stmt_begins.push(range(stmt).0); + self.completed_stmt_begins.push(range(stmt).0); + self.inside_stmt_begins.remove(&range(stmt).0); } } diff --git a/selene-lib/tests/lints/manual_table_clone/false_positive.lua b/selene-lib/tests/lints/manual_table_clone/false_positive.lua index 52961fd4..200e62a6 100644 --- a/selene-lib/tests/lints/manual_table_clone/false_positive.lua +++ b/selene-lib/tests/lints/manual_table_clone/false_positive.lua @@ -39,6 +39,34 @@ local function falsePositive3(t) return result end +local result4 = {} +local function falsePositive4(t) + for key, value in t do + result3[key] = value + end +end + +local result5 = {} +local function falsePositive5(t) + local function f() end + + for key, value in t do + result4[key] = value + end +end + +local function falsePositive6(t) + local result = {} + + if b then return end + + if a then + for key, value in t do + result4[key] = value + end + end +end + local function notFalsePositive1(t) local result = {} diff --git a/selene-lib/tests/lints/manual_table_clone/false_positive.stderr b/selene-lib/tests/lints/manual_table_clone/false_positive.stderr index 356c9224..1af67e80 100644 --- a/selene-lib/tests/lints/manual_table_clone/false_positive.stderr +++ b/selene-lib/tests/lints/manual_table_clone/false_positive.stderr @@ -1,24 +1,24 @@ error[manual_table_clone]: manual implementation of table.clone - ┌─ false_positive.lua:49:2 + ┌─ false_positive.lua:77:2 │ -43 │ local result = {} +71 │ local result = {} │ ----------------- remove this definition · -49 │ ╭ for key, value in pairs(t) do -50 │ │ result[key] = value -51 │ │ end +77 │ ╭ for key, value in pairs(t) do +78 │ │ result[key] = value +79 │ │ end │ ╰───────^ │ = try `local result = table.clone(t)` error[manual_table_clone]: manual implementation of table.clone - ┌─ false_positive.lua:58:3 + ┌─ false_positive.lua:86:3 │ -58 │ ╭ local result = {} -59 │ │ -60 │ │ for key, value in pairs(t) do -61 │ │ result[key] = value -62 │ │ end +86 │ ╭ local result = {} +87 │ │ +88 │ │ for key, value in pairs(t) do +89 │ │ result[key] = value +90 │ │ end │ ╰───────────^ │ = try `local result = table.clone(t)` From cbb0503e11a05618c5b5cdd4c7a5b892f78a0ec3 Mon Sep 17 00:00:00 2001 From: Chris Chang <51393127+chriscerie@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:32:36 -0700 Subject: [PATCH 5/9] Fix clippy error (#562) --- selene-lib/src/lints/if_same_then_else.rs | 4 ++-- selene/src/validate_config.rs | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/selene-lib/src/lints/if_same_then_else.rs b/selene-lib/src/lints/if_same_then_else.rs index 502e1bbf..c8874b9c 100644 --- a/selene-lib/src/lints/if_same_then_else.rs +++ b/selene-lib/src/lints/if_same_then_else.rs @@ -55,8 +55,8 @@ impl Visitor for IfSameThenElseVisitor { fn visit_if(&mut self, if_block: &ast::If) { let else_ifs = if_block .else_if() - .map(|else_ifs| else_ifs.iter().collect()) - .unwrap_or_else(Vec::new); + .map(|else_ifs| else_ifs.iter().collect::>()) + .unwrap_or_default(); let mut blocks = Vec::with_capacity(2 + else_ifs.len()); blocks.push(if_block.block()); diff --git a/selene/src/validate_config.rs b/selene/src/validate_config.rs index b552e306..074522ab 100644 --- a/selene/src/validate_config.rs +++ b/selene/src/validate_config.rs @@ -120,7 +120,9 @@ pub fn validate_config( ErrorRange { start, end } }); - let Err(error) = crate::standard_library::collect_standard_library(&config, config.std(), directory, &None) else { + let Err(error) = + crate::standard_library::collect_standard_library(&config, config.std(), directory, &None) + else { return Ok(()); }; @@ -185,16 +187,16 @@ mod tests { let Err(validate_result) = validate_config(&config_path, &config_contents, &validate_config_test.path()) - else { - tests_pass = false; + else { + tests_pass = false; - eprintln!( - "{} did not error", - validate_config_test.file_name().to_string_lossy() - ); + eprintln!( + "{} did not error", + validate_config_test.file_name().to_string_lossy() + ); - continue; - }; + continue; + }; let mut rich_output_buffer = termcolor::NoColor::new(Vec::new()); validate_result From de703190e5482e011b0ca0267be8821ee35c357c Mon Sep 17 00:00:00 2001 From: Chris Chang <51393127+chriscerie@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:34:10 -0700 Subject: [PATCH 6/9] Fix compilation errors (#564) Fixes [error](https://github.com/Kampfkarren/selene/actions/runs/6647693372/job/18063533594?pr=563) introduced by https://github.com/rust-lang/rust/pull/116734 as well as warning introduced by https://github.com/rust-lang/rust/commit/482275b19422b871b986ec0400257a9b80080218 --- selene-lib/src/ast_util/mod.rs | 1 - selene-lib/src/lints/high_cyclomatic_complexity.rs | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/selene-lib/src/ast_util/mod.rs b/selene-lib/src/ast_util/mod.rs index 7947d18e..ff7ecf4e 100644 --- a/selene-lib/src/ast_util/mod.rs +++ b/selene-lib/src/ast_util/mod.rs @@ -16,7 +16,6 @@ mod strip_parentheses; pub mod visit_nodes; pub use extract_static_token::extract_static_token; -pub use loop_tracker::LoopTracker; pub use purge_trivia::purge_trivia; pub use side_effects::HasSideEffects; pub use strip_parentheses::strip_parentheses; diff --git a/selene-lib/src/lints/high_cyclomatic_complexity.rs b/selene-lib/src/lints/high_cyclomatic_complexity.rs index d3dd36d7..cb5104d0 100644 --- a/selene-lib/src/lints/high_cyclomatic_complexity.rs +++ b/selene-lib/src/lints/high_cyclomatic_complexity.rs @@ -131,10 +131,9 @@ fn count_suffix_complexity(suffix: &ast::Suffix, starting_complexity: u16) -> u1 ast::Suffix::Index(ast::Index::Brackets { expression, .. }) => { complexity = count_expression_complexity(expression, complexity) } - #[cfg_attr( - feature = "force_exhaustive_checks", - deny(non_exhaustive_omitted_patterns) - )] + ast::Suffix::Index(ast::Index::Dot { .. }) => { + // Dot indexing doesn't contribute to complexity + } ast::Suffix::Call(call) => match call { ast::Call::AnonymousCall(arguments) => { complexity = count_arguments_complexity(arguments, complexity) From 2df3dd5afd3cc42c2ce0d620b4aff0e061f34a7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:52:45 -0700 Subject: [PATCH 7/9] Bump webpki from 0.22.0 to 0.22.4 (#563) Bumps [webpki](https://github.com/briansmith/webpki) from 0.22.0 to 0.22.4.
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=webpki&package-manager=cargo&previous-version=0.22.0&new-version=0.22.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/Kampfkarren/selene/network/alerts).
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 120 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0309ef6b..273398c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -863,12 +863,26 @@ dependencies = [ "cc", "libc", "once_cell", - "spin", - "untrusted", + "spin 0.5.2", + "untrusted 0.7.1", "web-sys", "winapi", ] +[[package]] +name = "ring" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9babe80d5c16becf6594aa32ad2be8fe08498e7ae60b77de8df700e67f191d7e" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -891,7 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", - "ring", + "ring 0.16.20", "sct", "webpki", ] @@ -926,8 +940,8 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ - "ring", - "untrusted", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -1071,6 +1085,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "strsim" version = "0.8.0" @@ -1365,6 +1385,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "ureq" version = "2.6.2" @@ -1490,12 +1516,12 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.0" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring", - "untrusted", + "ring 0.17.3", + "untrusted 0.9.0", ] [[package]] @@ -1544,43 +1570,109 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.39.0", + "windows_i686_gnu 0.39.0", + "windows_i686_msvc 0.39.0", + "windows_x86_64_gnu 0.39.0", + "windows_x86_64_msvc 0.39.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "yansi" version = "0.5.1" From a38a7bf349b7f54e600fb3ed24668da7ce709746 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 8 Nov 2023 09:34:02 -0800 Subject: [PATCH 8/9] Add bit32.byteswap to Luau standard library (#567) Adds bit32.byteswap to the Luau standard library. --- CHANGELOG.md | 1 + selene-lib/default_std/luau.yml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6015620..bcee94f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added `no-exclude` cli flag to disable excludes. - When given in standard library format, additional information now shows up in `incorrect_standard_library_use` missing required parameter errors. - Added new [`mixed_table` lint](https://kampfkarren.github.io/selene/lints/mixed_table.html), which will warn against mixed tables. +- Added `bit32.byteswap` to Luau standard library ### Fixed - `string.pack` and `string.unpack` now have proper function signatures in the Lua 5.3 standard library. diff --git a/selene-lib/default_std/luau.yml b/selene-lib/default_std/luau.yml index 8d41cb45..c4077b56 100644 --- a/selene-lib/default_std/luau.yml +++ b/selene-lib/default_std/luau.yml @@ -29,6 +29,10 @@ globals: args: - type: "..." must_use: true + bit32.byteswap: + args: + - type: number + must_use: true bit32.countlz: args: - type: number From 92afa63e6e9477f5e148e424a0c144cfce82e614 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 8 Nov 2023 10:35:08 -0800 Subject: [PATCH 9/9] Add buffer library to Luau standard library (#566) This adds the buffer library to the Luau standard library. I tried my best to sort them in alphabetical order but it was done by hand, so there's a chance I made a mistake. --- CHANGELOG.md | 1 + selene-lib/default_std/luau.yml | 148 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcee94f9..0ddc0eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - When given in standard library format, additional information now shows up in `incorrect_standard_library_use` missing required parameter errors. - Added new [`mixed_table` lint](https://kampfkarren.github.io/selene/lints/mixed_table.html), which will warn against mixed tables. - Added `bit32.byteswap` to Luau standard library +- Added `buffer` library to Luau standard library ### Fixed - `string.pack` and `string.unpack` now have proper function signatures in the Lua 5.3 standard library. diff --git a/selene-lib/default_std/luau.yml b/selene-lib/default_std/luau.yml index c4077b56..0243c110 100644 --- a/selene-lib/default_std/luau.yml +++ b/selene-lib/default_std/luau.yml @@ -76,6 +76,154 @@ globals: - type: number - type: number must_use: true + buffer.copy: + args: + - type: + display: buffer + - type: number + - type: + display: buffer + - required: false + type: number + - required: false + type: number + buffer.create: + args: + - type: number + must_use: true + buffer.fill: + args: + - type: + display: buffer + - type: number + - type: number + - required: false + type: number + buffer.fromstring: + args: + - type: string + must_use: true + buffer.len: + args: + - type: + display: buffer + must_use: true + buffer.readf32: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readf64: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readi8: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readi16: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readi32: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readstring: + args: + - type: + display: buffer + - type: number + - type: number + must_use: true + buffer.readu8: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readu16: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.readu32: + args: + - type: + display: buffer + - type: number + must_use: true + buffer.tostring: + args: + - type: + display: buffer + must_use: true + buffer.writef32: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writef64: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writei8: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writei16: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writei32: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writestring: + args: + - type: + display: buffer + - type: number + - type: string + - required: false + type: number + buffer.writeu8: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writeu16: + args: + - type: + display: buffer + - type: number + - type: number + buffer.writeu32: + args: + - type: + display: buffer + - type: number + - type: number collectgarbage: args: - type: