-
-
Notifications
You must be signed in to change notification settings - Fork 110
Description
Description
The NUnit migration code fixer (TUNU0001) occasionally corrupts source files by appending trailing characters to lines, particularly comment lines. This appears to be a text manipulation bug where characters from elsewhere in the file get appended to unrelated lines.
Reproduction Steps
This issue was discovered during a large-scale migration. After running:
dotnet format analyzers --severity info --diagnostics TUNU0001
A license header comment was corrupted:
Before:
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions andAfter:
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.f
// See the License for the specific language governing permissions andNote the trailing f character that was appended to line 12.
Expected Behavior
The code fixer should only modify code related to NUnit-to-TUnit migration. Comment lines and unrelated code should remain unchanged.
Environment
- TUnit Version: 1.11.64
- .NET SDK: 10.0.100-preview.1.25103.12
- OS: Windows 11
Additional Context
This appears to be related to other text manipulation bugs reported:
- TUNU0001 code fixer corrupts code when #region directive follows a comment #4487: Code fixer corrupts code when #region directive follows a comment
- TUNU0001 code fixer leaves orphaned #endif when #if directive is removed #4488: Code fixer leaves orphaned #endif when #if directive is removed
These issues suggest the code fixer's text manipulation logic has edge cases that cause character displacement or corruption when processing complex files.
The corruption is subtle and easy to miss during code review, potentially causing issues later.
Note: Please add tests when fixing this issue to prevent regression. Consider adding tests that verify the fixer doesn't modify lines it shouldn't touch.