Skip to content

Commit

Permalink
Update generated analyzer plugin docs
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Sep 23, 2024
1 parent 140591c commit 6993ba0
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 74 deletions.
14 changes: 10 additions & 4 deletions analyzer_plugin/lints/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ <h2 id="warning-rules">Warnings</h2>
<!--suppress HtmlUnknownTarget --><strong><a href="over_react_invalid_dom_attribute.html">over_react_invalid_dom_attribute</a></strong><br/> <p>Avoid setting props that map to invalid HTML element attributes.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_late_required_prop.html">over_react_late_required_prop</a></strong><br/> <p>Always provide required props.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_low_quality_key.html">over_react_low_quality_key</a></strong><br/> <p>Avoid deriving React keys from objects that have a high chance of colliding.</p>


Expand All @@ -122,10 +125,16 @@ <h2 id="warning-rules">Warnings</h2>

<!--suppress HtmlUnknownTarget --><strong><a href="over_react_unknown_key_type.html">over_react_unknown_key_type</a></strong><br/> <p>Avoid deriving React keys from an object typed as dynamic/Object.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_unsafe_required_prop_access.html">over_react_unsafe_required_prop_access (experimental)</a></strong><br/> <p>Do not unsafely access required props when they're not guaranteed to be present.</p>


<h2 id="hint-rules">Hints</h2>

<!--suppress HtmlUnknownTarget --><strong><a href="over_react_boilerplate_debug.html">over_react_boilerplate_debug (experimental)</a></strong><br/> <p>Internal tool for debugging boilerplate parsing / building.</p>
<!--suppress HtmlUnknownTarget --><strong><a href="over_react_annotation_required_prop.html">over_react_annotation_required_prop</a></strong><br/> <p>Always provide required props.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_boilerplate_debug.html">over_react_boilerplate_debug (experimental)</a></strong><br/> <p>Internal tool for debugging boilerplate parsing / building.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_bool_prop_name_readability.html">over_react_bool_prop_name_readability</a></strong><br/> <p>Name boolean props in a way that makes them easy to read and infer their purpose.</p>
Expand All @@ -143,9 +152,6 @@ <h2 id="hint-rules">Hints</h2>
<!--suppress HtmlUnknownTarget --><strong><a href="over_react_prefer_use_or_create_ref.html">over_react_prefer_use_or_create_ref</a></strong><br/> <p>Avoid using callback refs to assign ref field values.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_required_prop.html">over_react_required_prop (experimental)</a></strong><br/> <p>Avoid omitting props that are required.</p>


<!--suppress HtmlUnknownTarget --><strong><a href="over_react_string_ref.html">over_react_string_ref</a></strong><br/> <p>Avoid using deprecated string refs.</p>


Expand Down
4 changes: 3 additions & 1 deletion analyzer_plugin/lints/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h1 id="analysis-options">Analysis Options</h1>

<pre><code>linter:
rules:
- over_react_annotation_required_prop
- over_react_avoid_link_target_vulnerability
- over_react_boilerplate_debug
- over_react_boilerplate_error
Expand All @@ -54,6 +55,7 @@ <h1 id="analysis-options">Analysis Options</h1>
- over_react_invalid_child
- over_react_invalid_dom_attribute
- over_react_invalid_render_return_type
- over_react_late_required_prop
- over_react_low_quality_key
- over_react_missing_cascade_parens
- over_react_missing_key
Expand All @@ -63,12 +65,12 @@ <h1 id="analysis-options">Analysis Options</h1>
- over_react_prefer_use_or_create_ref
- over_react_proptypes_do_not_throw
- over_react_pseudo_static_lifecycle
- over_react_required_prop
- over_react_rules_of_hooks
- over_react_string_ref
- over_react_style_missing_unit
- over_react_unknown_key_type
- over_react_unnecessary_key
- over_react_unsafe_required_prop_access
- over_react_variadic_children
</code></pre>

Expand Down
107 changes: 107 additions & 0 deletions analyzer_plugin/lints/over_react_annotation_required_prop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>over_react_annotation_required_prop</title>
<link rel="stylesheet" href="../stylesheets/styles.css">
<link rel="stylesheet" href="../stylesheets/pygment_trac.css">
<script src="../javascripts/scale.fix.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

