Skip to content

Commit

Permalink
Allow usage of a forbidden item in a hide combinator (#352)
Browse files Browse the repository at this point in the history
* Allow usage of a forbidden item in a `hide` combinator

* Release leancode_lint v14.1.0

* Check isInHide once per node
  • Loading branch information
shilangyu authored Sep 2, 2024
1 parent feab933 commit 759193b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/leancode_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 14.1.0

- Allow usage of a forbidden item in a `hide` combinator in `use_design_system_item`

# 14.0.0

- Enable the following lints:
Expand Down
15 changes: 15 additions & 0 deletions packages/leancode_lint/lib/lints/use_instead_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ abstract base class UseInsteadType extends DartLintRule {
Element element,
AstNode node,
) {
if (_isInHide(node)) {
return;
}

for (final (preferredItemName, checker) in _checkers) {
try {
if (checker.isExactly(element)) {
Expand All @@ -96,4 +100,15 @@ abstract base class UseInsteadType extends DartLintRule {
}
}
}

bool _isInHide(AstNode node) {
if (node.parent case final parent?) {
if (parent is HideCombinator) {
return true;
}
return _isInHide(parent);
} else {
return false;
}
}
}
2 changes: 1 addition & 1 deletion packages/leancode_lint/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: leancode_lint
version: 14.0.0
version: 14.1.0
homepage: https://github.com/leancodepl/flutter_corelibrary/tree/master/packages/leancode_lint
repository: https://github.com/leancodepl/flutter_corelibrary
description: Robust, high-quality lint rules used at LeanCode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ custom_lint:
LftScaffold:
- instead_of: Scaffold
from_package: flutter
LftPlaceholder:
- instead_of: Placeholder
from_package: flutter
- prefix_widgets_returning_slivers:
application_prefix: Lncd
# TODO: remove explicit enable once enabled by default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// for tests
// ignore_for_file: unused_local_variable

import 'package:flutter/material.dart';
import 'package:flutter/material.dart'
// `Placeholder` is forbidden, we check that no lint is raised for a `hide`
hide
Placeholder;

class SampleWidget extends StatelessWidget {
const SampleWidget({super.key});
Expand Down

0 comments on commit 759193b

Please sign in to comment.