Skip to content
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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

Pinho13
Copy link
Contributor

@Pinho13 Pinho13 commented Nov 26, 2024

closes #1385

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 12%. Comparing base (3cd50d8) to head (b954bac).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #1400   +/-   ##
=======================================
  Coverage       12%     12%           
=======================================
  Files          264     264           
  Lines         7223    7223           
=======================================
  Hits           815     815           
  Misses        6408    6408           

@limwa limwa force-pushed the enhancement/Custom_Uni_UI_Lint branch from c8e76b4 to 9142c2d Compare December 9, 2024 16:35
@limwa limwa mentioned this pull request Dec 9, 2024
7 tasks
@Pinho13 Pinho13 requested review from thePeras and DGoiana December 27, 2024 15:21
@thePeras thePeras requested a review from limwa December 27, 2024 16:23
Copy link
Member

@limwa limwa left a 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

packages/uni_lint/lib/uni_lint.dart Outdated Show resolved Hide resolved
packages/uni_lint/lib/uni_lint.dart Outdated Show resolved Hide resolved
packages/uni_lint/lib/uni_lint.dart Outdated Show resolved Hide resolved
packages/uni_lint/lib/uni_lint.dart Outdated Show resolved Hide resolved
packages/uni_lint/lib/uni_lint.dart Outdated Show resolved Hide resolved
packages/uni_ui/pubspec.yaml Outdated Show resolved Hide resolved
packages/uni_lint/pubspec.lock Outdated Show resolved Hide resolved
packages/uni_ui/pubspec.lock Outdated Show resolved Hide resolved
packages/uni_ui/analysis_options.yaml Outdated Show resolved Hide resolved
@Pinho13
Copy link
Contributor Author

Pinho13 commented Jan 1, 2025

@limwa I think everything is solved, please do let me know if anything else is missing!

@Pinho13 Pinho13 requested a review from limwa January 1, 2025 21:53
NoStringLiteralsInWidgetsLint() : super(code: _code);

static const _code = LintCode(
name: 'string_literals_lint',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: 'string_literals_lint',
name: 'no_string_literals_in_widgets',

custom_lint:
debug: true
rules:
- string_literals_lint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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") {
Copy link
Member

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.

Copy link
Collaborator

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

Copy link
Member

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create uni_ui custom lint rule to avoid string literals
4 participants