Fix formatter bugs and consolidate snapshot tests#1012
Open
DaelonSuzuka wants to merge 11 commits into
Open
Conversation
Add non-null assertions for RegExpMatchArray.index and use type predicates in filter() calls to satisfy strictNullChecks.
When '-' followed an '=' token, the formatter treated it as a binary subtraction and added a space before the next identifier. Now checks for '=' before the operator to correctly identify unary negation. Fixes godotengine#865.
Tests for godotengine#889 (negative indices), godotengine#976 (self keyword spacing), and godotengine#984 (@abstract + is). These bugs are already fixed in current code — tests prevent regressions.
Replace in.gd/out.gd directory pairs with single-file inline format using # --- IN --- / # --- OUT --- / # --- END --- markers. This makes tests easier to read and edit, and consistent with existing inline snapshot tests.
All snapshot tests are now in the inline single-file format. Remove the directory-based pair test runner, the get_options() helper, and the in.gd/out.gd file filter that are no longer needed.
Change maxEmptyLines from a dropdown of 1/2 to a numeric input allowing any non-negative integer. Sanitize configured values to clamp negatives to 0 and round to integers, defaulting to 2.
…ces (godotengine#858, godotengine#1002) - match_keyword pattern: change from ^\s* anchor to (?:^|:) so 'match' is recognized after ':', fixing 'if true: match x:' being tokenized as 'matchx' by the formatter - function_call begin pattern: add \s* between name and \( so 'func_name (args)' is scoped as a function call, not a variable followed by a grouped expression - statement_keyword: same (?:^|:) change for case/match consistency - Add nested_match.gd snapshot test covering the godotengine#858 fix
New test files for previously uncovered features: - annotations.gd: @export, @onready, @rpc, @warning_ignore, @abstract - control_flow.gd: if/elif/else, for..in, while, ternary if, pass/break/continue - declarations.gd: return types, class_name, extends, signal, static, const - dense_params.gd: denseFunctionParameters config option - dictionaries.gd: dict literals, nested/typed dicts, subscript access - is_as_operator.gd: is/is not and as operators - method_calls.gd: function call spacing, method chains - trailing_newlines.gd: strictTrailingNewlines config (renamed from test.gd) Reorganized existing tests: - Merge scientific_notation.gd into float_notation.gd - Merge self_keyword_spacing.gd into keywords.gd (expanded with super, const, class_name, signal, self) - Expand match.gd with more pattern types (string, array, dict, wildcard, comma-separated) - Rename test.gd to trailing_newlines.gd Discovered formatter gaps (marked as idempotency tests for now): - class_name/extends ARE now formatted (was unknown) - signal with args IS formatted (was unknown) - static func/var IS formatted (was unknown) - const inside functions IS formatted (was unknown) - denseFunctionParameters does not affect := spacing
- Add yield to no-space-before-paren list (alongside func, assert, export) so yield(expr) stays compact instead of becoming yield (expr) - Make signal tokenization scope-aware: keyword in declarations (signal my_signal) but variable in expression context (yield(signal, ...)) so it doesn't get extra keyword spacing inside function calls - Add godot3_compat.gd test covering: tool, export, onready, remote/ master/puppet sync keywords, setget syntax, and yield()
The biome linter on CI (newer version) treats noNonNullAssertion as an error. Replace match.index! assertions with early-continue guards that handle the undefined case explicitly.
Add 'npm run test:headless' that runs tests under xvfb-run with WAYLAND_DISPLAY unset. Add --ozone-platform=x11 to test launchArgs so VS Code's Electron uses X11 instead of crashing on Wayland systems. This prevents the test runner from stealing window focus on Linux desktops running Wayland.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
matchafter:(closes Auto Formatter incorrectly remove space between test value and nested match statement #858) and function calls with spaces before parens (closes A space between method name and arguments causes incorrect tokenization and syntax highlighting #1002)yield(expr)getting extra space before(— treated likefunc(,assert(,export(signalgetting extra keyword spacing inside expressions likeyield(signal, ...)— now scope-awaremaxEmptyLinessetting (closes Allow Max Empty Lines to be more than just "1" or "2" #1004)<<<<<<</=======/>>>>>>>into separated operators (closes Autoformatter Incorrectly Formats Merge Conflicts #850)denseFunctionParametersstripping spaces inside lambda bodies — assignments likex = falseinsideconnect(func(): ...)now preserve spacing (closes Formatting issue of lambda functions #938)1e-6are already fixed by prior grammar changes; verified with expandedfloat_notation.gdsnapshot tests (closes Formatter adds space inside float literal with negative exponent. #928)Grammar fixes (#858, #1002)
match_keywordandstatement_keywordpatterns now use(?:^|:)instead of^\s*, somatchis recognized after:function_callbegin pattern now allows\s*between name and(, sofunc_name (args)scopes as a function callFormatter fixes (#858, #865, #928, #938, #850, yield, signal)
between()in textmate.ts now checks for=before-/+tokens, treating them as unary when preceded by assignmentyieldto no-space-before-paren list (alongsidefunc,assert,export)signaltokenization scope-aware: keyword in declarations, variable in expressionsis_merge_conflict_marker()skips lines starting with<<<<<<<,=======, or>>>>>>>entirely, preventing the formatter from corrupting git conflict markers (Autoformatter Incorrectly Formats Merge Conflicts #850)inLambdaBodyflag on tokens tracks when we're inside a lambda body that's a function call argument — dense parameter formatting is suppressed for lambda body content so assignments keep their spaces (Formatting issue of lambda functions #938)1e-6is correctly tokenized as a singleconstant.numeric.float.gdscripttoken by the grammar — verified, was already fixed (Formatter adds space inside float literal with negative exponent. #928)Setting enhancement (#1004)
maxEmptyLineschanged fromenum ["1","2"]tonumberwithminimum: 0, default2Test infrastructure
in.gd/out.gddirectory pairs converted to single inline.gdfilesget_options()helper fromformatter.test.tstest.gd→trailing_newlines.gd, mergedscientific_notation.gd→float_notation.gd, mergedself_keyword_spacing.gd→keywords.gdNew test files for previously uncovered features
annotations.gd—@export,@onready,@rpc,@warning_ignore,@abstract, stacked annotationscontrol_flow.gd—if/elif/else,for..in,while, ternaryif,pass/break/continuedeclarations.gd— return types,class_name,extends,signal,static,constdense_params.gd—denseFunctionParametersconfig option, lambda body spacing (Formatting issue of lambda functions #938)dictionaries.gd— dict literals, nested/typed dicts, subscript accessgodot3_compat.gd—tool,export,onready,remote/master/puppetkeywords,setgetsyntax,yield()is_as_operator.gd—is/is notandasoperatorsmerge_conflict.gd— git conflict markers left untouched (Autoformatter Incorrectly Formats Merge Conflicts #850)method_calls.gd— function call spacing, method chainstrailing_newlines.gd—strictTrailingNewlinesconfigTest plan
matchand spaced function calls looks correct in VS CodemaxEmptyLinesaccepts any non-negative integer in settingsdenseFunctionParameters: true