-
Notifications
You must be signed in to change notification settings - Fork 19
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
Enhancement/custom uni UI lint #1400
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1400 +/- ##
=======================================
Coverage 12% 12%
=======================================
Files 264 264
Lines 7223 7223
=======================================
Hits 815 815
Misses 6408 6408 |
c8e76b4
to
9142c2d
Compare
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.
Good progress so far, but some things are still needed before we can merge this PR
@limwa I think everything is solved, please do let me know if anything else is missing! |
NoStringLiteralsInWidgetsLint() : super(code: _code); | ||
|
||
static const _code = LintCode( | ||
name: 'string_literals_lint', |
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.
name: 'string_literals_lint', | |
name: 'no_string_literals_in_widgets', |
custom_lint: | ||
debug: true | ||
rules: | ||
- string_literals_lint |
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.
- string_literals_lint | |
- no_string_literals_in_widgets |
context.registry.addStringLiteral((node) { | ||
final fileUri = node.thisOrAncestorOfType<CompilationUnit>()?.declaredElement?.source?.uri; | ||
final fileName = fileUri?.pathSegments.last; | ||
if (isInsideWidgetClass(node) && fileName != "main.dart") { |
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.
String literals inside functions inside widgets will also trigger the lint.
So the suggestion is incomplete and there is still some more code missing. What is the AST node responsible for the construction of a widget? (what node corresponds to Text("hi")?) Because then we might be able to target that node type instead.
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.
I guess string literals in functions should be avoided as well, right? We can follow the same method, passing them as parameters
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.
Not really, I might want to do something like Navigator.push('/...')
, which would incorrectly generate a warning with this lint...
I'm trying to think of easy ways to fix this, but I think the only way would be doing a check if the function call returns a widget or something like that...
closes #1385