-
Notifications
You must be signed in to change notification settings - Fork 18
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
Pinho13
wants to merge
16
commits into
develop
Choose a base branch
from
enhancement/Custom_Uni_UI_Lint
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1f9da2d
Starter Setup
Pinho13 ae06cd2
enhancement: Started working on String Literal in Widget lint custom …
Pinho13 001a5c3
Minor Changes
Pinho13 9142c2d
analysis_options.yaml updated
Pinho13 4188e4f
chore: segregate lint rules into specific package
limwa c66638d
chore: add custom_lint.log to gitignore
limwa 7dc30f5
Merge branch 'develop' into enhancement/Custom_Uni_UI_Lint
Pinho13 efd0fbb
Lint name and message updated
Pinho13 de4c176
Changed lint search (from searching variable declarations to string l…
Pinho13 fb10bc8
Fixed version
Pinho13 607cca4
Removed pubspec.lock from uni_ui and uni_lint
Pinho13 928ca16
Re-enabled other lint rules
Pinho13 28bd55c
Merge branch 'develop' into enhancement/Custom_Uni_UI_Lint
Pinho13 b954bac
Linter checks for State<> and ignores main.dart
Pinho13 eb00470
Changed Lint Name
Pinho13 3b7e7ea
Merge branch 'develop' into enhancement/Custom_Uni_UI_Lint
Pinho13 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
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 @@ | ||
# uni_lint | ||
|
||
This package contains custom lint rules for uni development. | ||
|
||
Try to keep dependencies to the minimum. This package, ideally, | ||
should not have any dependencies, except for the analyzer package | ||
and custom_lint_builder. |
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,58 @@ | ||
import 'package:analyzer/error/listener.dart'; | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
|
||
PluginBase createPlugin() => UniUILint(); | ||
|
||
class UniUILint extends PluginBase { | ||
@override | ||
List<LintRule> getLintRules(CustomLintConfigs configs) => [ | ||
NoStringLiteralsInWidgetsLint(), | ||
]; | ||
} | ||
|
||
class NoStringLiteralsInWidgetsLint extends DartLintRule { | ||
NoStringLiteralsInWidgetsLint() : super(code: _code); | ||
|
||
static const _code = LintCode( | ||
name: 'string_literals_lint', | ||
problemMessage: 'String literals are not allowed inside a widget. Please pass this value as a parameter for the widget.', | ||
); | ||
|
||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ErrorReporter reporter, | ||
CustomLintContext context, | ||
) { | ||
context.registry.addStringLiteral((node) { | ||
if (isInsideWidgetClass(node) && node.parent is VariableDeclaration) { | ||
reporter.atNode(node, code); | ||
//if (isStringLiteral(node)) { | ||
// reporter.atNode(node, code); | ||
//} | ||
} | ||
}); | ||
} | ||
|
||
bool isInsideWidgetClass(StringLiteral node) { | ||
var parent = node.thisOrAncestorOfType<ClassDeclaration>(); | ||
if (parent == null) return false; | ||
|
||
final extendsClause = parent.extendsClause; | ||
if (extendsClause != null) { | ||
final superclass = extendsClause.superclass; | ||
print(superclass.element?.displayName == "StatelessWidget" || superclass.element?.displayName == "StatefulWidget"); | ||
return superclass.element?.displayName == "StatelessWidget" || superclass.element?.displayName == "StatefulWidget"; | ||
} | ||
return false; | ||
} | ||
|
||
bool isStringLiteral(VariableDeclaration node) { | ||
final initializer = node.initializer; | ||
if (initializer is StringLiteral) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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,18 @@ | ||
name: uni_lint | ||
description: Custom lint rules for Uni. | ||
publish_to: none | ||
version: 1.0.0 | ||
|
||
environment: | ||
sdk: ">=3.4.0 <4.0.0" | ||
# flutter: 3.24.3 | ||
|
||
dependencies: | ||
custom_lint_builder: ^0.6.8 | ||
analyzer: ^6.7.0 | ||
analyzer_plugin: ^0.11.3 | ||
# flutter: | ||
# sdk: flutter | ||
|
||
dev_dependencies: | ||
test: any |
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,8 @@ | ||
analyzer: | ||
plugins: | ||
- custom_lint | ||
|
||
custom_lint: | ||
debug: true | ||
rules: | ||
- string_literals_lint | ||
Pinho13 marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
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.