### Process Lua Files with Custom Configuration Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md This example shows how to process Lua files from 'src' to 'processed-src' while explicitly specifying a custom configuration file using the '--config' or '-c' argument. ```Bash darklua process src processed-src --config ./path/config.json # or the shorter version: darklua process src processed-src -c ./path/config.json ``` -------------------------------- ### Get General darklua Help Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md This command displays a list of all available commands and options for the darklua command-line tool. ```Bash darklua help ``` -------------------------------- ### Minify Lua Files Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md This example demonstrates using the 'minify' command to reduce the size of all Lua scripts in a 'src' folder, outputting the minified versions into a new 'minified-src' folder. ```Bash darklua minify src minified-src ``` -------------------------------- ### Get Specific darklua Command Help Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md This command provides detailed help and usage information for a specific darklua command, such as 'process', by appending '--help' or '-h'. ```Bash darklua process --help ``` -------------------------------- ### Process Lua Files with Default Configuration Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md This example demonstrates processing all Lua files within a 'src' folder into a 'processed-src' folder. darklua automatically uses a configuration file if found in the current directory. ```Bash darklua process src processed-src ``` -------------------------------- ### darklua Process Command Syntax Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md The 'process' command applies rules to Lua files from an input path and generates processed code at an output path. It supports an optional configuration file. ```Bash darklua process optional arguments: -c, --config Path to a configuration file ``` -------------------------------- ### darklua Minify Command Syntax Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md The 'minify' command reformats Lua code to reduce its size, measured in bytes. It can process a single file or an entire directory, maintaining the file hierarchy. ```Bash darklua minify optional arguments: --column-span The maximum number of characters that should be written on a line ``` -------------------------------- ### Install darklua using Cargo Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/installation/index.md Instructions for installing darklua using the Rust package manager, Cargo. This includes installing the stable version from crates.io and the latest version directly from the Git repository. ```bash cargo install darklua ``` ```bash cargo install --git https://github.com/seaofvoices/darklua.git ``` -------------------------------- ### Install darklua with Foreman Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/installation/index.md Adds darklua as a dependency in the `foreman.toml` configuration file, specifying the GitHub repository and a specific version. ```toml darklua = { github = "seaofvoices/darklua", version = "=0.13.1" } ``` -------------------------------- ### Install JavaScript test dependencies Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Installs all required Node.js packages and dependencies for the `javascript-tests` suite using npm, preparing the environment for testing. ```Bash npm install ``` -------------------------------- ### darklua Convert Command Syntax Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/getting-started/index.md The 'convert' command transforms a data file (JSON, JSON5, YAML, or TOML) into a Lua file. If no output path is provided, the Lua code is printed to the console. ```Bash darklua convert [output-path] optional arguments: -f, --format {json, yaml, toml} ``` -------------------------------- ### Darklua Configuration File Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/config/index.md Illustrates the structure and available options for a darklua configuration file, including generator settings, bundle configurations (modules identifier, excludes, require mode), and a list of transformation rules with their default values and parameter examples. ```JSON5 { // Output code in different ways depending on the given generator generator: "retain_lines", // default value bundle: { // Identifier used by darklua to store the bundled modules modules_identifier: "__DARKLUA_BUNDLE_MODULES", // To avoid bundling certain paths, insert patterns into the list to exclude // them (see https://github.com/olson-sean-k/wax/blob/master/README.md#patterns // for details about the syntax) excludes: [], // Configure how requires are interpreted require_mode: { // Currently, the only supported require mode is `path` name: "path", // When requiring folders, require the file named like this value inside of it module_folder_name: "init", // Provide paths that can be required with a specific prefix sources: { // Map strings to paths relative to the configuration files itself // for example, to support requires of Wally packages as `pkg/PackageName`, // map `pkg` to a path to the `Packages` folder created by Wally: pkg: "./Packages" }, // Enable or disable finding `.luaurc` files to load source aliases use_luau_configuration: true // default value } }, // Define the rules that will transform the Lua code. // If you do not provide this field, the default list of rules is // going to be executed. rules: [ "remove_comments", "remove_spaces", // For rules with parameters, use the object notation to specify // the values to override { rule: "inject_global_value", identifier: "DEBUG", value: false }, "remove_nil_declaration", "compute_expression", "remove_unused_if_branch", "filter_after_early_return", "remove_empty_do" ] } ``` -------------------------------- ### Install darklua with Foreman Source: https://github.com/seaofvoices/darklua/blob/main/README.md This TOML snippet adds darklua as a dependency in your `foreman.toml` file, specifying the GitHub repository and a precise version for installation. ```TOML darklua = { github = "seaofvoices/darklua", version = "=0.13.1" } ``` -------------------------------- ### Installing Rust snapshot testing utility (cargo-insta) Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md Install `cargo-insta` to manage and review snapshot tests. This utility is essential for working with darklua's snapshot testing framework. ```Shell cargo install cargo-insta ``` -------------------------------- ### Installing Rust linter (Clippy) Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md Install `clippy`, a static analysis tool for Rust. Clippy helps identify and avoid common programming mistakes and bad practices in Rust code. ```Shell rustup component add clippy ``` -------------------------------- ### Start Gatsby development server Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md Navigate into the newly created Gatsby project directory and launch the local development server. This makes the site accessible in your browser, typically at http://localhost:8000. ```Shell cd my-blog-starter/ gatsby develop ``` -------------------------------- ### Lua Path-Based Require Examples Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Illustrates how `path` require mode interprets `require` calls, supporting both relative paths (e.g., `./Config`) and module paths (e.g., `Packages/Promise`). ```lua local Config = require("./Config") local Promise = require("Packages/Promise") ``` -------------------------------- ### Install darklua with Aftman Source: https://github.com/seaofvoices/darklua/blob/main/README.md This command uses Aftman to add the darklua tool from its GitHub repository to your project, making it available for use. ```Shell aftman add seaofvoices/darklua ``` -------------------------------- ### Installing Rust code formatter (rustfmt) Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md Install `rustfmt` to automatically format Rust code. This tool ensures consistent code style across the project, which is enforced on merge requests. ```Shell rustup component add rustfmt ``` -------------------------------- ### Installing Lua dependencies for end-to-end tests Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md Install the required Lua packages `luafilesystem` and `busted` using Luarocks. These packages are necessary to run darklua's end-to-end tests. ```Shell luarocks install luafilesystem luarocks install busted ``` -------------------------------- ### Gatsby project top-level file and directory structure overview Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md An overview of the essential files and directories found in a Gatsby project. This includes standard Node.js project components like `node_modules`, `package.json`, and `README.md`, along with Gatsby-specific configuration files and the source code directory. - `/node_modules`: Contains all installed npm packages. - `/src`: Holds front-end source code, including components and page templates. - `.gitignore`: Specifies files and directories to be ignored by Git. - `.prettierrc`: Configuration file for Prettier code formatter. - `LICENSE`: Placeholder for project licensing information. - `package-lock.json`: Records exact versions of npm dependencies. - `package.json`: Manifest file for Node.js projects, listing metadata and dependencies. - `README.md`: Provides useful reference information about the project. ```Text . ├── node_modules ├── src ├── .gitignore ├── .prettierrc ├── gatsby-browser.js ├── gatsby-config.js ├── gatsby-node.js ├── gatsby-ssr.js ├── LICENSE ├── package-lock.json ├── package.json └── README.md ``` -------------------------------- ### JSON to Lua Data Conversion Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Demonstrates how Darklua's `path` require mode can automatically convert a JSON file into a corresponding Lua table structure during the bundling process. ```json { "experienceActivation_singleton": "experienceActivation", "experienceConfiguration_singleton": "experienceConfiguration", "experience_singleton": { "experience": { "assetId": 3296599132, "startPlaceId": 8667346609 } }, "placeConfiguration_start": "placeConfiguration", "placeFile_start": { "placeFile": { "version": 2 } }, "place_start": { "place": { "assetId": 8667346609 } } } ``` ```lua { experienceActivation_singleton = "experienceActivation", experienceConfiguration_singleton = "experienceConfiguration", experience_singleton = { experience = { assetId = 3296599132, startPlaceId = 8667346609, }, }, placeConfiguration_start = "placeConfiguration", placeFile_start = { placeFile = { version = 2, }, }, place_start = { place = { assetId = 8667346609, }, }, } ``` -------------------------------- ### darklua remove_comments Rule Configuration with Exception Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_comments.md Example JSON5 configuration for the 'remove_comments' rule, demonstrating how to use the 'except' parameter to prevent removal of comments starting with '--!' (e.g., for Luau native compilation triggers). ```JSON5 { rule: "remove_comments", except: ["^--!"] } ``` -------------------------------- ### Darklua inject_global_value Rule Configuration Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/inject_global_value.md Example JSON5 configuration for the `inject_global_value` rule, demonstrating how to set an identifier and read a value from an environment variable instead of a direct value. ```json5 { rule: "inject_global_value", identifier: "GLOBAL", env: "SOME_VARIABLE", } ``` -------------------------------- ### Lua Static Expression Examples Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/compute_expression.md Examples demonstrating various static expressions that can be computed and replaced by the darklua rule, including arithmetic, boolean, and string operations. ```Lua return 1 + 1 ``` ```Lua return 10 * 10 ``` ```Lua return true and 'true' or 'not true' ``` ```Lua return 'Hello' .. ' friend!' ``` -------------------------------- ### Darklua Rule Input Examples (Front Matter) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_unused_if_branch.md Initial examples from the front matter demonstrating various 'if' expressions and statements that can be optimized by the darklua rule. ```lua return if true then value else default ``` ```lua return if false then value else default ``` ```lua if false then local sum = 0 for _, element in ipairs(array) do sum = sum + element end print("sum of array:", sum) end ``` -------------------------------- ### Lua Example: Empty Do Blocks for Removal Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_empty_do.md An example of Lua code containing empty `do` blocks that the `darklua` rule will identify and remove. ```Lua do end do do end end return {} ``` -------------------------------- ### Lua Floor Division Operator Examples Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_floor_division.md Examples demonstrating the Lua floor division operator (`//`) and its compound assignment (`//=`) which are targeted for transformation by this rule. ```Lua return variable // divider variable //= 5 ``` -------------------------------- ### Convert TOML Cargo Project Configuration to Lua Table Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Illustrates the conversion of a Rust Cargo project's TOML configuration file (Cargo.toml) into a Lua table. This example highlights how complex nested TOML structures, including package metadata, dependencies, features, and build profiles, are accurately represented in Lua. ```toml [package] name = "darklua" version = "0.16.0" edition = "2018" readme = "README.md" description = "Transform Lua scripts" repository = "https://github.com/seaofvoices/darklua" homepage = "https://darklua.com" license = "MIT" keywords = ["lua", "obsfucation", "minify"] exclude = ["site"] [badges] github = { repository = "seaofvoices/darklua" } [lib] name = "darklua_core" path = "src/lib.rs" [[bin]] name = "darklua" path = "src/bin.rs" [features] tracing = ["dep:tracing"] [dependencies] clap = { version = "4.1.1", features = ["derive"] } durationfmt = "0.1.1" elsa = "1.7.0" env_logger = "0.9.0" full_moon = { version = "0.16.2", features = ["roblox"] } json5 = "0.4" log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.92" serde_yaml = "0.9.17" toml = "0.7.2" tracing = { version = "0.1", optional = true } wax = "0.5.0" [dev-dependencies] assert_cmd = "2.0.4" criterion = { version = "0.4", features = ["html_reports"] } include_dir = "0.7.3" insta = { version = "1.29.0", features = ["json", "filters"] } paste = "1.0" pretty_assertions = "0.7.2" rand = "0.7.3" rand_distr = "0.2.2" serde_bytes = "0.11" tempfile = "3.5.0" tracing-subscriber = "0.3.16" tracing-tracy = "0.10.1" [target.'cfg(target_arch = "wasm32")'.dependencies] node-sys = "0.4.2" web-sys = { version = "0.3.60", features = ["Window", "Performance"] } [profile.dev.package.full_moon] opt-level = 3 [[bench]] name = "process_bench" harness = false [[bench]] name = "parse_bench" harness = false ``` ```lua { bench = { { harness = false, name = "process_bench" }, { harness = false, name = "parse_bench" }, }, bin = { { name = "darklua", path = "src/bin.rs" }, }, badges = { github = { repository = "seaofvoices/darklua" }, }, dependencies = { durationfmt = "0.1.1", elsa = "1.7.0", env_logger = "0.9.0", json5 = "0.4", log = "0.4", serde_json = "1.0.92", serde_yaml = "0.9.17", toml = "0.7.2", wax = "0.5.0", clap = { features = { "derive" }, version = "4.1.1" }, full_moon = { features = { "roblox" }, version = "0.16.2" }, serde = { features = { "derive" }, version = "1.0" }, tracing = { optional = true, version = "0.1" }, }, ["dev-dependencies"] = { assert_cmd = "2.0.4", include_dir = "0.7.3", paste = "1.0", pretty_assertions = "0.7.2", rand = "0.7.3", rand_distr = "0.2.2", serde_bytes = "0.11", tempfile = "3.5.0", ["tracing-subscriber"] = "0.3.16", ["tracing-tracy"] = "0.10.1", criterion = { features = { "html_reports" }, version = "0.4" }, insta = { features = { "json", "filters" }, version = "1.29.0" }, }, features = { tracing = { "dep:tracing" }, }, lib = { name = "darklua_core", path = "src/lib.rs" }, package = { description = "Transform Lua scripts", edition = "2018", exclude = { "site" }, homepage = "https://darklua.com", keywords = { "lua", "obsfucation", "minify" }, license = "MIT", name = "darklua", readme = "README.md", repository = "https://github.com/seaofvoices/darklua", version = "0.16.0", }, profile = { dev = { package = { full_moon = { ["opt-level"] = 3 } }, }, }, target = { ['cfg(target_arch = "wasm32")'] = { dependencies = { ["node-sys"] = "0.4.2", ["web-sys"] = { features = { "Window", "Performance" }, version = "0.3.60" }, }, }, }, } ``` -------------------------------- ### Darklua inject_global_value Rule Lua Usage Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/inject_global_value.md Example Lua code demonstrating the effect of the `inject_global_value` rule after processing, showing how injected global variables are used in conditional statements. ```lua if _G.AMOUNT > 10 or _G.CONSTANT ~= nil then --[[ ... ]] end ``` -------------------------------- ### Darklua Rule Examples: Interpolated String Conversion Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_interpolated_string.md Illustrative examples of how the darklua rule processes and converts various interpolated strings into `string.format` calls. ```Lua return `abc` ``` ```Lua return `` ``` ```Lua return `+{value} (in seconds)` ``` ```Lua return `Total = {#elements}` ``` -------------------------------- ### Exclude Paths from Darklua Bundle Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Configuration example demonstrating how to use the `excludes` field to prevent specific files or patterns (e.g., `@lune/**`) from being included in the bundled output. ```json5 { bundle: { require_mode: "path", excludes: ["@lune/**"], }, } ``` -------------------------------- ### Lua Example: assert Function Call Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_assertions.md A typical Lua `assert` function call. This example demonstrates the syntax of `assert` with a condition and an error message, which is the target for removal by the darklua rule. ```Lua assert(condition, 'condition is incorrect!') ``` -------------------------------- ### Darklua: Append Comment at File Start Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/append_text_comment.md Demonstrates configuring the `append_text_comment` rule to insert a comment with specific text at the beginning of a Lua file. ```JSON [{"rule": "append_text_comment", "text": "!native"}] ``` ```Lua print('Print from module') ``` -------------------------------- ### Specify Rule by Name (Default Parameters) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/rules/index.md Demonstrates the shortest format for defining a darklua rule in the configuration file, where only the rule name is provided, and all its parameters use their default values. This example shows the `remove_empty_do` rule, which has no parameters. ```JSON5 { rules: ["remove_empty_do"], } ``` -------------------------------- ### Lua Example: Array Average Function for darklua Processing Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_spaces.md A Lua function `getAverage` that calculates the average of numbers in an array. This example illustrates the type of code that would be processed by darklua's rules, particularly those affecting spacing. ```Lua local function getAverage(array) local sum = 0 for _, element in ipairs(array) do sum = sum + element end return sum / #array end ``` -------------------------------- ### Configure convert_require rule for Lua portability Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/convert_require.md Example configuration for the 'convert_require' rule, demonstrating how to set up 'path' as the current require mode and 'roblox' as the target mode for Lua code portability, including optional settings for module folders, sources, Rojo sourcemaps, and indexing styles. ```JSON5 { rule: "convert_require", current: { name: "path", // optional (defaults to 'init') module_folder_name: "init", // optional sources: { pkg: "./Packages", }, }, target: { name: "roblox", // optional rojo_sourcemap: "./path-to/sourcemap.json", // optional (defaults to 'find_first_child') indexing_style: "find_first_child", // 'wait_for_child' or 'property' }, } ``` -------------------------------- ### Luau Compound Assignment Examples Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_compound_assignment.md Examples of compound assignment operators in Luau that this Darklua rule converts into standard Lua assignments. This functionality is particularly useful for transpiling Luau code to be compatible with Lua. ```Luau counter += 1 object.prop -= 1 object.message ..= ' (context: ' .. context .. ')' ``` -------------------------------- ### Example Lua Require Calls Using Custom Sources Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/path-require-mode/index.md This Lua snippet demonstrates how to use the custom source mappings defined in the darklua configuration. It shows require calls using aliased paths like '@pkg/Promise' and 'images', which resolve to the configured source locations. ```lua local Promise = require("@pkg/Promise") local images = require("images") ``` -------------------------------- ### Lua Function Call Parentheses Removal Examples Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_function_call_parens.md Examples demonstrating the 'remove_function_call_parentheses' rule in darklua, showing how parentheses are removed for function calls with a single string or table argument. ```Lua print('hello') ``` ```Lua create({ ... }) ``` -------------------------------- ### Updating Clippy Component with rustup Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command adds or updates the `clippy` component to the current Rust toolchain. It ensures that the latest version of Clippy is installed and available, resolving potential discrepancies between local and CI linting results. ```sh rustup component add clippy ``` -------------------------------- ### Merge Consecutive Local Assignments (Lua) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/group_local_assignment.md Example demonstrating how the rule merges simple consecutive local assignments into a single statement. ```lua local foo = 1 local bar = 2 ``` -------------------------------- ### Lua: Example of Method to Field Conversion Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_method_definition.md This Lua code snippet demonstrates a function defined using the method syntax (':') which would be converted by the darklua rule. The 'move' function operates on a 'Car' object, updating its position. ```Lua local Car = {} function Car:move(distance) self.position = self.position + distance end ``` -------------------------------- ### Configure rename_variables to avoid specific identifiers Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/rename_variables.md Example configuration for the `rename_variables` rule to avoid specific identifiers in addition to default globals. ```json5 { rule: "rename_variables", globals: ["$default", "a", "b"] } ``` -------------------------------- ### Configuring the readable Lua Code Generator Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/generators/index.md Describes the `readable` generator, which aims for human-readable output but does not preserve original line numbers or comments. It provides configuration examples in `json5`, including how to set a custom `column_span`. ```JSON5 { generator: "readable", } ``` ```JSON5 { generator: { name: "readable", column_span: 50 }, } ``` -------------------------------- ### Luau If Expression Removal Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_if_expression.md Demonstrates a `local` variable assignment using an `if` expression in Luau, which this rule would transform into standard Lua. ```Lua local variable = if condition() then { option = true } else { option = false } ``` -------------------------------- ### Configure Convert Require Rule with Wait For Child Indexing Style Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/roblox-require-mode/index.md Example demonstrating how to configure the 'convert_require' rule to use the 'wait_for_child' indexing style. This overrides the default 'find_first_child' behavior for generating instance paths, ensuring that the system waits for child instances to exist. ```JSON { "rules": [ { "rule": "convert_require", "current": "path", "target": { "name": "roblox", "indexing_style": "wait_for_child" } } ] } ``` -------------------------------- ### Lua: Transform continue to break statement Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_continue.md Example demonstrating the transformation of a `continue` statement within a loop into equivalent logic using `break` statements, useful for Luau to Lua conversion. ```Lua for i = 1, 10 do if i == 1 then continue end print(i) end ``` -------------------------------- ### Lua Rule: Examples of Unused Variable Removal Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_unused_variable.md Examples demonstrating the types of Lua code structures where the 'Removes unused variable declarations' rule applies. The rule identifies and removes local variable declarations and local function definitions that are not used anywhere in the code. ```Lua local var ``` ```Lua local var1 = true local var2 = var1 ``` ```Lua local var = call() ``` ```Lua local function fn() print('unused') end ``` ```Lua local a, b, c = 1, 2, 3 return a ``` -------------------------------- ### Configure Convert Require Rule with Rojo Sourcemap Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/roblox-require-mode/index.md Example of using the 'convert_require' rule with the 'roblox' target mode, specifying a 'rojo_sourcemap' file. This allows darklua to directly map file locations to the Roblox DataModel. ```JSON { "rules": [ { "rule": "convert_require", "current": "path", "target": { "name": "roblox", "rojo_sourcemap": "./path-to/sourcemap.json" } } ] } ``` -------------------------------- ### Lua Example: Code Affected by debug.profilebegin/end Removal Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_debug_profiling.md Illustrates a typical Lua code block containing `debug.profilebegin` and `debug.profileend` calls, which are targeted for removal by the darklua rule. ```Lua debug.profilebegin('function name') performUpdate() debug.profileend() ``` -------------------------------- ### Configure rename_variables to avoid Roblox globals Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/rename_variables.md Example configuration for the `rename_variables` rule to prevent renaming variables to identifiers used by Roblox globals. ```json5 { rule: "rename_variables", globals: ["$default", "$roblox"] } ``` -------------------------------- ### Prevent Merging Multi-Value Assignments (Lua) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/group_local_assignment.md This example illustrates that assignments extracting multiple return values from a function will not be merged, even if followed by another local assignment. ```lua local foo, bar = multiple_return_values() local baz = 0 ``` -------------------------------- ### Configure Rule with Object Format (Custom Parameters) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/rules/index.md Illustrates how to use the object format to configure a darklua rule and override its default parameters. The `rule` field specifies the rule name, and additional fields define custom parameter values. This example configures the `rename_variables` rule to include function names by setting `include_functions` to `true`. ```JSON5 { rule: "rename_variables", include_functions: true, } ``` -------------------------------- ### Prevent Merging Due to Temporal Dependency (Lua) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/group_local_assignment.md This example shows a scenario where the rule will not merge assignments because the second assignment depends on the value of the first, preventing behavior changes. ```lua local foo = 1 local bar = foo ``` -------------------------------- ### Lua Examples: Removing Explicit Nil Declarations Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_nil_declaration.md Illustrates the Darklua rule's behavior in optimizing local assignments by removing explicit `nil` declarations and trimming unnecessary expressions. ```Lua local var = nil ``` ```Lua local a, b, c = 1, nil, nil ``` ```Lua local a, b = nil, call() ``` ```Lua local var = call(), otherValue, true ``` -------------------------------- ### Create a new Gatsby site using the blog starter Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md Utilize the Gatsby CLI to initialize a new project, specifying the official blog starter template. This command fetches the starter from GitHub and sets up the basic project structure. ```Shell gatsby new my-blog-starter https://github.com/gatsbyjs/gatsby-starter-blog ``` -------------------------------- ### Lua Code Transformation: Unreachable Statements After Return Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/filter_after_early_return.md This example demonstrates the Darklua rule's effect. The first block shows the original Lua code with an unreachable `otherImplementation` function. The second block shows the code after the rule has been applied, with the unreachable code removed. ```Lua do local function process() -- ... end return process end local function otherImplementation() -- ... end return otherImplementation ``` ```Lua do local function process() -- ... end return process end ``` -------------------------------- ### Convert Local Lua Function to Variable Declaration Example Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/convert_local_function_to_assign.md This snippet illustrates a local function definition in Lua that will be converted into a local assignment statement. This transformation is applied to non-recursive local functions and may alter behavior related to reflection APIs or stack trace information. ```Lua local function foo(a, b) return a + b end ``` -------------------------------- ### Execute Darklua Bundling Process Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Command-line instruction to bundle Lua code using Darklua, specifying the entry point file and the desired output file for the bundled code. ```shell darklua process entry-point.lua bundled.lua ``` -------------------------------- ### Gatsby site configuration (gatsby-config.js) Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md The `gatsby-config.js` file is the primary configuration file for a Gatsby site. It's used to specify site metadata (like title and description) and to include Gatsby plugins. ```APIDOC File: gatsby-config.js Purpose: Main configuration for site metadata and plugins. Reference: Gatsby config docs (https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/) ``` -------------------------------- ### Gatsby Node APIs configuration (gatsby-node.js) Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md The `gatsby-node.js` file is where Gatsby expects to find any usage of its Node APIs. These APIs enable customization and extension of default Gatsby settings that influence the site build process. ```APIDOC File: gatsby-node.js Purpose: Customization/extension of default Gatsby settings affecting the site build process. Reference: Gatsby Node APIs (https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/) ``` -------------------------------- ### Configure Darklua for Path-Based Bundling Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Minimal Darklua configuration to enable bundling with `path` require mode, allowing the tool to merge required modules into a single file. ```json5 { bundle: { require_mode: "path", }, } ``` -------------------------------- ### Running all darklua tests (unit, snapshot, integration) Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md Execute all darklua tests, including unit, snapshot, and integration tests, using the standard cargo command. The `-q` flag provides a quieter output for less verbosity. ```Shell cargo test # or if the output is too verbose cargo test -q ``` -------------------------------- ### Gatsby Browser APIs configuration (gatsby-browser.js) Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md The `gatsby-browser.js` file is where Gatsby expects to find any usage of its browser APIs. These APIs allow for customization and extension of default Gatsby settings that affect the browser environment. ```APIDOC File: gatsby-browser.js Purpose: Customization/extension of default Gatsby settings affecting the browser. Reference: Gatsby browser APIs (https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/) ``` -------------------------------- ### Gatsby Server-Side Rendering APIs configuration (gatsby-ssr.js) Source: https://github.com/seaofvoices/darklua/blob/main/site/README.md The `gatsby-ssr.js` file is where Gatsby expects to find any usage of its server-side rendering APIs. These APIs allow for customization of default Gatsby settings that affect server-side rendering. ```APIDOC File: gatsby-ssr.js Purpose: Customization of default Gatsby settings affecting server-side rendering. Reference: Gatsby server-side rendering APIs (https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/) ``` -------------------------------- ### Build WebAssembly for web with wasm-pack Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Builds the Rust project into a WebAssembly module optimized for web browsers, generating JavaScript bindings and .wasm files. ```Bash wasm-pack build -t web ``` -------------------------------- ### Running Benchmarks with Tracy Profiling Enabled Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command runs the project's benchmarks with the `tracing` feature enabled, allowing some benchmarks to emit tracing information. This data can then be captured and visualized using the Tracy profiler for detailed performance analysis. ```sh cargo bench --features tracing ``` -------------------------------- ### Running darklua integration tests Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md After passing the quick development checks, run this command to execute the longer integration tests for darklua, ensuring full system functionality. ```Shell lua ./scripts/test-commands.lua ``` -------------------------------- ### Publish WebAssembly package to NPM Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Publishes the compiled WebAssembly package, along with its JavaScript bindings, to the Node Package Manager (NPM) registry, making it available for public consumption. ```Bash wasm-pack publish ``` -------------------------------- ### Running Rust Benchmarks with Criterion.rs Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command executes the project's performance benchmarks, which are set up using Criterion.rs. After execution, detailed benchmark reports are automatically generated in the `target/criterion/` directory. ```sh cargo bench ``` -------------------------------- ### Build WebAssembly for Node.js environment Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Compiles the WebAssembly module specifically for the Node.js runtime, ensuring compatibility with server-side JavaScript applications. ```Bash npm run build ``` -------------------------------- ### Downloading Benchmark Content Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This script fetches public Lua source code necessary for running benchmarks, as these sources are not committed to the repository. It's a prerequisite step before executing performance benchmarks. ```sh ./bench_content/download_content.sh ``` -------------------------------- ### Running quick development checks for darklua Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md These commands provide fast and actionable feedback during darklua development. They include formatting, unit testing, and linting checks, and should be run frequently. ```Shell cargo fmt cargo test -q cargo clippy --all-targets --all-features -- -D warnings ``` -------------------------------- ### Navigate to JavaScript tests directory Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Changes the current working directory to the `javascript-tests` package, which contains additional tests for the WebAssembly module using Jest. ```Bash cd javascript-tests ``` -------------------------------- ### Test WebAssembly in headless browsers Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Executes tests for the WebAssembly module in a headless browser environment, specifically targeting Firefox. Supports Chrome and Safari as alternatives. ```Bash wasm-pack test --headless --firefox ``` -------------------------------- ### Configure Bundle with Custom Sources Mapping Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/path-require-mode/index.md This JSON5 snippet shows how to define custom source mappings within the 'path' require mode configuration. It allows mapping prefixes (e.g., '@pkg', 'images') to specific file system paths or files, enabling aliased require calls. ```json5 { bundle: { require_mode: { name: "path", sources: { "@pkg": "./Packages", // you can also map directly to a file (Lua or // any supported data file) images: "./assets/image-links.json", }, }, }, } ``` -------------------------------- ### Convert YAML GitHub Actions Workflow to Lua Table Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Demonstrates the transformation of a GitHub Actions workflow defined in YAML into its equivalent Lua table representation. This conversion is useful for tools that process configuration files in Lua, allowing for programmatic manipulation or interpretation of CI/CD pipelines. ```yml name: Tests on: push: branches: - main pull_request: branches: - main jobs: code-style: name: Verify code style runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Verify code format run: cargo fmt -- --check ``` ```lua { name = "Tests", on = { push = { branches = { "main" }, }, pull_request = { branches = { "main" }, }, }, jobs = { ["code-style"] = { name = "Verify code style", ["runs-on"] = "ubuntu-latest", steps = { { uses = "actions/checkout@v3", }, { name = "Verify code format", run = "cargo fmt -- --check", }, }, }, }, } ``` -------------------------------- ### Run JavaScript tests for WebAssembly module Source: https://github.com/seaofvoices/darklua/blob/main/site/darklua-wasm/README.md Executes the JavaScript-based tests, typically using Jest, against the WebAssembly module built for the Node.js environment. ```Bash npm run test ``` -------------------------------- ### Running Clippy for Rust Code Linting Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command runs Clippy, the Rust linter, across all targets and features to generate a comprehensive report of potential code issues and warnings. The `-D warnings` flag treats all warnings as errors, enforcing strict code quality. ```sh cargo clippy --all-targets --all-features -- -D warnings ``` -------------------------------- ### Configure Path Require Mode with Default Values Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/path-require-mode/index.md This JSON5 snippet shows the basic structure for configuring the 'path' require mode in darklua, including optional parameters like 'module_folder_name', 'sources', and 'use_luau_configuration' with their default values. ```json5 { name: "path", // optional (defaults to 'init') module_folder_name: "init", // optional sources: { pkg: "./Packages", }, // optional (defaults to true) use_luau_configuration: true, } ``` -------------------------------- ### Formatting Rust Code with cargo fmt Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command automatically formats all Rust code within the project according to the standard Rust formatting guidelines. Running this ensures consistent code style across the codebase. ```sh cargo fmt ``` -------------------------------- ### convert_require Rule Parameters and Restrictions Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/convert_require.md Defines the parameters for configuring the 'convert_require' rule, specifying the current and target require modes for transforming Lua 'require' calls between different environments, along with their current restrictions. ```APIDOC Rule Parameters: current: type: require mode required: true description: The require mode used in the input code target: type: require mode required: true description: The require mode used to generate the new require calls Restrictions: current: can only be the `path` require mode target: can only be the `roblox` require mode ``` -------------------------------- ### Updating Rust Toolchain with rustup Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command updates the Rust toolchain to the latest stable version. It is often necessary to resolve issues where `clippy` or other tools behave differently between local and CI environments due to version mismatches. ```sh rustup update ``` -------------------------------- ### Configure Bundle with Custom Module Folder Name Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/path-require-mode/index.md This JSON5 snippet demonstrates how to configure darklua's bundle settings to use a custom 'module_folder_name' (e.g., 'index') for resolving module paths, similar to JavaScript's 'index.js' behavior. ```json5 { bundle: { require_mode: { name: "path", // folders with a `index.lua` or `index.luau` file // can be required module_folder_name: "index", }, }, } ``` -------------------------------- ### Configure Roblox Require Mode Object Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/roblox-require-mode/index.md Defines the structure for configuring the 'roblox' require mode, including optional parameters like 'rojo_sourcemap' for specifying a sourcemap file and 'indexing_style' to control how instance paths are generated. ```JSON { "name": "roblox", "rojo_sourcemap": "./path-to/sourcemap.json", "indexing_style": "find_first_child" } ``` -------------------------------- ### Customize Darklua Bundle Modules Identifier Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/bundle/index.md Configuration snippet showing how to change the default variable name (`__DARKLUA_BUNDLE_MODULES`) used by Darklua to store required modules in the bundled file. ```json5 { bundle: { require_mode: "path", // by default, darklua will use the following value modules_identifier: "__DARKLUA_BUNDLE_MODULES", }, } ``` -------------------------------- ### Reviewing Snapshot Test Failures with cargo insta Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This command allows interactive review of snapshot test failures or new snapshots. It enters an interactive terminal mode where users can accept, reject, or skip changes, facilitating the update of test baselines. ```sh cargo insta review ``` -------------------------------- ### Darklua Rule: inject_global_value API Reference Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/inject_global_value.md Detailed API documentation for the `inject_global_value` rule, including its purpose, versioning, and parameter definitions with their types, requirements, and descriptions. ```APIDOC Rule: inject_global_value description: Inject a global variable added_in: 0.3.5 Parameters: identifier: type: string required: true description: The name of the global variable value: type: boolean, number or string description: The value to inject default: nil env: added_in: 0.7.0 type: string description: An environment variable to read the value from ``` -------------------------------- ### Running End-to-End Tests with Lua Script Source: https://github.com/seaofvoices/darklua/blob/main/CONTRIBUTING.md This Lua script executes end-to-end tests by cloning Lua repositories, applying darklua rules, and asserting that tests continue to pass. It's crucial for verifying the integrity of darklua's transformations. ```lua lua ./scripts/test-commands.lua ``` -------------------------------- ### Configure Convert Require Rule with Custom Module Folder Name Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/path-require-mode/index.md This JSON5 snippet illustrates how to apply a custom 'module_folder_name' (e.g., 'index') within the 'convert_require' rule, allowing darklua to resolve module paths using 'index.lua' or 'index.luau' files when converting require calls. ```json5 { rules: [ { rule: "convert_require", current: { name: "path", // folders with a `index.lua` or `index.luau` file // can be required module_folder_name: "index", }, target: "roblox", }, ], } ``` -------------------------------- ### Generate Rojo Sourcemaps for Roblox Projects Source: https://github.com/seaofvoices/darklua/blob/main/tests/test_cases/sourcemap/notes.txt This snippet demonstrates how to generate sourcemap JSON files from Rojo project configurations. Sourcemaps are essential for debugging Roblox projects, mapping compiled code back to its original source. The `rojo sourcemap` command takes a project JSON file as input and redirects the output to a specified JSON file. ```sh rojo sourcemap tests/test_cases/sourcemap/default.project.json > tests/test_cases/sourcemap/sourcemap.json rojo sourcemap tests/test_cases/sourcemap/place.project.json > tests/test_cases/sourcemap/place-sourcemap.json ``` -------------------------------- ### Configuring the dense Lua Code Generator Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/generators/index.md Explains the `dense` generator, which minimizes whitespace and fills lines up to a specified character limit, defaulting to 80. It also shows how to configure it in `json5`, including setting a custom `column_span`. ```JSON5 { generator: "dense", } ``` ```JSON5 { generator: { name: "dense", column_span: 50 }, } ``` -------------------------------- ### darklua Rule: remove_debug_profile_functions Parameters Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_debug_profiling.md Details the `preserve_arguments_side_effects` parameter for the darklua rule that removes `debug.profilebegin` and `debug.profileend` calls, explaining its impact on argument handling. ```APIDOC Parameter: preserve_arguments_side_effects Type: boolean Description: Defines how darklua handle arguments passed to the functions. If true, darklua will inspect each argument and preserve any potential side effects. When false, darklua will not perform any verification and simply erase any arguments passed. Default: true ``` -------------------------------- ### darklua Rule Definition: Removes Spaces Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_spaces.md Formal definition and metadata for the darklua rule designed to remove spaces from processed code, indicating its version and parameters. ```APIDOC description: Removes spaces added_in: "0.7.0" parameters: [] ``` -------------------------------- ### Rule: rename_variables API Documentation Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/rename_variables.md Defines the `rename_variables` rule, its purpose, and configurable parameters for darklua. ```APIDOC Rule: rename_variables description: Renames variables and function parameters added_in: "0.2.1" parameters: - name: globals type: array default: "['$default']" description: What identifier should be avoided when generating new names - name: include_functions added_in: "0.7.0" type: boolean default: "false" description: Controls if function names get renamed ``` -------------------------------- ### Darklua Rule: append_text_comment API Reference Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/append_text_comment.md Detailed API documentation for the `append_text_comment` rule, outlining its parameters, types, descriptions, and default values. ```APIDOC append_text_comment Rule: parameters: - name: text type: string description: The string to use inside the comment (required if `file` is not defined) - name: file type: string description: A path to a file to be used as the comment content (required if `text` is not defined) - name: location type: "start" or "end" default: start description: The location where to add the comment ``` -------------------------------- ### Lua Code Generation with retain_lines Generator Source: https://github.com/seaofvoices/darklua/blob/main/site/content/docs/generators/index.md Demonstrates how the `retain_lines` generator preserves line numbers and structure when processing Lua code, even after transformations like inlining and whitespace removal. It also shows the configuration for this generator. ```Lua local function giveReason(message) if _G.DEBUG_MODE then return message .. " - reason: " .. getReason() else return message end end ``` ```Lua local function giveReason(message) return message.." - reason: "..getReason() end ``` ```JSON5 { generator: "retain_lines", } ``` -------------------------------- ### Darklua Rule Definition: Remove Empty Do Statements Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_empty_do.md Formal definition of the `darklua` rule for removing empty `do` statements, including its version and parameters. ```APIDOC Rule Definition: description: Removes empty do statements added_in: "0.2.0" parameters: [] ``` -------------------------------- ### Darklua: Append Comment at File End Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/append_text_comment.md Demonstrates configuring the `append_text_comment` rule to insert a comment with specific text at the end of a Lua file. ```JSON [{"rule": "append_text_comment", "text": "hello!", "location": "end"}] ``` ```Lua print('Print from module') ``` -------------------------------- ### Darklua Rule: Transforming If to Do Block Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_unused_if_branch.md Demonstrates how the darklua rule transforms an 'if' statement into a 'do' block when the initial 'if' condition is always true, making all subsequent branches unreachable. ```lua if true then return 2 elseif unknown then return 1 else return 0 end ``` ```lua do return 2 end ``` -------------------------------- ### Convert Lua Index Expressions to Field Expressions Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/convert_index_to_field.md This rule transforms Lua index expressions using static strings into field expressions. It also applies to table declarations, converting bracket syntax entries like { ['key'] = value } into field-like entries when the key is a static string. This improves readability and consistency. ```Lua return var['field'] ``` ```Lua return { ['field'] = true } ``` -------------------------------- ### Darklua Rule: assert Parameters Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_assertions.md Details the configurable parameters for the darklua rule that removes `assert` function calls. The `preserve_arguments_side_effects` parameter dictates whether darklua analyzes and preserves side effects from arguments passed to `assert`. ```APIDOC Rule: Remove Assert Calls Parameters: - name: preserve_arguments_side_effects type: boolean description: Defines how darklua handle arguments passed to the function. If true, darklua will inspect each argument and preserve any potential side effects. When false, darklua will not perform any verification and simply erase any arguments passed. default: "true" ``` -------------------------------- ### Darklua Rule Definition: Remove Unreachable Statements Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/filter_after_early_return.md Formal definition and metadata for the Darklua rule that removes unreachable statements following return statements. ```APIDOC Rule Definition: description: Removes unreachable statements following return statements added_in: "0.8.0" parameters: [] ``` -------------------------------- ### Roblox Lua Globals ($roblox) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/rename_variables.md List of global identifiers specific to Roblox Lua that are included in the `$roblox` group for the `globals` property. ```Lua Axes, bit32, BrickColor, CellId, ColorSequence, ColorSequenceKeypoint, Color3, CFrame, DateTime, DebuggerManager, delay, DockWidgetPluginGuiInfo, elapsedTime, Enum, Faces, Instance, LoadLibrary, game, NumberRange, NumberSequence, NumberSequenceKeypoint, PathWaypoint, PhysicalProperties, plugin, PluginDrag, PluginManager, printidentity, Random, Ray, RaycastParams, Rect, Region3, Region3int16, script, settings, shared, stats, spawn, tick, time, TweenInfo, typeof, UDim, UDim2, UserSettings, utf8, Vector2, Vector2int16, Vector3, Vector3int16, version, wait, warn, workspace, ypcall ``` -------------------------------- ### Default Lua Globals ($default) Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/rename_variables.md List of standard global identifiers in Lua that are included in the `$default` group for the `globals` property. ```Lua arg, assert, collectgarbage, coroutine, debug, dofile, error, gcinfo, getfenv, getmetatable, io, ipairs, load, loadfile, loadstring, math, module, newproxy, next, os, package, pairs, pcall, print, rawequal, rawget, rawset, require, select, setfenv, setmetatable, string, table, tonumber, tostring, type, unpack, xpcall, _G, _VERSION ``` -------------------------------- ### Darklua Rule Parameter: Strategy for Interpolated String Conversion Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_interpolated_string.md Details the `strategy` parameter for the darklua rule that removes interpolated strings. This parameter controls how backtick strings are converted into `string.format` calls, offering 'string' and 'tostring' options. ```APIDOC Parameter: strategy Type: "string" or "tostring" Description: Defines how darklua converts the interpolated strings into `string.format` calls. The "string" strategy will make the rule use the `%s` specifier and the "tostring" strategy will use the `%*` specifier. Default: string ``` -------------------------------- ### darklua remove_comments Rule API Reference Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_comments.md Defines the 'remove_comments' rule in darklua, including its purpose, versioning, and parameters with their types and descriptions. ```APIDOC Rule: remove_comments Description: Removes comments Added In: 0.7.0 Parameters: - Name: except Type: string array Description: Comments matching any of the given regular expressions will be kept Added In: 0.13.1 ``` -------------------------------- ### Darklua Rule: Removing Redundant Else Block Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_unused_if_branch.md Illustrates how the darklua rule removes a redundant 'else' block when a preceding 'elseif' condition is always true, making the 'else' block superfluous. ```lua if unknown then return 2 elseif true then return 1 else return 0 end ``` ```lua if unknown then return 2 elseif true then return 1 end ``` -------------------------------- ### Lua: Darklua Rule for Removing Unused While Loop Source: https://github.com/seaofvoices/darklua/blob/main/site/content/rules/remove_unused_while.md This Lua code snippet demonstrates a `while` loop with a condition that evaluates to `false` (`'foo' == 'bar'`). The darklua rule will identify this as an unused statement and remove it during optimization, as the condition has no side effects. ```Lua while 'foo' == 'bar' do -- ... end ```