Skip to content

fix: remove unexpected space in output format string #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ulivz
Copy link
Member

@ulivz ulivz commented Aug 15, 2025

Summary

Improves the autofix for no-unnecessary-type-assertion rule to properly remove whitespace before 'as' keyword, preventing extra spaces in output.

Close: #280

  • Before: foo() as number -> foo() ;
  • After: foo() as number -> foo();

Edge Case

This Pull Request does not solve an edge case:

  • Source:
const foo = (  3 + 5
  ) /*as*/ as //as
  (
    number
  );
  • Expected:
const foo = (  3 + 5
  ) /*as*/  //as
;
  • Current workaround:
const foo = (  3 + 5
  ) /*as*/;

@Copilot Copilot AI review requested due to automatic review settings August 15, 2025 15:54
Copy link

netlify bot commented Aug 15, 2025

Deploy Preview for rslint canceled.

Name Link
🔨 Latest commit 88a844e
🔍 Latest deploy log https://app.netlify.com/projects/rslint/deploys/689f5a735dbc310008170ef8

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a formatting issue in the autofix functionality of the no-unnecessary-type-assertion rule where extra spaces were being left in the output after removing unnecessary type assertions. The fix ensures that when removing type assertions like foo() as number, the result is properly formatted as foo(); instead of foo() ;.

Key changes:

  • Improved whitespace handling in the autofix logic to include preceding spaces when removing 'as' keyword
  • Simplified the fix generation to use a single removal range instead of multiple separate fixes
  • Updated test expectations to reflect the corrected output format

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
no_unnecessary_type_assertion.go Enhanced autofix logic to properly handle whitespace removal before 'as' keyword and simplified fix generation
no_unnecessary_type_assertion_test.go Updated test case expectation to reflect the corrected output format without extra spaces

@ulivz ulivz changed the title fix: remove unexpected space in output format string WIP: fix: remove unexpected space in output format string Aug 15, 2025
Improves the autofix for no-unnecessary-type-assertion rule to properly
remove whitespace before 'as' keyword, preventing extra spaces in output.

Before: foo() as number -> foo()  ;
After:  foo() as number -> foo();

refactor: remove redundant comments from no_unnecessary_type_assertion

Remove duplicate explanatory comments that were repeating
the obvious functionality of the code below them.
@ulivz ulivz force-pushed the fix/unexpected-space-after-fix branch from e0e5af3 to 9a5f9f4 Compare August 15, 2025 16:00
Add bounds check before accessing sourceText[startPos-2] to prevent
potential panic when startPos-2 < 0.
@ulivz ulivz changed the title WIP: fix: remove unexpected space in output format string fix: remove unexpected space in output format string Aug 15, 2025
@ulivz
Copy link
Member Author

ulivz commented Aug 15, 2025

Updated: I tested the original issue (#280) locally with the fixed build bin and it was verified to be resolved:

Before

image

After

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: An unexpected space after --fix
1 participant