feat: add avoid_hardcoded_unicode lint rule (generalized from avoid_hardcoded_japanese)#100
Draft
feat: add avoid_hardcoded_unicode lint rule (generalized from avoid_hardcoded_japanese)#100
Conversation
…ardcoded_japanese)
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new lint rule, avoid_hardcoded_unicode, generalizing the previous avoid_hardcoded_japanese rule to detect hardcoded string literals containing characters outside the allowed ASCII range.
- Added rule implementation in packages/altive_lints/lib/src/lints/avoid_hardcoded_unicode.dart
- Updated rule registration in altive_lints.dart and all_lint_rules.yaml
- Included tests and examples in the packages/altive_lints/example directory
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/altive_lints/lib/src/lints/avoid_hardcoded_unicode.dart | Implements the new lint rule to check for disallowed Unicode characters in string literals and interpolations |
| packages/altive_lints/lib/altive_lints.dart | Registers the new lint rule with the plugin |
| packages/altive_lints/lib/all_lint_rules.yaml | Adds the new lint rule to the configuration |
| packages/altive_lints/example/test/avoid_hardcoded_unicode.dart | Provides test cases ensuring the rule is inactive in test files |
| packages/altive_lints/example/lints/avoid_hardcoded_unicode_test.dart | Confirms the test exemption based on file naming |
| packages/altive_lints/example/lints/avoid_hardcoded_unicode.dart | Tests the rule detection with expected lint comments |
| }); | ||
|
|
||
| context.registry.addStringInterpolation((node) { | ||
| final stringValue = node.toSource(); |
There was a problem hiding this comment.
[nitpick] Using node.toSource() to retrieve the content of a string interpolation may include extra syntax artifacts from the interpolation itself. Consider extracting just the literal parts if possible to avoid potential false positives.
Suggested change
| final stringValue = node.toSource(); | |
| final stringValue = node.elements | |
| .whereType<InterpolationString>() | |
| .map((e) => e.value) | |
| .join(); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces a new lint rule: avoid_hardcoded_unicode.\n\n- Detects hardcoded string literals containing characters outside a configurable ASCII range (default: 0x20-0x7E).\n- Generalizes the previous avoid_hardcoded_japanese rule.\n- Includes tests and documentation.\n\nPlease review.