Skip to content

Commit 6462f18

Browse files
Split up formatting / best practices sections
1 parent 4558466 commit 6462f18

File tree

1 file changed

+89
-76
lines changed

1 file changed

+89
-76
lines changed

README.md

Lines changed: 89 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* [UiComponent](#uicomponent)
1818
* __[Fluent-style component consumption](#fluent-style-component-consumption)__
1919
* __[DOM components and props](#dom-components-and-props)__
20+
* __[Component Formatting](#component-formatting)__
2021
* __[Building custom components](#building-custom-components)__
2122
* __[Component Boilerplates](#component-boilerplate-templates)__
22-
* __[Component Formatting](#component-formatting)__
23+
* __[Component Best Practices](#component-best-practices)__
2324
* __[Common Pitfalls](#common-pitfalls)__
2425
* __[Contributing](#contributing)__
2526

@@ -491,6 +492,90 @@ as shown in the examples above.
491492

492493

493494

495+
## Component Formatting
496+
497+
> NOTE: At this time, we __do not recommend using [`dartfmt`](https://github.com/dart-lang/dart_style)__, as it
498+
> _greatly_ decreases the readability of components built using
499+
> [OverReact's fluent-style](#fluent-style-component-consumption).
500+
>
501+
> _We have a long-term goal of writing our own formatter that extends from `dartfmt` to make it possible for our
502+
> fluent-style to remain readable even after the formatter executes._
503+
504+
Since using `dartfmt` results in unreadable code, we have documented the following formatting best-practices that
505+
we _strongly recommended_ when building components using the `over_react` library.
506+
507+
 
508+
509+
* __ALWAYS__ place the closing builder parent on a new line.
510+
511+
_Good:_
512+
```dart
513+
(Button()
514+
..skin = ButtonSkin.SUCCESS
515+
..isDisabled = true
516+
)('Submit')
517+
```
518+
519+
_Bad:_
520+
```dart
521+
(Button()
522+
..skin = ButtonSkin.SUCCESS
523+
..isDisabled = true)('Submit')
524+
```
525+
526+
 
527+
528+
* __ALWAYS__ pass nested components as variadic children when keys are not specified, on a new line with a __2 space__
529+
indentation.
530+
531+
_Good:_
532+
```dart
533+
Dom.div()(
534+
Dom.span()('nested component'),
535+
Dom.span()('nested component')
536+
)
537+
```
538+
539+
_Bad:_
540+
```dart
541+
// Nested component is not on a new line
542+
Dom.div()(Dom.span()('nested component'))
543+
544+
// Nested component has a continuation indent
545+
Dom.div()(
546+
Dom.span()('nested component'),
547+
)
548+
549+
// Nested components are within a list instead of
550+
// being passed in as variadic children.
551+
Dom.div()([
552+
Dom.span()('nested component'),
553+
Dom.span()('nested component')
554+
])
555+
```
556+
557+
 
558+
559+
* __AVOID__ specifying more than one cascading prop setter on the same line.
560+
561+
_Good:_
562+
```dart
563+
(Dom.div()
564+
..id = 'my_div'
565+
..className = 'my-class'
566+
)()
567+
```
568+
569+
_Bad:_
570+
```dart
571+
(Dom.div()..id = 'my_div'..className = 'my-class')()
572+
```
573+
574+
 
575+
 
576+
577+
578+
494579
## Building custom components
495580

496581
Now that we’ve gone over how to [use the `over_react` package in your project](#using-it-in-your-project),
@@ -603,81 +688,8 @@ that you get for free from OverReact, you're ready to start building your own cu
603688

604689
 
605690

606-
### Component Formatting
607-
608-
> NOTE: At this time, we __do not recommend using [`dartfmt`](https://github.com/dart-lang/dart_style)__, as it _greatly_ decreases the readability of components built using [OverReact's fluent-style](#fluent-style-component-consumption).
609-
>
610-
> _We have a long-term goal of writing our own formatter that extends from `dartfmt` to make it possible for our fluent-style to remain readable even after the formatter executes._
611-
612-
Since using `dartfmt` results in unreadable code, we have documented the following formatting best-practices that we _strongly recommended_ when building components using the `over_react` library.
613-
614-
 
615-
616-
* __ALWAYS__ place the closing builder parent on a new line.
617-
618-
_Good:_
619-
```dart
620-
(Button()
621-
..skin = ButtonSkin.SUCCESS
622-
..isDisabled = true
623-
)('Submit')
624-
```
625-
626-
_Bad:_
627-
```dart
628-
(Button()
629-
..skin = ButtonSkin.SUCCESS
630-
..isDisabled = true)('Submit')
631-
```
632-
633-
 
634-
635-
* __ALWAYS__ pass nested components as variadic children when keys are not specified, on a new line with a __2 space__ indentation.
691+
### Component Best Practices
636692

637-
_Good:_
638-
```dart
639-
Dom.div()(
640-
Dom.span()('nested component'),
641-
Dom.span()('nested component')
642-
)
643-
```
644-
645-
_Bad:_
646-
```dart
647-
// Nested component is not on a new line
648-
Dom.div()(Dom.span()('nested component'))
649-
650-
// Nested component has a continuation indent
651-
Dom.div()(
652-
Dom.span()('nested component'),
653-
)
654-
655-
// Nested components are within a list instead of
656-
// being passed in as variadic children.
657-
Dom.div()([
658-
Dom.span()('nested component'),
659-
Dom.span()('nested component')
660-
])
661-
```
662-
663-
 
664-
665-
* __AVOID__ specifying more than one cascading prop setter on the same line.
666-
667-
_Good:_
668-
```dart
669-
(Dom.div()
670-
..id = 'my_div'
671-
..className = 'my-class'
672-
)()
673-
```
674-
675-
_Bad:_
676-
```dart
677-
(Dom.div()..id = 'my_div'..className = 'my-class')()
678-
```
679-
680-
 
681693

682694
* __ALWAYS__ write informative comments for your component factories.
683695
Include what the component relates to, relies on, or if it extends
@@ -876,7 +888,8 @@ Yes please! ([__Please read our contributor guidelines first__][contributing-doc
876888
The `over_react` library adheres to [Semantic Versioning](http://semver.org/):
877889
878890
* Any API changes that are not backwards compatible will __bump the major version__ _(and reset the minor / patch)_.
879-
* Any new functionality that is added in a backwards-compatible manner will __bump the minor version__ _(and reset the patch)_.
891+
* Any new functionality that is added in a backwards-compatible manner will __bump the minor version__
892+
_(and reset the patch)_.
880893
* Any backwards-compatible bug fixes that are added will __bump the patch version__.
881894
882895

0 commit comments

Comments
 (0)