### Install binary on Linux or macOS Source: https://github.com/atelico/gdstyle/blob/main/README.md Extract and move the downloaded binary to a directory in your system PATH. ```bash tar xzf gdstyle-*.tar.gz cp gdstyle ~/.local/bin/ # or /usr/local/bin/, or anywhere on your PATH ``` -------------------------------- ### Command-line usage examples Source: https://github.com/atelico/gdstyle/blob/main/README.md Common commands for linting, formatting, and configuring the gdstyle tool. ```bash # Lint the current directory (recursively finds all .gd files) gdstyle # Lint specific files or directories gdstyle check src/player.gd src/enemies/ # Auto-fix safe violations gdstyle check --fix # Auto-fix all violations including unsafe ones gdstyle check --unsafe-fix # Format all GDScript files in place gdstyle fmt # Check formatting without modifying files (exit 1 if changes needed) gdstyle fmt --check # Show formatting diff without modifying files gdstyle fmt --diff # Output lint results as JSON (for CI integration) gdstyle check --format json # List all available rules gdstyle rules # Generate a starter config file gdstyle init # Only check naming rules gdstyle check --select naming # Ignore specific rules gdstyle check --ignore "format/max-line-length,format/double-quotes" # Override max line length gdstyle check --max-line-length 120 ``` -------------------------------- ### Install gdstyle CLI Source: https://github.com/atelico/gdstyle/blob/main/RELEASE_NOTES.md Command to install the gdstyle CLI tool via cargo. ```bash cargo install gdstyle ``` -------------------------------- ### Define gdstyle configuration file Source: https://github.com/atelico/gdstyle/blob/main/README.md Example TOML configuration file demonstrating global limits, file exclusions, and rule severity overrides. ```toml # gdstyle.toml # Maximum line length (default: 100) max_line_length = 100 # Use tabs for indentation (default: true) use_tabs = true # Maximum function body length in lines (default: 50) max_function_length = 50 # Maximum file length in lines (default: 1000) max_file_length = 1000 # Maximum number of function parameters (default: 5) max_parameters = 5 # Maximum return statements per function (default: 6) max_returns = 6 # Maximum nesting depth inside a function (default: 4) max_nesting_depth = 4 # Maximum local variables per function (default: 10) max_local_variables = 10 # Maximum branches (if/elif/match) per function (default: 8) max_branches = 8 # Maximum class-level variables (default: 15) max_class_variables = 15 # Maximum public methods per class (default: 20) max_public_methods = 20 # Maximum inner classes per file (default: 5) max_inner_classes = 5 # File/directory patterns to exclude exclude = [".godot", "addons"] # Patterns to force-include even when `exclude` matches them. An include always # wins over an exclude, so you can lint one plugin inside an otherwise-excluded # directory. Empty by default. include = ["addons/my_plugin"] # Per-rule severity overrides # Values: "off", "warn", "error" [rules] "format/double-quotes" = "off" # Disable a rule entirely "naming/class-name-pascal-case" = "error" # Escalate to error "quality/max-function-length" = "warn" # Keep as warning "quality/no-debug-print" = "warn" # Enable an off-by-default rule ``` -------------------------------- ### Fix line continuation lexing Source: https://github.com/atelico/gdstyle/blob/main/RELEASE_NOTES.md Example of valid line continuation that previously triggered a false lex error. ```gdscript if a() and \ b(): return true ``` -------------------------------- ### Parse JSON diagnostic output Source: https://github.com/atelico/gdstyle/blob/main/README.md Example of the JSON structure returned when running gdstyle with the --format json flag. ```json [ { "rule": "naming/variable-name-snake-case", "message": "Variable 'BadName' should use snake_case: 'bad_name'", "severity": "warn", "span": { "line": 5, "column": 1 }, "file": "src/player.gd" } ] ``` -------------------------------- ### Fix inline callable formatting Source: https://github.com/atelico/gdstyle/blob/main/RELEASE_NOTES.md Example of code that previously caused a parse error due to incorrect statement splitting. ```gdscript _active_tween.tween_method( func(v: float) -> void: _calc.visual = v; queue_redraw(), from, to, duration ) ``` -------------------------------- ### Trailing comma formatting behavior Source: https://github.com/atelico/gdstyle/blob/main/RELEASE_NOTES.md Demonstrates the change in trailing comma application where the closing bracket must start its own line. ```gdscript # 0.2.4 rewrote this ... print("%s %s" % [ alpha, beta]) # ... into this. 0.2.5 leaves it alone. print("%s %s" % [ alpha, beta,]) ``` ```gdscript var xs := [ alpha, beta, # still added, the closer owns its line ] ``` -------------------------------- ### Initialize gdstyle configuration Source: https://github.com/atelico/gdstyle/blob/main/README.md Generates a starter configuration file in the current directory. ```bash gdstyle init ``` -------------------------------- ### Build from source Source: https://github.com/atelico/gdstyle/blob/main/README.md Clone the repository and compile the project using Cargo. ```bash git clone https://github.com/atelico/gdstyle.git cd gdstyle cargo build --release # The binary is at target/release/gdstyle cp target/release/gdstyle ~/.local/bin/ ``` -------------------------------- ### Use gdstyle as a Rust library Source: https://github.com/atelico/gdstyle/blob/main/README.md Demonstrates how to initialize a configuration, lint a GDScript file, and format a source string using the gdstyle crate. ```rust use gdstyle::config::Config; use gdstyle::linter; use gdstyle::formatter; fn main() { let config = Config::default(); // Lint a file let diagnostics = linter::lint_file( std::path::Path::new("player.gd"), &config, ).unwrap(); for d in &diagnostics { println!("line {}: [{}] {}", d.span.line, d.rule, d.message); } // Format a source string let source = "var x = 'hello'\n"; let formatted = formatter::format_source(source, &config); assert!(formatted.contains("\"hello\"")); } ``` -------------------------------- ### Basic CLI Usage Source: https://github.com/atelico/gdstyle/blob/main/README.md The general syntax for executing gdstyle commands. ```bash gdstyle [COMMAND] [OPTIONS] [PATHS]... ``` -------------------------------- ### Run project tests Source: https://github.com/atelico/gdstyle/blob/main/README.md Commands to execute unit, integration, and linting tests for the project. ```bash cargo test # Run all tests cargo test --lib # Unit tests only cargo test --test integration_test # Integration tests only cargo clippy # Lint check ``` -------------------------------- ### Project directory structure Source: https://github.com/atelico/gdstyle/blob/main/README.md An overview of the gdstyle repository layout, detailing the Rust source modules, GDExtension wrapper, and Godot plugin files. ```text gdstyle/ ├── src/ │ ├── main.rs # CLI entry point (clap subcommands) │ ├── lib.rs # Library root │ ├── token.rs # Token types (Span, TokenKind, Token) │ ├── lexer.rs # Tokenizer (indentation-aware, GDScript 4.x) │ ├── ast.rs # AST node types for linting │ ├── parser.rs # Lightweight parser (just enough for linting) │ ├── diagnostic.rs # Diagnostic, Fix, and Replacement types │ ├── config.rs # TOML configuration loading │ ├── linter.rs # Main lint pipeline (tokenize -> parse -> rules -> filter) │ ├── reporter.rs # Text and JSON output formatting │ ├── fixer.rs # Auto-fix engine (applies replacements) │ ├── formatter.rs # Multi-pass formatter │ └── rules/ │ ├── mod.rs # Rule dispatcher │ ├── naming.rs # 11 naming convention rules │ ├── formatting.rs # 20 formatting rules │ ├── ordering.rs # Class member ordering rule │ └── quality.rs # 23 code quality rules ├── gdstyle-gdext/ # GDExtension wrapper (exposes linter/formatter to Godot) │ ├── Cargo.toml │ └── src/lib.rs ├── godot-plugin/ # Godot 4.x editor plugin │ └── addons/gdstyle/ │ ├── plugin.cfg │ ├── plugin.gd │ ├── gdstyle_panel.gd │ └── gdstyle.gdextension ├── tests/ │ ├── integration_test.rs # End-to-end integration tests │ └── fixtures/ # GDScript test fixtures ├── .github/workflows/ │ ├── ci.yml # rustfmt, clippy, and tests on every PR │ └── release.yml # builds + publishes CLI + GDExtension for all platforms ├── examples/ # Example GDScript files for trying out gdstyle ├── Cargo.toml └── gdstyle.example.toml ``` -------------------------------- ### Run local development checks Source: https://github.com/atelico/gdstyle/blob/main/CONTRIBUTING.md Execute the standard test suite, linter, and formatter to ensure code quality before submitting changes. ```bash cargo test cargo clippy --release cargo fmt --check ``` -------------------------------- ### Run gdstyle on GDScript files Source: https://github.com/atelico/gdstyle/blob/main/CONTRIBUTING.md Verify formatting and linting on GDScript files after making modifications. ```bash gdstyle check gdstyle fmt --check ``` -------------------------------- ### Configure pre-commit hook Source: https://github.com/atelico/gdstyle/blob/main/RELEASE_NOTES.md Configuration snippet for the pre-commit framework. ```yaml - repo: https://github.com/atelico/gdstyle rev: v0.2.5 hooks: - id: gdstyle - id: gdstyle-fmt ``` -------------------------------- ### Format GDScript files Source: https://github.com/atelico/gdstyle/blob/main/README.md Use the fmt subcommand to normalize code style, reorder class members, and preview changes. ```bash # Format all .gd files in place gdstyle fmt # Check if files are already formatted (exit 1 if not) gdstyle fmt --check # Show a diff of what would change gdstyle fmt --diff ``` -------------------------------- ### Run gdstyle CLI commands Source: https://github.com/atelico/gdstyle/blob/main/README.md Use these commands to lint, format, and auto-fix GDScript files from the command line. ```bash # Lint the examples. Expect warnings about naming, formatting, and quality. gdstyle check examples/ # See what the formatter would change gdstyle fmt --diff examples/ # Auto-fix all safe violations gdstyle check --fix examples/ # Format everything gdstyle fmt examples/ ``` -------------------------------- ### Configure GitHub Actions for GDStyle Source: https://github.com/atelico/gdstyle/blob/main/README.md Automate linting and formatting checks on every push or pull request using a GitHub Actions workflow. ```yaml name: GDScript Style on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install gdstyle run: cargo install gdstyle - name: Check formatting run: gdstyle fmt --check - name: Lint GDScript files run: gdstyle check ``` -------------------------------- ### Configure pre-commit hook for GDStyle Source: https://github.com/atelico/gdstyle/blob/main/README.md Integrate GDStyle into the pre-commit framework by adding the repository to your .pre-commit-config.yaml file. ```yaml repos: - repo: https://github.com/atelico/gdstyle rev: v0.2.5 # pin to a released tag; bump with `pre-commit autoupdate` hooks: - id: gdstyle # lint (fails the commit on diagnostics) - id: gdstyle-fmt # format in place ``` -------------------------------- ### Project directory structure Source: https://github.com/atelico/gdstyle/blob/main/CONTRIBUTING.md Overview of the source code organization for the gdstyle project. ```text src/ ├── lexer.rs GDScript tokenizer ├── parser.rs recursive-descent parser, AST ├── ast.rs ClassMember types ├── linter.rs top-level lint entry point ├── formatter.rs multi-pass formatter ├── fixer.rs applies replacements + scene-aware renames ├── reporter.rs text + JSON output ├── config.rs TOML config loader └── rules/ ├── naming.rs naming-convention rules ├── formatting.rs formatter-level rules ├── ordering.rs class member ordering ├── quality.rs code quality / complexity rules └── mod.rs rule registry tests/ ├── integration_test.rs end-to-end tests └── fixtures/ .gd files exercised by the integration tests gdstyle-gdext/ GDExtension wrapper (Rust → GDScript) godot-plugin/ Godot editor plugin source ``` -------------------------------- ### Implement a custom git pre-commit hook Source: https://github.com/atelico/gdstyle/blob/main/README.md Use a shell script in .git/hooks/pre-commit to run linting checks on staged GDScript files without external frameworks. ```bash #!/bin/bash # .git/hooks/pre-commit GD_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.gd') if [ -n "$GD_FILES" ]; then gdstyle check $GD_FILES if [ $? -ne 0 ]; then echo "GDScript lint failed. Fix with 'gdstyle check --fix' or suppress with '# gdstyle:ignore'." exit 1 fi fi ``` -------------------------------- ### Use GdStyle GDExtension API Source: https://github.com/atelico/gdstyle/blob/main/README.md Directly interact with the GdStyle engine in GDScript when using the GDExtension backend. ```gdscript var style = GdStyle.new() # Lint a file. var diagnostics = style.lint_res_file("res://player.gd") for d in diagnostics: print("Line %d: [%s] %s" % [d["line"], d["rule"], d["message"]]) if d["has_fix"]: print(" (auto-fixable, safe=%s)" % d["is_safe_fix"]) # Format a source string. var formatted = style.format_source(source_code) # Auto-fix violations. var fixed = style.fix_source(source_code, "player.gd") # Fix a single diagnostic by line and rule. style.fix_at_line("res://player.gd", 12, "naming/variable-name-snake-case") # Configure. style.set_max_line_length(120) style.disable_rule("format/double-quotes") style.load_config_res("res://gdstyle.toml") # Collect the project's .gd files the config would lint (honors exclude/include). # Load the config first so the walk reflects it. for res_path in style.collect_project_gd_files(): style.lint_res_file(res_path) ``` -------------------------------- ### Configuring project-wide rule suppression Source: https://github.com/atelico/gdstyle/blob/main/README.md Disable a rule globally by setting it to "off" in the gdstyle.toml configuration file. ```toml [rules] "quality/max-public-methods" = "off" ``` -------------------------------- ### Auto-fix GDScript violations Source: https://github.com/atelico/gdstyle/blob/main/README.md Use these commands to automatically apply fixes to your project files. Note that fixes are applied in-place without backups. ```bash # Fix safe violations only (formatting, naming conventions) gdstyle check --fix # Fix all violations including unsafe ones (signal renaming, member reordering) gdstyle check --unsafe-fix ``` -------------------------------- ### Pinning class members against reordering Source: https://github.com/atelico/gdstyle/blob/main/README.md Ignoring the order/class-member-order rule prevents the formatter from moving the annotated member. ```gdscript enum SaveGameFormat { BINARY, TEXT, } # gdstyle:ignore=order/class-member-order const SAVE_GAME_FORMAT_DISPLAY_NAMES: PackedStringArray = [ "OPTIONS_GENERAL_BINARY", "OPTIONS_GENERAL_TEXT", ] ``` -------------------------------- ### GdStyle GDExtension API Source: https://github.com/atelico/gdstyle/blob/main/README.md The GdStyle class allows developers to programmatically lint, format, and fix GDScript code. It supports file-based operations and direct source string manipulation. ```APIDOC ## GdStyle Class API ### Description The GdStyle class provides methods to interact with the linting and formatting engine. It can be instantiated in GDScript to perform static analysis and code style enforcement. ### Methods - **lint_res_file(path: String) -> Array** - Lint a specific file. Returns an array of diagnostic dictionaries containing line, rule, message, and fix information. - **format_source(source_code: String) -> String** - Formats the provided source code string and returns the formatted result. - **fix_source(source_code: String, path: String) -> String** - Applies all available auto-fixes to the provided source code string. - **fix_at_line(path: String, line: int, rule: String)** - Applies a specific fix for a diagnostic at a given line and rule. - **set_max_line_length(length: int)** - Configures the maximum line length for the formatter. - **disable_rule(rule_name: String)** - Disables a specific linting rule. - **load_config_res(path: String)** - Loads configuration settings from a TOML file. - **collect_project_gd_files() -> Array** - Returns a list of project GDScript files based on current configuration include/exclude rules. ``` -------------------------------- ### Suppressing diagnostics per-file Source: https://github.com/atelico/gdstyle/blob/main/README.md Use these directives to ignore rules across an entire file. These are typically placed at the top of the file. ```gdscript # gdstyle:ignore-file=quality/max-public-methods class_name OrchestrationFacade extends Node # ... 25 public methods follow ``` ```gdscript # gdstyle:ignore-file=quality/max-public-methods,quality/max-class-variables # gdstyle:ignore-file=quality/max-inner-classes class_name BigConfigDocument ``` ```gdscript # gdstyle:ignore-file # This file is generated by build/gen.py, do not edit. ``` -------------------------------- ### Suppressing diagnostics per-line Source: https://github.com/atelico/gdstyle/blob/main/README.md Use these directives to ignore rules on specific lines. Standalone comments affect the next line, while inline comments affect the same line. ```gdscript # gdstyle:ignore=naming/variable-name-snake-case var BadName: int = 5 ``` ```gdscript var BadName: int = 5 # gdstyle:ignore=naming/variable-name-snake-case ``` ```gdscript # gdstyle:ignore var BadName: int = 5 ``` ```gdscript # gdstyle:ignore=naming/variable-name-snake-case,format/max-line-length var SomeReallyLongVariableNameThatExceedsTheMaxLineLengthAndAlsoUsesTheBadNamingConvention: int = 5 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.