-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: disable avoid_hardcoded_color lint if it's a test file #83
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/altive_lints/example/lints/avoid_hardcoded_color_test.dart
This file contains 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,28 @@ | ||
// Check the `avoid_hardcoded_color` rule. | ||
// | ||
// This file ends with the name `_test.dart`, | ||
// so it should be exempt from the warning. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class MyWidget extends StatelessWidget { | ||
const MyWidget({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
const ColoredBox(color: Color(0xFF00FF00)), | ||
const ColoredBox(color: Color.fromRGBO(0, 255, 0, 1)), | ||
const ColoredBox(color: Colors.green), | ||
ColoredBox(color: Theme.of(context).colorScheme.primary), | ||
ColoredBox(color: _colorScheme.primary), | ||
const ColoredBox(color: Colors.transparent), | ||
], | ||
); | ||
} | ||
} | ||
|
||
ColorScheme get _colorScheme => const ColorScheme.dark( | ||
primary: Color.fromRGBO(0, 255, 0, 1), | ||
); |
27 changes: 27 additions & 0 deletions
27
packages/altive_lints/example/test/avoid_hardcoded_color.dart
This file contains 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,27 @@ | ||
// Check the `avoid_hardcoded_color` rule. | ||
// | ||
// It should exclude warnings for the entire `test` directory. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class MyWidget extends StatelessWidget { | ||
const MyWidget({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
const ColoredBox(color: Color(0xFF00FF00)), | ||
const ColoredBox(color: Color.fromRGBO(0, 255, 0, 1)), | ||
const ColoredBox(color: Colors.green), | ||
ColoredBox(color: Theme.of(context).colorScheme.primary), | ||
ColoredBox(color: _colorScheme.primary), | ||
const ColoredBox(color: Colors.transparent), | ||
], | ||
); | ||
} | ||
} | ||
|
||
ColorScheme get _colorScheme => const ColorScheme.dark( | ||
primary: Color.fromRGBO(0, 255, 0, 1), | ||
); |
File renamed without changes.
This file contains 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 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 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,7 @@ | ||
import 'package:analyzer/source/source.dart'; | ||
|
||
/// Whether the given [source] is a test file. | ||
bool isTestFile(Source source) { | ||
return source.uri.pathSegments.contains('test') || | ||
source.shortName.endsWith('_test.dart'); | ||
} |
This file contains 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 |
---|---|---|
|
@@ -18,3 +18,6 @@ dependencies: | |
analyzer: ^6.7.0 | ||
collection: ^1.18.0 | ||
custom_lint_builder: ^0.7.0 | ||
|
||
dev_dependencies: | ||
test: ^1.25.14 |
35 changes: 35 additions & 0 deletions
35
packages/altive_lints/test/src/utils/files_utils_test.dart
This file contains 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,35 @@ | ||
import 'package:altive_lints/src/utils/files_utils.dart'; | ||
import 'package:analyzer/file_system/physical_file_system.dart'; | ||
import 'package:analyzer/source/file_source.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('isTestFile', () { | ||
test('False if it is a not test file', () { | ||
final resourceProvider = PhysicalResourceProvider.INSTANCE; | ||
|
||
const filePath = '/project/lib/src/implementation.dart'; | ||
final file = resourceProvider.getFile(filePath); | ||
final source = FileSource(file); | ||
expect(isTestFile(source), isFalse); | ||
}); | ||
|
||
test('True if it is a test file', () { | ||
final resourceProvider = PhysicalResourceProvider.INSTANCE; | ||
|
||
const filePath = '/project/lib/src/implementation_test.dart'; | ||
final file = resourceProvider.getFile(filePath); | ||
final source = FileSource(file); | ||
expect(isTestFile(source), isTrue); | ||
}); | ||
|
||
test('True if it is a test directory', () { | ||
final resourceProvider = PhysicalResourceProvider.INSTANCE; | ||
|
||
const filePath = '/project/test/src/util.dart'; | ||
final file = resourceProvider.getFile(filePath); | ||
final source = FileSource(file); | ||
expect(isTestFile(source), isTrue); | ||
}); | ||
}); | ||
} |
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.
Removed
_test
from the filename because it does not confirm thetest
directory if_test
is added to the filename!