Skip to content

Commit

Permalink
Merge pull request #2771 from asashour/2416
Browse files Browse the repository at this point in the history
Fix curly_braces_in_flow_control_structures when "if" is "else" of previous "if"
  • Loading branch information
bwilkerson committed Jul 16, 2021
2 parents efb0eec + d0e81b6 commit 495f3c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# master

- New lint: `eol_at_end_of_file`
- Fix false negative case of else-if in `curly_braces_in_flow_control_structures.dart`
- Update `analyzer` constraint to `>=2.0.0 <3.0.0`.

# 1.7.1
Expand Down
5 changes: 5 additions & 0 deletions lib/src/rules/curly_braces_in_flow_control_structures.dart
Expand Up @@ -89,6 +89,11 @@ class _Visitor extends SimpleAstVisitor {
void visitIfStatement(IfStatement node) {
var elseStatement = node.elseStatement;
if (elseStatement == null) {
var parent = node.parent;
if (parent is IfStatement && node == parent.elseStatement) {
_check(node.thenStatement);
return;
}
if (node.thenStatement is Block) return;

var unit = node.root as CompilationUnit;
Expand Down
7 changes: 7 additions & 0 deletions test_data/rules/curly_braces_in_flow_control_structures.dart
Expand Up @@ -55,6 +55,13 @@ testIfElse() {

if (false) { print('should be on next line'); // OK
}

if (true) {
} else if (true) return; //LINT

if (true) {
} else if (true)
return; //LINT
}

testWhile() {
Expand Down

0 comments on commit 495f3c4

Please sign in to comment.