-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from fusion44/feat/analyzer_plugin
Create jaspr_lints package
- Loading branch information
Showing
32 changed files
with
1,465 additions
and
49 deletions.
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
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,207 @@ | ||
--- | ||
title: Linting | ||
description: Jaspr comes with its own set of lint rules and code assists. | ||
--- | ||
|
||
Jaspr has its own linting and analyzer package called `jaspr_lints`. This comes pre-configured | ||
with every new project and enables the following set of lint rules and code assists: | ||
|
||
## Lint Rules | ||
|
||
<Card> | ||
<Property name="prefer_html_methods" type="Fix available"> | ||
Prefer html methods like `div(...)` over `DomComponent(tag: 'div', ...)`. | ||
|
||
**BAD:** | ||
```dart | ||
yield DomComponent( | ||
tag: 'div', | ||
children: [ | ||
DomComponent( | ||
tag: 'p', | ||
child: Text('Hello World'), | ||
), | ||
], | ||
); | ||
``` | ||
|
||
**GOOD:** | ||
```dart | ||
yield div([ | ||
p([text('Hello World')]), | ||
]); | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="sort_children_properties_last" type="Fix available"> | ||
Sort children properties last in html component methods. | ||
|
||
This improves readability and best represents actual html. | ||
|
||
**BAD:** | ||
```dart | ||
yield div([ | ||
p([text('Hello World')], classes: 'text-red'), | ||
], id: 'main'); | ||
``` | ||
|
||
**GOOD:** | ||
```dart | ||
yield div(id: 'main', [ | ||
p(classes: 'text-red', [text('Hello World')]), | ||
]); | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
## Code Assists | ||
|
||
<Card> | ||
<Property name="Create StatelessComponent" type="Top level"> | ||
Creates a new `StatelessComponent` class. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Create StatefulComponent" type="Top level"> | ||
Creates a new `StatefulComponent` and respective `State` class. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Create InheritedComponent" type="Top level"> | ||
Creates a new `InheritedComponent` class. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Convert to StatefulComponent" type="Class level"> | ||
Converts a custom `StatelessComponent` into a `StatefulComponent` and respective `State` class. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Convert to AsyncStatelessComponent" type="Class level"> | ||
Converts a custom `StatelessComponent` into an `AsyncStatelessComponent`. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Remove this component" type="Component tree level"> | ||
Surgically removes the selected component from the component tree, making its | ||
children the new direct children of its parent. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Wrap with html..." type="Component tree level"> | ||
Wraps the selected component with a new html component. | ||
|
||
```dart | ||
yield div([ | ||
p([ // [!code ++] | ||
span([text('Hello World')]), | ||
]), // [!code ++] | ||
]); | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Wrap with component..." type="Component tree level"> | ||
Wraps the selected component with a new component. | ||
|
||
```dart | ||
yield div([ | ||
MyComponent( // [!code ++] | ||
child: span([text('Hello World')]), | ||
), // [!code ++] | ||
]); | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Wrap with Builder" type="Component tree level"> | ||
Wraps the selected component with a `Builder`. | ||
|
||
```dart | ||
yield div([ | ||
Builder(builder: (context) sync* { // [!code ++] | ||
yield span([text('Hello World')]); | ||
}), // [!code ++] | ||
]); | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Extract component" type="Component tree level"> | ||
Extracts the selected component plus subtree into a new `StatelessComponent`. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Add styles" type="Component tree level"> | ||
Adds new css styles to the selected component. | ||
|
||
This will either add a new class name: | ||
```dart | ||
yield div( | ||
classes: '[...]' // [!code ++] | ||
[], | ||
); | ||
|
||
/* ... */ | ||
|
||
@css // [!code ++] | ||
static List<StyleRule> styles = [ // [!code ++] | ||
css('.[...]').box(...), // [!code ++] | ||
]; // [!code ++] | ||
``` | ||
|
||
Or use an existing id or class name: | ||
```dart | ||
yield div(id: 'content', []); | ||
|
||
/* ... */ | ||
|
||
@css // [!code ++] | ||
static List<StyleRule> styles = [ // [!code ++] | ||
css('#content').box(...), // [!code ++] | ||
]; // [!code ++] | ||
``` | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Convert to web-only import" type="Directive level"> | ||
Converts any import to a web-only import using the [@Import](/utils/at_import) annotation. | ||
|
||
```dart | ||
import 'dart:html'; // [!code --] | ||
@Import.onWeb('dart:html', show: [#window]) // [!code ++] | ||
import 'filename.imports.dart'; // [!code ++] | ||
``` | ||
|
||
This will auto-detect all used members from the import and add them to the `show` parameter. | ||
</Property> | ||
</Card> | ||
|
||
<Card> | ||
<Property name="Convert to server-only import"> | ||
Converts any import to a server-only import using the [@Import](/utils/at_import) annotation. | ||
|
||
```dart | ||
import 'dart:io'; // [!code --] | ||
@Import.onServer('dart:io', show: [#HttpRequest]) // [!code ++] | ||
import 'filename.imports.dart'; // [!code ++] | ||
``` | ||
|
||
This will auto-detect all used members from the import and add them to the `show` parameter. | ||
</Property> | ||
</Card> |
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
Submodule build
updated
5 files
+4 −0 | build_modules/CHANGELOG.md | |
+2 −2 | build_modules/pubspec.yaml | |
+4 −0 | jaspr_web_compilers/CHANGELOG.md | |
+2 −2 | jaspr_web_compilers/pubspec.yaml | |
+3 −0 | mlc_config.json |
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
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,42 @@ | ||
import 'dart:io'; | ||
|
||
import '../logging.dart'; | ||
import 'base_command.dart'; | ||
|
||
class AnalyzeCommand extends BaseCommand { | ||
AnalyzeCommand({super.logger}) { | ||
argParser.addFlag( | ||
'fatal-infos', | ||
help: 'Treat info level issues as fatal', | ||
defaultsTo: true, | ||
); | ||
argParser.addFlag( | ||
'fatal-warnings', | ||
help: 'Treat warning level issues as fatal', | ||
defaultsTo: true, | ||
); | ||
argParser.addFlag( | ||
'fix', | ||
help: 'Apply all possible fixes to the lint issues found.', | ||
negatable: false, | ||
); | ||
} | ||
|
||
@override | ||
String get description => 'Report Jaspr specific lint warnings.'; | ||
|
||
@override | ||
String get name => 'analyze'; | ||
|
||
@override | ||
String get category => 'Tooling'; | ||
|
||
@override | ||
Future<CommandResult?> run() async { | ||
await super.run(); | ||
|
||
var process = await Process.start('dart', ['run', 'custom_lint', ...?argResults?.arguments]); | ||
|
||
return CommandResult.running(watchProcess('custom_lint', process, tag: Tag.none), stop); | ||
} | ||
} |
Oops, something went wrong.