</head>
<body>
<div class="wrapper">
<header>
<h1>over_react_annotation_required_prop</h1>
<p>Severity: AnalysisErrorSeverity.INFO</p>

<p>Maturity: stable</p>
<p style="padding-bottom: 10px;">Since 1.0.0</p>
<!--getBadges(name)-->
<p class="view"><a href="https://github.com/Workiva/over_react/blob/master/tools/analyzer_plugin/">View the Project on GitHub <small>workiva/over_react</small></a></p>
</header>
<section>

<p><strong>ALWAYS</strong> provide a value for <code>late</code> required props, either directly or by forwarding props.</p>
<p>Please see the documentation for <a href="https://github.com/Workiva/over_react/blob/master/doc/null_safety_and_required_props.md">null safety and required props</a>
for more information on required prop validation, which, in addition to this lint, also includes runtime <code>assert</code>s.</p>
<p>Those docs also note exceptions to this rule under the <a href="https://github.com/Workiva/over_react/blob/master/doc/null_safety_and_required_props.md#disabling-required-prop-validation-for-certain-props">Disabling required prop validation for certain props</a>
section, and include instructions for handling those. One common case where this doesn't apply are "wrapper" components that render another component and set some of its props within its render.</p>
<h3>Examples:</h3>
<p>Given the following component with the required prop <code>user</code>:</p>
<pre><code class="language-dart">mixin UserChipProps on UiProps {
late User user;
bool? isSelected;
}

UiFactory&lt;UserChipProps&gt; UserChip = uiFunction((props) {
// ...
}, _$UserChipConfig);
</code></pre>
<p>Then whenever UserChip is render, that required prop must always be set by the consumer.</p>
<p><strong>GOOD:</strong></p>
<pre><code class="language-dart"> (UserChip()..user = user)()
</code></pre>
<p><strong>BAD:</strong></p>
<pre><code class="language-dart"> UserChip()()
// ^^^^^^^^^^
// warning: Missing required late prop 'user' from 'UserChipProps'.
// (over_react_late_required_prop)
</code></pre>
<p>and, that code will also throw a runtime error when asserts are enabled:</p>
<pre><code>Uncaught Error: RequiredPropsError: Required prop `user` is missing.
at Object.throw_ [as throw]
at _$$UserChipProps$JsMap.new.validateRequiredProps
</code></pre>
<h4>Prop forwarding</h4>
<p><strong>GOOD:</strong></p>
<pre><code class="language-dart">mixin CustomUserChipPropsMixin on UiProps {
String? color;
}

class CustomUserChipProps = UiProps with UserChipProps, CustomUserChipPropsMixin;

