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

Docs/website #112

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jan 15, 2023
5fa5d1b
docs: Hello world code snippets.
pattobrien Jan 16, 2023
063379c
docs: Application layer example code.
pattobrien Jan 16, 2023
40fc2c4
docs: Bloc feature-first snippets.
pattobrien Jan 17, 2023
b45ce01
docs: Delete placeholder tutorial pages.
pattobrien Jan 17, 2023
a780840
test: Fixed sourceLocationFromJson
pattobrien Jan 17, 2023
783e56f
docs: Index page text changes.
pattobrien Jan 19, 2023
033403a
docs: Undraw images, blue style for entire site.
pattobrien Jan 19, 2023
6ac6bcb
docs: Discord invite link.
pattobrien Jan 19, 2023
5e93820
docs: Introduction page and tutorial page.
pattobrien Jan 19, 2023
8ef16f2
docs: Initial setup CLI image, removed old usage guide placeholders.
pattobrien Jan 19, 2023
ac7307b
docs: Removed docusaurus nav bar icon.
pattobrien Jan 19, 2023
418ff7c
docs: Usage rewording.
pattobrien Jan 19, 2023
b3356f5
docs: Add gitignore for snippets.
pattobrien Jan 19, 2023
35fb54c
docs: Delete log files.
pattobrien Jan 19, 2023
1902d69
docs: Make unfinished tutorials private.
pattobrien Jan 19, 2023
694b151
docs: Hello world completed tutorial.
pattobrien Jan 19, 2023
929be37
docs: Bloc file structure guide cleanup.
pattobrien Jan 19, 2023
5e2266f
feat: generateSnippet shows particular snippets.
pattobrien Jan 21, 2023
d46c681
feat: TypeChecker core concepts.
pattobrien Jan 21, 2023
a34fa16
docs: TypeChecking finalized docs.
pattobrien Jan 22, 2023
ab74851
docs: Rule Creation table with available sidecar_lints.
pattobrien Jan 22, 2023
a6300d9
docs: Hello world tutorial fixes.
pattobrien Jan 22, 2023
d9a51f4
docs: Feature-first project structure tutorial.
pattobrien Jan 22, 2023
d83b047
Merge branch 'master' into docs/website
pattobrien Jan 22, 2023
5781be5
chore: Upgrade to Sidecar v0.1.0-dev.21.
pattobrien Jan 22, 2023
fccac33
docs: Testing documentation.
pattobrien Jan 23, 2023
4368174
docs: Integration Testing documentation.
pattobrien Jan 23, 2023
b928da7
docs: Warning message on intro page.
pattobrien Jan 23, 2023
45f6970
test: Test change to see if codecov is triggered.
pattobrien Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/data_rules/.dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
"languageVersion": "2.17"
}
],
"generated": "2023-01-13T14:36:21.478334Z",
"generated": "2023-01-14T21:01:26.976686Z",
"generator": "pub",
"generatorVersion": "2.17.6"
}
}
2 changes: 1 addition & 1 deletion packages/sidecar_lints/example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include: package:lints/recommended.yaml

analyzer:
plugins:
- sidecar
# - sidecar
16 changes: 8 additions & 8 deletions website/sidecar/.dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
"packageUri": "lib/",
"languageVersion": "2.17"
},
{
"name": "design_system_lints",
"rootUri": "file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/design_system_lints-0.1.0-dev.11",
"packageUri": "lib/",
"languageVersion": "2.17"
},
{
"name": "file",
"rootUri": "file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/file-6.1.4",
Expand Down Expand Up @@ -321,7 +327,7 @@
},
{
"name": "sidecar",
"rootUri": "../../../packages/sidecar",
"rootUri": "file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/sidecar-0.1.0-dev.21",
"packageUri": "lib/",
"languageVersion": "2.17"
},
Expand All @@ -331,12 +337,6 @@
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "sidecar_package_utilities",
"rootUri": "file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/sidecar_package_utilities-0.1.0-dev.7",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "source_gen",
"rootUri": "file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/source_gen-1.2.6",
Expand Down Expand Up @@ -476,7 +476,7 @@
"languageVersion": "2.17"
}
],
"generated": "2023-01-09T06:26:19.624577Z",
"generated": "2023-01-23T16:33:20.511367Z",
"generator": "pub",
"generatorVersion": "2.17.6"
}
6 changes: 3 additions & 3 deletions website/sidecar/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# For more info see: https://dart.dev/go/dot-packages-deprecation
#
# Generated by pub on 2023-01-09 01:26:19.616588.
# Generated by pub on 2023-01-23 11:33:20.502685.
_fe_analyzer_shared:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-47.0.0/lib/
analyzer:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/analyzer-4.7.0/lib/
analyzer_plugin:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/analyzer_plugin-0.11.1/lib/
Expand All @@ -27,6 +27,7 @@ convert:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/convert-3.1.
coverage:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/coverage-1.6.1/lib/
crypto:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/crypto-3.0.2/lib/
dart_style:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/dart_style-2.2.4/lib/
design_system_lints:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/design_system_lints-0.1.0-dev.11/lib/
file:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/file-6.1.4/lib/
fixnum:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/fixnum-1.0.1/lib/
freezed:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/freezed-2.2.0/lib/
Expand Down Expand Up @@ -57,9 +58,8 @@ shelf:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/shelf-1.4.0/li
shelf_packages_handler:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/shelf_packages_handler-3.0.1/lib/
shelf_static:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/shelf_static-1.1.1/lib/
shelf_web_socket:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-1.0.3/lib/
sidecar:../../packages/sidecar/lib/
sidecar:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/sidecar-0.1.0-dev.21/lib/
sidecar_annotations:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/sidecar_annotations-0.1.0-dev.1/lib/
sidecar_package_utilities:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/sidecar_package_utilities-0.1.0-dev.7/lib/
source_gen:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/source_gen-1.2.6/lib/
source_helper:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/source_helper-1.3.3/lib/
source_map_stack_trace:file:///Users/pattobrien/.pub-cache/hosted/pub.dartlang.org/source_map_stack_trace-2.1.1/lib/
Expand Down
49 changes: 49 additions & 0 deletions website/sidecar/.vscode/launch.json
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"
}
]
}
7 changes: 7 additions & 0 deletions website/sidecar/docs/concepts/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "Core Concepts",
"position": 3,
Copy link
Owner Author

Choose a reason for hiding this comment

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

Test comment

"link": {
pattobrien marked this conversation as resolved.
Show resolved Hide resolved
"type": "generated-index"
}
}
45 changes: 45 additions & 0 deletions website/sidecar/docs/concepts/integration_testing.mdx
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>

26 changes: 26 additions & 0 deletions website/sidecar/docs/concepts/rule_creation_checklist.mdx
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.
66 changes: 66 additions & 0 deletions website/sidecar/docs/concepts/snippets/testing.dart
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 */
44 changes: 44 additions & 0 deletions website/sidecar/docs/concepts/snippets/type_checking.dart
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 */
35 changes: 35 additions & 0 deletions website/sidecar/docs/concepts/type_checking.mdx
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.
8 changes: 0 additions & 8 deletions website/sidecar/docs/core-concepts/_category_.json

This file was deleted.

4 changes: 0 additions & 4 deletions website/sidecar/docs/core-concepts/how_it_works.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions website/sidecar/docs/core-concepts/main.dart

This file was deleted.

4 changes: 0 additions & 4 deletions website/sidecar/docs/core-concepts/publishing_rules.mdx

This file was deleted.

Loading