-
Notifications
You must be signed in to change notification settings - Fork 1
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
Docs/website #112
Open
pattobrien
wants to merge
30
commits into
master
Choose a base branch
from
docs/website
base: master
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
Docs/website #112
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
40d8d53
docs: Hello World full tutorial example.
pattobrien 5fa5d1b
docs: Hello world code snippets.
pattobrien 063379c
docs: Application layer example code.
pattobrien 40fc2c4
docs: Bloc feature-first snippets.
pattobrien b45ce01
docs: Delete placeholder tutorial pages.
pattobrien a780840
test: Fixed sourceLocationFromJson
pattobrien 783e56f
docs: Index page text changes.
pattobrien 033403a
docs: Undraw images, blue style for entire site.
pattobrien 6ac6bcb
docs: Discord invite link.
pattobrien 5e93820
docs: Introduction page and tutorial page.
pattobrien 8ef16f2
docs: Initial setup CLI image, removed old usage guide placeholders.
pattobrien ac7307b
docs: Removed docusaurus nav bar icon.
pattobrien 418ff7c
docs: Usage rewording.
pattobrien b3356f5
docs: Add gitignore for snippets.
pattobrien 35fb54c
docs: Delete log files.
pattobrien 1902d69
docs: Make unfinished tutorials private.
pattobrien 694b151
docs: Hello world completed tutorial.
pattobrien 929be37
docs: Bloc file structure guide cleanup.
pattobrien 5e2266f
feat: generateSnippet shows particular snippets.
pattobrien d46c681
feat: TypeChecker core concepts.
pattobrien a34fa16
docs: TypeChecking finalized docs.
pattobrien ab74851
docs: Rule Creation table with available sidecar_lints.
pattobrien a6300d9
docs: Hello world tutorial fixes.
pattobrien d9a51f4
docs: Feature-first project structure tutorial.
pattobrien d83b047
Merge branch 'master' into docs/website
pattobrien 5781be5
chore: Upgrade to Sidecar v0.1.0-dev.21.
pattobrien fccac33
docs: Testing documentation.
pattobrien 4368174
docs: Integration Testing documentation.
pattobrien b928da7
docs: Warning message on intro page.
pattobrien 45f6970
test: Test change to see if codecov is triggered.
pattobrien 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ include: package:lints/recommended.yaml | |
|
||
analyzer: | ||
plugins: | ||
- sidecar | ||
# - sidecar |
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,49 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "sidecar", | ||
"request": "launch", | ||
"type": "dart" | ||
}, | ||
{ | ||
"name": "snippets", | ||
"cwd": "docs/usage/snippets", | ||
"request": "launch", | ||
"type": "dart" | ||
}, | ||
{ | ||
"name": "snippets (profile mode)", | ||
"cwd": "docs/usage/snippets", | ||
"request": "launch", | ||
"type": "dart", | ||
"flutterMode": "profile" | ||
}, | ||
{ | ||
"name": "snippets (release mode)", | ||
"cwd": "docs/usage/snippets", | ||
"request": "launch", | ||
"type": "dart", | ||
"flutterMode": "release" | ||
}, | ||
{ | ||
"name": "bloc_feature_structure", | ||
"program": "lib/src/tutorials/bloc_feature_structure/example/.dart_tool/sidecar/debug.dart", | ||
"request": "launch", | ||
"type": "dart", | ||
"args": [ | ||
"--enable-vm-service", | ||
"--debug", | ||
] | ||
}, | ||
{ | ||
"name": "hello_world", | ||
"cwd": "lib/src/tutorials/hello_world", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"label": "Core Concepts", | ||
"position": 3, | ||
"link": { | ||
pattobrien marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"type": "generated-index" | ||
} | ||
} |
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,45 @@ | ||
--- | ||
title: Integration Testing | ||
sidebar_position: 3 | ||
description: "" | ||
--- | ||
|
||
import CodeBlock from '@theme/CodeBlock'; | ||
import testing from "!!raw-loader!./snippets/testing.dart"; | ||
import { | ||
trimSnippet, | ||
generateSnippet, | ||
CodeSnippet, | ||
} from "../../src/components/CodeSnippet"; | ||
|
||
Sidecar ships with a series of test utilities that make it easy to write integration tests for Sidecar rules. | ||
|
||
When writing rule tests, we must create a string containing example code that we expect to trigger or not trigger a lint. | ||
|
||
The below snippet shows code that we would expect to show a lint for the `avoid_edge_insets_literal` rule from design_system_lints. The rule | ||
is expected to find values used in an `EdgeInsets` constructor, and show a lint if that value is not annotated | ||
with `@designSystem` (see [design_system_lints](https://pub.dev/packages/design_system_lints) for | ||
a full explanation of these rules). | ||
|
||
<CodeBlock language="dart">{generateSnippet(testing, ['Content2'])}</CodeBlock> | ||
|
||
In this example, we would expect a lint to be reported underneath the `2.0` value. We can easily test for this, | ||
by writing the following rule in the `test` directory of our rule package: | ||
|
||
<CodeBlock title="test/src/avoid_edge_insets_literal_test.dart" language="dart">{generateSnippet(testing, ['StartTest', 'TestEnd', 'RuleTest2' ])}</CodeBlock> | ||
|
||
Before we can run any rule test, we must first use the `setUpRules` function with the particular rule we're looking to test (here, `AvoidEdgeInsetsLiteral`). | ||
We can then use the `ExpectedText` test utility to check if a lint is found over the particular code `2.0`. We also make | ||
the test description `EdgeInsets.all`, as that's exactly the use case we're testing for. | ||
|
||
If we want to test that a lint is found when using a different instantiation of `EdgeInsets` (e.g. `EdgeInsets.only`), | ||
we can create another test that checks each of the parameters given to `EdgeInsets.only` (i.e. `left`, `right`, `top`, `bottom`) | ||
by writing 4 different `ExpectedText` values and providing them to our `ruleTest`: | ||
|
||
<CodeBlock language="dart">{generateSnippet(testing, ['Imports', 'StartTest', 'TestEnd', 'RuleTest3', 'Content3'])}</CodeBlock> | ||
|
||
Finally, if we write a test where we expect no lints (such as when our `EdgeInset` values are annotated with `@designSystem`), | ||
we simply simply leave the `ExpectedText` array empty for our `ruleTest`: | ||
|
||
<CodeBlock language="dart">{generateSnippet(testing, ['Imports', 'StartTest', 'TestEnd', 'RuleTest1', 'Content1'])}</CodeBlock> | ||
|
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,26 @@ | ||
--- | ||
title: Rule Creation Checklist | ||
sidebar_position: 1 | ||
description: "" | ||
--- | ||
|
||
import CodeBlock from '@theme/CodeBlock'; | ||
import { | ||
trimSnippet, | ||
CodeSnippet, | ||
} from "../../src/components/CodeSnippet"; | ||
|
||
If you're creating a new lint rule and lints are not appearing in the IDE of an example project, | ||
you can follow this checklist for requirements. | ||
|
||
|
||
| Description | Examples | Lints Available | | ||
|---------------------------------------------|---------|:----------------:| | ||
| Rule has a unique RuleCode ID in snake_case | `LintCode('avoid_edge_insets_literal')` | ✅ | | ||
| The Rule's ClassName is the PascalCase equivalent of the RuleCode ID | `class AvoidEdgeInsetsLiteral extends LintRule {...}` | ✅ | | ||
| The `code.package` value matches the name given to the rule package | `LintCode(..., package: 'design_system_lints')` | ✅ | | ||
| Lint Rule is exported from `lib/<package_name>.dart` | | 🚧 | | ||
|
||
|
||
It's recommended that you use the lints included in [`package:sidecar_lints`](https://pub.dev/packages/sidecar_lints) to enforce the above rules | ||
on your Sidecar-based rule package. |
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,66 @@ | ||
/* SNIP Imports */ | ||
import 'package:design_system_lints/design_system_lints.dart'; | ||
import 'package:sidecar/test.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
/* SNIP Imports END */ | ||
/* SNIP Content1 */ | ||
const contentDesignSystem = ''' | ||
import 'package:design_system_annotations/design_system_annotations.dart'; | ||
import 'package:flutter/material.dart'; | ||
@designSystem | ||
class DesignSystemX { | ||
static const value = 3.1; | ||
} | ||
final edgeInsets = EdgeInsets.all(DesignSystemX.value); | ||
'''; | ||
/* SNIP Content1 END */ | ||
/* SNIP Content2 */ | ||
const contentEdgeInsetsAll = ''' | ||
import 'package:flutter/material.dart'; | ||
class MyWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: EdgeInsets.all(2.0), | ||
); | ||
} | ||
} | ||
'''; | ||
/* SNIP Content2 END */ | ||
/* SNIP Content3 */ | ||
const contentEdgeInsetsOnly = ''' | ||
import 'package:flutter/material.dart'; | ||
class MyWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: EdgeInsets.only(left: 1.1, right: 1.2, top: 1.3, bottom: 1.4), | ||
); | ||
} | ||
} | ||
'''; | ||
/* SNIP Content3 END */ | ||
/* SNIP StartTest */ | ||
void main() { | ||
group('avoid_edge_insets_literal:', () { | ||
setUpRules([AvoidEdgeInsetsLiteral()]); | ||
/* SNIP StartTest END */ | ||
/* SNIP RuleTest1 */ | ||
ruleTest('EdgeInsets using Design System', contentDesignSystem, []); | ||
/* SNIP RuleTest1 END */ | ||
/* SNIP RuleTest2 */ | ||
ruleTest('EdgeInsets.all', contentEdgeInsetsAll, [ExpectedText('2.0')]); | ||
/* SNIP RuleTest2 END */ | ||
/* SNIP RuleTest3 */ | ||
ruleTest('EdgeInsets.only', contentEdgeInsetsOnly, [ | ||
ExpectedText('1.1'), | ||
ExpectedText('1.2'), | ||
ExpectedText('1.3'), | ||
ExpectedText('1.4'), | ||
]); | ||
/* SNIP RuleTest3 END */ | ||
/* SNIP TestEnd */ | ||
}); | ||
} | ||
/* SNIP TestEnd END */ |
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,44 @@ | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:sidecar/sidecar.dart'; | ||
|
||
/* SNIP TypeChecker */ | ||
// 1. Create the TypeChecker | ||
const statelessWidget = | ||
TypeChecker.fromPackage('StatelessWidget', package: 'flutter'); | ||
|
||
/* SNIP TypeChecker END */ | ||
/* SNIP ClassStart */ | ||
class MyLint extends LintRule { | ||
/* SNIP ClassStart END */ | ||
@override | ||
LintCode get code => throw UnimplementedError(); | ||
|
||
@override | ||
void initializeVisitor(NodeRegistry registry) { | ||
// TODO: implement initializeVisitor | ||
} | ||
/* SNIP VisitMethod */ | ||
@override | ||
void visitInstanceCreationExpression(InstanceCreationExpression node) { | ||
// 2. Use the TypeChecker to check the type of a particular AstNode | ||
final returnType = node.constructorName.staticElement?.returnType; | ||
if (statelessWidget.isAssignableFromType(returnType)) { | ||
// do something | ||
} | ||
} | ||
/* SNIP VisitMethod END */ | ||
/* SNIP ClassEnd */ | ||
} | ||
/* SNIP ClassEnd END */ | ||
|
||
/* SNIP DartType */ | ||
@override | ||
void visitInstanceCreationExpression(InstanceCreationExpression node) { | ||
// 2. Use the TypeChecker to check the type of a particular AstNode | ||
const colorTypeChecker = TypeChecker.fromDart('Color', package: 'ui'); | ||
final returnType = node.constructorName.staticElement?.returnType; | ||
if (colorTypeChecker.isAssignableFromType(returnType)) { | ||
// do something | ||
} | ||
} | ||
/* SNIP DartType END */ |
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,35 @@ | ||
--- | ||
title: Type Checking | ||
sidebar_position: 2 | ||
description: "" | ||
--- | ||
|
||
import CodeBlock from '@theme/CodeBlock'; | ||
import dartTypeChecker from "!!raw-loader!./snippets/type_checking.dart"; | ||
import { | ||
generateSnippet, | ||
CodeSnippet, | ||
} from "../../src/components/CodeSnippet"; | ||
|
||
When creating a lint rule, you will often need to check if a node is of a certain type. | ||
For example, you may want to find all class declarations which extend | ||
`StatelessWidget` in order to perform some analysis on them. | ||
|
||
Unfortunately, we cannot just use the `is` keyword to check if a node is of a certain type, | ||
because the analyzer can only provide us with `DartType` objects, which are not the same as | ||
the `Type` objects we'd typically use when checking types in Dart programs. | ||
|
||
Fortunately, Sidecar ships with its own `TypeChecker` utility, which provides an easy | ||
way for checking if an AstNode is of a certain type: | ||
|
||
<CodeBlock language="dart">{generateSnippet(dartTypeChecker, ['TypeChecker', 'ClassStart', 'ClassEnd', 'VisitMethod'])}</CodeBlock> | ||
|
||
There are two notable ways to create a TypeChecker: | ||
|
||
- `TypeChecker.fromName` - Used for non-Dart packages | ||
- `TypeChecker.fromDartType` - Used for `dart` packages like `dart:core` or `dart:async` | ||
|
||
|
||
<CodeBlock language="dart">{generateSnippet(dartTypeChecker, ['DartType'])}</CodeBlock> | ||
|
||
In both cases, the utility takes the name of the Type and the name of the Type's package. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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.
Test comment