This PR introduces a new lint loop_for_while that detects and suggests replacing unnecessary loop constructs with while loops, improving code clarity and conciseness.
Changes Made β‘οΈ
Implementation of loop_for_while Lint
Added a new lint in plugin.rs to detect loop constructs that can be replaced by while loops.
Implemented the fix logic in fix.rs, ensuring that the conversion from loop to while preserves the original logic while simplifying the code structure.
Added diagnostic and fix logic in loop_for_while.rs to handle conditions and loop bodies appropriately.
Test Coverage π₯·πΌ
Added test cases in test_files/loop_for_while to validate the loop_for_while lint:
Conversion of a simple loop with a comparison condition to a while.
Handling of loop with multiple conditions involving logical operators.
Conversion of a loop with arithmetic conditions.
Ensured that the while loop correctly reflects the logic of the original loop.
Test Results β
All tests have passed successfully, confirming that the loop_for_while lint works as intended and improves the readability of the code.
Summary π
This PR closes issue #34
This PR introduces a new lint
loop_for_while
that detects and suggests replacing unnecessaryloop
constructs withwhile
loops, improving code clarity and conciseness.Changes Made β‘οΈ
Implementation of
loop_for_while
Lintplugin.rs
to detectloop
constructs that can be replaced bywhile
loops.fix.rs
, ensuring that the conversion fromloop
towhile
preserves the original logic while simplifying the code structure.loop_for_while.rs
to handle conditions and loop bodies appropriately.Test Coverage π₯·πΌ
test_files/loop_for_while
to validate theloop_for_while
lint:loop
with a comparison condition to awhile
.loop
with multiple conditions involving logical operators.loop
with arithmetic conditions.while
loop correctly reflects the logic of the originalloop
.Test Results β
All tests have passed successfully, confirming that the
loop_for_while
lint works as intended and improves the readability of the code.