-
Notifications
You must be signed in to change notification settings - Fork 24
Migrate newline before return rule and its tests #240
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
Merged
daria-trusca-solid
merged 7 commits into
analysis_server_migration
from
migrate_newline_before_return_visitor
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
19f2b80
Updated newline_before_return_visitor rule and its visitor
daria-trusca-solid 2f42ec8
Merged tests for newline_return_rule
daria-trusca-solid 87ef2fc
Delete previous test file for newline_before_return
daria-trusca-solid 3488af1
Updated min version of sdk
daria-trusca-solid a8f5da1
Added safety handle for the null case
daria-trusca-solid 8134563
Update newline_before_return_rule_test.dart
daria-trusca-solid ba7d7fb
Merge branch 'analysis_server_migration' into migrate_newline_before_…
daria-trusca-solid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
171 changes: 171 additions & 0 deletions
171
test/lints/newline_before_return/newline_before_return_rule_test.dart
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import 'package:analyzer_testing/analysis_rule/analysis_rule.dart'; | ||
| import 'package:solid_lints/src/lints/newline_before_return/newline_before_return_rule.dart'; | ||
| import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
|
||
| void main() { | ||
| defineReflectiveSuite(() { | ||
| defineReflectiveTests(NewlineBeforeReturnRuleTest); | ||
| }); | ||
| } | ||
|
|
||
| @reflectiveTest | ||
| class NewlineBeforeReturnRuleTest extends AnalysisRuleTest { | ||
| @override | ||
| void setUp() { | ||
| rule = NewlineBeforeReturnRule(); | ||
| super.setUp(); | ||
| } | ||
|
|
||
| @override | ||
| String get analysisRule => rule.name; | ||
|
|
||
| void test_reports_no_newline_before_return_value() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| int method() { | ||
| final a = 0; | ||
| return 1; | ||
| } | ||
| ''', | ||
| [lint(32, 9)], | ||
| ); | ||
| } | ||
|
|
||
| void test_reports_no_newline_before_return() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| void method() { | ||
| final a = 0; | ||
| return; | ||
| } | ||
| ''', | ||
| [lint(33, 7)], | ||
| ); | ||
| } | ||
|
|
||
| void test_reports_no_newline_before_return_with_comment() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| void method() { | ||
| final a = 0; | ||
| // Comment | ||
| return; | ||
| } | ||
| ''', | ||
| [lint(46, 7)], | ||
| ); | ||
| } | ||
|
|
||
| void test_reports_no_newline_before_return_with_multiple_comments() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| void method() { | ||
| final a = 0; | ||
| // Comment 1 | ||
| // Comment 2 | ||
| return; | ||
| } | ||
| ''', | ||
| [lint(63, 7)], | ||
| ); | ||
| } | ||
|
|
||
| void test_does_not_report_newline_before_return_with_comment() async { | ||
| await assertNoDiagnostics(r''' | ||
| void method() { | ||
| final a = 0; | ||
|
|
||
| // Comment | ||
| return; | ||
| } | ||
| '''); | ||
| } | ||
|
|
||
| void test_does_not_report_no_newline_before_single_statement_return() async { | ||
| await assertNoDiagnostics(r''' | ||
| void method() { | ||
| return; | ||
| } | ||
| '''); | ||
| } | ||
|
|
||
| void test_does_not_report_newline_before_return() async { | ||
| await assertNoDiagnostics(r''' | ||
| void method() { | ||
| final a = 0; | ||
|
|
||
| return; | ||
| } | ||
| '''); | ||
| } | ||
|
|
||
| void | ||
| test_does_not_report_no_newline_before_single_statement_return_value() async { | ||
| await assertNoDiagnostics(r''' | ||
| int method() { | ||
| return 1; | ||
| } | ||
| '''); | ||
| } | ||
|
|
||
| void | ||
| test_does_not_report_no_newline_before_single_statement_nested_return() async { | ||
| await assertNoDiagnostics(r''' | ||
| class Foo{ | ||
| void bar(void Function()) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void fun() { | ||
| final foo = Foo(); | ||
| foo.bar(() { | ||
| return; | ||
| }); | ||
| } | ||
| '''); | ||
| } | ||
|
|
||
| void test_reports_no_newline_before_return_nested() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| class Foo{ | ||
| void bar(void Function()) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void fun() { | ||
| final foo = Foo(); | ||
| foo.bar(() { | ||
| final a = 1; | ||
| return; | ||
| }); | ||
| } | ||
| ''', | ||
| [lint(130, 7)], | ||
| ); | ||
| } | ||
|
|
||
| void test_reports_no_newline_before_two_return_nested() async { | ||
| await assertDiagnostics( | ||
| r''' | ||
| class Foo{ | ||
| void bar(void Function()) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void fun() { | ||
| final foo = Foo(); | ||
| foo.bar(() { | ||
| final a = 1; | ||
| return; | ||
| }); | ||
| return; | ||
| } | ||
| ''', | ||
| [lint(130, 7), lint(146, 7)], | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case to verify that the lint is correctly reported when there are multiple comments above a
returnstatement without a blank line. This test case will fail with the current implementation due to the bug in_optimalTokenbut will pass once the bug is fixed.