UiFactory&lt;CustomUserChipProps&gt; CustomUserChip = uiFunction((props) {
final color = props.color;

return (UserChip()
// Required props are correctly forwarded here by the wrapper component
..addProps(props.getPropsToForward(exclude: {CustomUserChipPropsMixin})
..style = {
if (color != null) 'border': '2px solid $color',
...?props.style,
}
)();
}, _$CustomUserChipConfig);
</code></pre>
<p><strong>BAD:</strong></p>
<pre><code class="language-dart">UiFactory&lt;CustomUserChipProps&gt; CustomUserChip = uiFunction((props) {
final color = props.color;

// Required props are not forwarded, so we get:
// warning: Missing required late prop 'user' from 'UserChipProps'.
// (over_react_late_required_prop)
return (UserChip()
..style = {
if (color != null) 'border': '2px solid $color',
...?props.style,
}
)();
}, _$CustomUserChipConfig);
</code></pre>


</section>
</div>
<footer>
<p>Project maintained by <a href="https://workiva.github.io/" target="_blank" rel="noopener noreferrer">Workiva</a></p>
<p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist" target="_blank" rel="noopener noreferrer">orderedlist</a></p>
</footer>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->

</body>
</html>
107 changes: 107 additions & 0 deletions analyzer_plugin/lints/over_react_late_required_prop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>over_react_late_required_prop</title>
<link rel="stylesheet" href="../stylesheets/styles.css">
<link rel="stylesheet" href="../stylesheets/pygment_trac.css">
<script src="../javascripts/scale.fix.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

</head>
<body>
<div class="wrapper">
<header>
<h1>over_react_late_required_prop</h1>
<p>Severity: AnalysisErrorSeverity.WARNING</p>

<p>Maturity: stable</p>
<p style="padding-bottom: 10px;">Since 1.0.0</p>
<!--getBadges(name)-->
<p class="view"><a href="https://github.com/Workiva/over_react/blob/master/tools/analyzer_plugin/">View the Project on GitHub <small>workiva/over_react</small></a></p>
</header>
<section>

<p><strong>ALWAYS</strong> provide a value for <code>late</code> required props, either directly or by forwarding props.</p>
<p>Please see the documentation for <a href="https://github.com/Workiva/over_react/blob/master/doc/null_safety_and_required_props.md">null safety and required props</a>
for more information on required prop validation, which, in addition to this lint, also includes runtime <code>assert</code>s.</p>
<p>Those docs also note exceptions to this rule under the <a href="https://github.com/Workiva/over_react/blob/master/doc/null_safety_and_required_props.md#disabling-required-prop-validation-for-certain-props">Disabling required prop validation for certain props</a>
section, and include instructions for handling those. One common case where this doesn't apply are "wrapper" components that render another component and set some of its props within its render.</p>
<h3>Examples:</h3>
<p>Given the following component with the required prop <code>user</code>:</p>
<pre><code class="language-dart">mixin UserChipProps on UiProps {
late User user;
bool? isSelected;
}

UiFactory&lt;UserChipProps&gt; UserChip = uiFunction((props) {
// ...
}, _$UserChipConfig);
</code></pre>
<p>Then whenever UserChip is render, that required prop must always be set by the consumer.</p>
<p><strong>GOOD:</strong></p>
<pre><code class="language-dart"> (UserChip()..user = user)()
</code></pre>
<p><strong>BAD:</strong></p>
<pre><code class="language-dart"> UserChip()()
// ^^^^^^^^^^
// warning: Missing required late prop 'user' from 'UserChipProps'.
// (over_react_late_required_prop)
</code></pre>
<p>and, that code will also throw a runtime error when asserts are enabled:</p>
<pre><code>Uncaught Error: RequiredPropsError: Required prop `user` is missing.
at Object.throw_ [as throw]
at _$$UserChipProps$JsMap.new.validateRequiredProps
</code></pre>
<h4>Prop forwarding</h4>
<p><strong>GOOD:</strong></p>
<pre><code class="language-dart">mixin CustomUserChipPropsMixin on UiProps {
String? color;
}

class CustomUserChipProps = UiProps with UserChipProps, CustomUserChipPropsMixin;

UiFactory&lt;CustomUserChipProps&gt; CustomUserChip = uiFunction((props) {
final color = props.color;

return (UserChip()
// Required props are correctly forwarded here by the wrapper component
..addProps(props.getPropsToForward(exclude: {CustomUserChipPropsMixin})
..style = {
if (color != null) 'border': '2px solid $color',
...?props.style,
}
)();
}, _$CustomUserChipConfig);
</code></pre>
<p><strong>BAD:</strong></p>
<pre><code class="language-dart">UiFactory&lt;CustomUserChipProps&gt; CustomUserChip = uiFunction((props) {
final color = props.color;

// Required props are not forwarded, so we get:
// warning: Missing required late prop 'user' from 'UserChipProps'.
// (over_react_late_required_prop)
return (UserChip()
..style = {
if (color != null) 'border': '2px solid $color',
...?props.style,
}
)();
}, _$CustomUserChipConfig);
</code></pre>


</section>
</div>
<footer>
<p>Project maintained by <a href="https://workiva.github.io/" target="_blank" rel="noopener noreferrer">Workiva</a></p>
<p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist" target="_blank" rel="noopener noreferrer">orderedlist</a></p>
</footer>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->

</body>
</html>
69 changes: 0 additions & 69 deletions analyzer_plugin/lints/over_react_required_prop.html

This file was deleted.

Loading

0 comments on commit 6993ba0

Please sign in to comment.