From 3d333ffaad20418426c2f1967b54f46c2c988461 Mon Sep 17 00:00:00 2001 From: jeparlefrancais Date: Sun, 24 Nov 2024 16:44:33 -0500 Subject: [PATCH 1/3] Fix `rename_variables` rule to rename type namespaces --- src/rules/rename_variables/rename_processor.rs | 10 +++++++++- tests/rule_tests/rename_variables.rs | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rules/rename_variables/rename_processor.rs b/src/rules/rename_variables/rename_processor.rs index 930a7a78..e3dfef38 100644 --- a/src/rules/rename_variables/rename_processor.rs +++ b/src/rules/rename_variables/rename_processor.rs @@ -1,4 +1,4 @@ -use crate::nodes::{Expression, Identifier, LocalFunctionStatement}; +use crate::nodes::{Expression, Identifier, LocalFunctionStatement, TypeField}; use crate::process::utils::{identifier_permutator, CharPermutator}; use crate::process::{utils::KEYWORDS, NodeProcessor, Scope}; @@ -164,6 +164,14 @@ impl NodeProcessor for RenameProcessor { variable.set_name(obfuscated_name); } } + + fn process_type_field(&mut self, type_field: &mut TypeField) { + if let Some(obfuscated_name) = + self.get_obfuscated_name(type_field.get_namespace().get_name()) + { + type_field.mutate_namespace().set_name(obfuscated_name); + } + } } #[cfg(test)] diff --git a/tests/rule_tests/rename_variables.rs b/tests/rule_tests/rename_variables.rs index a2e9335f..eef420ef 100644 --- a/tests/rule_tests/rename_variables.rs +++ b/tests/rule_tests/rename_variables.rs @@ -44,6 +44,7 @@ test_rule!( function_expression_parameters_reference("return function(foo, bar) return foo + bar end") => "return function(a, b) return a + b end", recycle_previous_identifiers("do local foo end local foo") => "do local a end local a", + reexported_type_field("local types = require('./types') export type Oof = types.Oof") => "local a = require('./types') export type Oof = a.Oof", ); test_rule!( @@ -88,6 +89,7 @@ test_rule!( function_expression_parameters_reference("return function(foo, bar) return foo + bar end") => "return function(a, b) return a + b end", recycle_previous_identifiers("do local foo end local foo") => "do local a end local a", + reexported_type_field("local types = require('./types') export type Oof = types.Oof") => "local a = require('./types') export type Oof = a.Oof", ); test_rule_without_effects!( From 980fd3273f13adffa4fe9d673264892299ba6b29 Mon Sep 17 00:00:00 2001 From: jeparlefrancais Date: Sun, 24 Nov 2024 16:49:24 -0500 Subject: [PATCH 2/3] add entry to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfab396b..2f395547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* fix `rename_variables` rule to rename module names in types ([#233](https://github.com/seaofvoices/darklua/pull/233)) * fix string encoding containing unicode characters taking more than 1 byte ([#232](https://github.com/seaofvoices/darklua/pull/232)) * fix `append_text_comment` to not add an extra space to comments ([#231](https://github.com/seaofvoices/darklua/pull/231)) * add rule to remove floor divisions (`remove_floor_division`) ([#230](https://github.com/seaofvoices/darklua/pull/230)) From 7f80cf956487908f5def073becf1b279bf20bc75 Mon Sep 17 00:00:00 2001 From: jeparlefrancais Date: Sun, 24 Nov 2024 16:53:35 -0500 Subject: [PATCH 3/3] add test case --- tests/rule_tests/rename_variables.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/rule_tests/rename_variables.rs b/tests/rule_tests/rename_variables.rs index eef420ef..dad84376 100644 --- a/tests/rule_tests/rename_variables.rs +++ b/tests/rule_tests/rename_variables.rs @@ -45,6 +45,8 @@ test_rule!( => "return function(a, b) return a + b end", recycle_previous_identifiers("do local foo end local foo") => "do local a end local a", reexported_type_field("local types = require('./types') export type Oof = types.Oof") => "local a = require('./types') export type Oof = a.Oof", + type_variable_type_field("local React = require('@pkg/@jsdotlua/react') type Props = { children: React.ReactNode }") + => "local a = require('@pkg/@jsdotlua/react') type Props = { children: a.ReactNode }", ); test_rule!( @@ -90,6 +92,8 @@ test_rule!( => "return function(a, b) return a + b end", recycle_previous_identifiers("do local foo end local foo") => "do local a end local a", reexported_type_field("local types = require('./types') export type Oof = types.Oof") => "local a = require('./types') export type Oof = a.Oof", + type_variable_type_field("local React = require('@pkg/@jsdotlua/react') type Props = { children: React.ReactNode }") + => "local a = require('@pkg/@jsdotlua/react') type Props = { children: a.ReactNode }", ); test_rule_without_effects!(