mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Deploying to gh-pages from @ 48b15b9bf8
🚀
This commit is contained in:
parent
42809c9681
commit
f760465482
106 changed files with 5612 additions and 4623 deletions
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="generator" content="Crystal Docs 0.36.1">
|
||||
<meta name="generator" content="Crystal Docs 1.1.1">
|
||||
<meta name="crystal_docs.project_version" content="master">
|
||||
<meta name="crystal_docs.project_name" content="ameba">
|
||||
|
||||
|
@ -286,6 +286,11 @@
|
|||
|
||||
<ul>
|
||||
|
||||
<li class=" " data-id="ameba/Ameba/Rule/Lint/AmbiguousAssignment" data-name="ameba::rule::lint::ambiguousassignment">
|
||||
<a href="../../../Ameba/Rule/Lint/AmbiguousAssignment.html">AmbiguousAssignment</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class=" " data-id="ameba/Ameba/Rule/Lint/BadDirective" data-name="ameba::rule::lint::baddirective">
|
||||
<a href="../../../Ameba/Rule/Lint/BadDirective.html">BadDirective</a>
|
||||
|
||||
|
@ -641,11 +646,8 @@
|
|||
|
||||
<p>A rule that disallows using shared variables in fibers,
|
||||
which are mutated during iterations.</p>
|
||||
|
||||
<p>In most cases it leads to unexpected behaviour and is undesired.</p>
|
||||
|
||||
<p>For example, having this example:</p>
|
||||
|
||||
<pre><code class="language-crystal">n <span class="o">=</span> <span class="n">0</span>
|
||||
channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
|
||||
|
||||
|
@ -655,12 +657,9 @@ channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">
|
|||
<span class="k">end</span>
|
||||
|
||||
<span class="n">3</span>.times { puts channel.receive } <span class="c"># => # 3, 3, 3</span></code></pre>
|
||||
|
||||
<p>The problem is there is only one shared between fibers variable <code>n</code>
|
||||
and when <code>channel.receive</code> is executed its value is <code>3</code>.</p>
|
||||
|
||||
<p>To solve this, the code above needs to be rewritten to the following:</p>
|
||||
|
||||
<pre><code class="language-crystal">n <span class="o">=</span> <span class="n">0</span>
|
||||
channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
|
||||
|
||||
|
@ -671,16 +670,12 @@ channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">
|
|||
<span class="k">end</span>
|
||||
|
||||
<span class="n">3</span>.times { puts channel.receive } <span class="c"># => # 1, 2, 3</span></code></pre>
|
||||
|
||||
<p>This rule is able to find the shared variables between fibers, which are mutated
|
||||
during iterations. So it reports the issue on the first sample and passes on
|
||||
the second one.</p>
|
||||
|
||||
<p>There are also other technics to solve the problem above which are
|
||||
<a href="https://crystal-lang.org/reference/guides/concurrency.html">officially documented</a></p>
|
||||
|
||||
<p>YAML configuration example:</p>
|
||||
|
||||
<pre><code class="language-crystal">Lint/SharedVarInFiber:
|
||||
Enabled: true</code></pre>
|
||||
|
||||
|
@ -723,7 +718,7 @@ the second one.</p>
|
|||
</h2>
|
||||
|
||||
|
||||
<a href="https://github.com/crystal-ameba/ameba/blob/9a91e42b/src/ameba/rule/lint/shared_var_in_fiber.cr#L52" target="_blank">
|
||||
<a href="https://github.com/crystal-ameba/ameba/blob/48b15b9b/src/ameba/rule/lint/shared_var_in_fiber.cr#L52" target="_blank">
|
||||
ameba/rule/lint/shared_var_in_fiber.cr
|
||||
</a>
|
||||
|
||||
|
@ -764,12 +759,12 @@ the second one.</p>
|
|||
<ul class="list-summary">
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#new(ctx:YAML::ParseContext,node:YAML::Nodes::Node)-class-method" class="signature"><strong>.new</strong>(ctx : YAML::ParseContext, node : YAML::Nodes::Node)</a>
|
||||
<a href="#new%28ctx%3AYAML%3A%3AParseContext%2Cnode%3AYAML%3A%3ANodes%3A%3ANode%29-class-method" class="signature"><strong>.new</strong>(ctx : YAML::ParseContext, node : YAML::Nodes::Node)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#new(config=nil)-class-method" class="signature"><strong>.new</strong>(config = <span class="n">nil</span>)</a>
|
||||
<a href="#new%28config%3Dnil%29-class-method" class="signature"><strong>.new</strong>(config = <span class="n">nil</span>)</a>
|
||||
|
||||
<div class="summary"><p>A rule that disallows using shared variables in fibers, which are mutated during iterations.</p></div>
|
||||
|
||||
|
@ -792,52 +787,52 @@ the second one.</p>
|
|||
<ul class="list-summary">
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#description:String-instance-method" class="signature"><strong>#description</strong> : String</a>
|
||||
<a href="#description%3AString-instance-method" class="signature"><strong>#description</strong> : String</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#description=(description:String)-instance-method" class="signature"><strong>#description=</strong>(description : String)</a>
|
||||
<a href="#description%3D%28description%3AString%29-instance-method" class="signature"><strong>#description=</strong>(description : String)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#enabled:Bool-instance-method" class="signature"><strong>#enabled</strong> : Bool</a>
|
||||
<a href="#enabled%3ABool-instance-method" class="signature"><strong>#enabled</strong> : Bool</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#enabled=(enabled)-instance-method" class="signature"><strong>#enabled=</strong>(enabled)</a>
|
||||
<a href="#enabled%3D%28enabled%29-instance-method" class="signature"><strong>#enabled=</strong>(enabled)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#excluded:Array(String)?-instance-method" class="signature"><strong>#excluded</strong> : Array(String)?</a>
|
||||
<a href="#excluded%3AArray%28String%29%3F-instance-method" class="signature"><strong>#excluded</strong> : Array(String)?</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#excluded=(excluded:Array(String)?)-instance-method" class="signature"><strong>#excluded=</strong>(excluded : Array(String)?)</a>
|
||||
<a href="#excluded%3D%28excluded%3AArray%28String%29%3F%29-instance-method" class="signature"><strong>#excluded=</strong>(excluded : Array(String)?)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#severity:Ameba::Severity-instance-method" class="signature"><strong>#severity</strong> : Ameba::Severity</a>
|
||||
<a href="#severity%3AAmeba%3A%3ASeverity-instance-method" class="signature"><strong>#severity</strong> : Ameba::Severity</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#severity=(severity)-instance-method" class="signature"><strong>#severity=</strong>(severity)</a>
|
||||
<a href="#severity%3D%28severity%29-instance-method" class="signature"><strong>#severity=</strong>(severity)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#test(source,node,scope:AST::Scope)-instance-method" class="signature"><strong>#test</strong>(source, node, scope : AST::Scope)</a>
|
||||
<a href="#test%28source%2Cnode%2Cscope%3AAST%3A%3AScope%29-instance-method" class="signature"><strong>#test</strong>(source, node, scope : AST::Scope)</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="entry-summary">
|
||||
<a href="#test(source)-instance-method" class="signature"><strong>#test</strong>(source)</a>
|
||||
<a href="#test%28source%29-instance-method" class="signature"><strong>#test</strong>(source)</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
@ -874,17 +869,17 @@ the second one.</p>
|
|||
<h3>Instance methods inherited from class <code><a href="../../../Ameba/Rule/Base.html">Ameba::Rule::Base</a></code></h3>
|
||||
|
||||
|
||||
<a href="../../../Ameba/Rule/Base.html#==(other)-instance-method" class="tooltip">
|
||||
<a href="../../../Ameba/Rule/Base.html#%3D%3D%28other%29-instance-method" class="tooltip">
|
||||
<span>==(other)</span>
|
||||
==</a>,
|
||||
|
||||
|
||||
<a href="../../../Ameba/Rule/Base.html#catch(source:Source)-instance-method" class="tooltip">
|
||||
<a href="../../../Ameba/Rule/Base.html#catch%28source%3ASource%29-instance-method" class="tooltip">
|
||||
<span>catch(source : Source)</span>
|
||||
catch</a>,
|
||||
|
||||
|
||||
<a href="../../../Ameba/Rule/Base.html#excluded?(source)-instance-method" class="tooltip">
|
||||
<a href="../../../Ameba/Rule/Base.html#excluded%3F%28source%29-instance-method" class="tooltip">
|
||||
<span>excluded?(source)</span>
|
||||
excluded?</a>,
|
||||
|
||||
|
@ -904,12 +899,12 @@ the second one.</p>
|
|||
name</a>,
|
||||
|
||||
|
||||
<a href="../../../Ameba/Rule/Base.html#special?-instance-method" class="tooltip">
|
||||
<a href="../../../Ameba/Rule/Base.html#special%3F-instance-method" class="tooltip">
|
||||
<span>special?</span>
|
||||
special?</a>,
|
||||
|
||||
|
||||
<a href="../../../Ameba/Rule/Base.html#test(source:Source,node:Crystal::ASTNode,*opts)-instance-method" class="tooltip">
|
||||
<a href="../../../Ameba/Rule/Base.html#test%28source%3ASource%2Cnode%3ACrystal%3A%3AASTNode%2C%2Aopts%29-instance-method" class="tooltip">
|
||||
<span>test(source : Source, node : Crystal::ASTNode, *opts)<br/>test(source : Source)</span>
|
||||
test</a>
|
||||
|
||||
|
@ -979,7 +974,7 @@ the second one.</p>
|
|||
|
||||
def self.<strong>new</strong>(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
|
||||
|
||||
<a class="method-permalink" href="#new(ctx:YAML::ParseContext,node:YAML::Nodes::Node)-class-method">#</a>
|
||||
<a class="method-permalink" href="#new%28ctx%3AYAML%3A%3AParseContext%2Cnode%3AYAML%3A%3ANodes%3A%3ANode%29-class-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -993,18 +988,15 @@ the second one.</p>
|
|||
|
||||
def self.<strong>new</strong>(config = <span class="n">nil</span>)
|
||||
|
||||
<a class="method-permalink" href="#new(config=nil)-class-method">#</a>
|
||||
<a class="method-permalink" href="#new%28config%3Dnil%29-class-method">#</a>
|
||||
</div>
|
||||
|
||||
<div class="doc">
|
||||
|
||||
<p>A rule that disallows using shared variables in fibers,
|
||||
which are mutated during iterations.</p>
|
||||
|
||||
<p>In most cases it leads to unexpected behaviour and is undesired.</p>
|
||||
|
||||
<p>For example, having this example:</p>
|
||||
|
||||
<pre><code class="language-crystal">n <span class="o">=</span> <span class="n">0</span>
|
||||
channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
|
||||
|
||||
|
@ -1014,12 +1006,9 @@ channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">
|
|||
<span class="k">end</span>
|
||||
|
||||
<span class="n">3</span>.times { puts channel.receive } <span class="c"># => # 3, 3, 3</span></code></pre>
|
||||
|
||||
<p>The problem is there is only one shared between fibers variable <code>n</code>
|
||||
and when <code>channel.receive</code> is executed its value is <code>3</code>.</p>
|
||||
|
||||
<p>To solve this, the code above needs to be rewritten to the following:</p>
|
||||
|
||||
<pre><code class="language-crystal">n <span class="o">=</span> <span class="n">0</span>
|
||||
channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">Int32</span>).<span class="k">new</span>
|
||||
|
||||
|
@ -1030,16 +1019,12 @@ channel <span class="o">=</span> <span class="t">Channel</span>(<span class="t">
|
|||
<span class="k">end</span>
|
||||
|
||||
<span class="n">3</span>.times { puts channel.receive } <span class="c"># => # 1, 2, 3</span></code></pre>
|
||||
|
||||
<p>This rule is able to find the shared variables between fibers, which are mutated
|
||||
during iterations. So it reports the issue on the first sample and passes on
|
||||
the second one.</p>
|
||||
|
||||
<p>There are also other technics to solve the problem above which are
|
||||
<a href="https://crystal-lang.org/reference/guides/concurrency.html">officially documented</a></p>
|
||||
|
||||
<p>YAML configuration example:</p>
|
||||
|
||||
<pre><code class="language-crystal">Lint/SharedVarInFiber:
|
||||
Enabled: true</code></pre>
|
||||
</div>
|
||||
|
@ -1047,7 +1032,7 @@ the second one.</p>
|
|||
<br/>
|
||||
<div>
|
||||
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/9a91e42b/src/ameba/rule/lint/shared_var_in_fiber.cr#L52" target="_blank">View source</a>]
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/48b15b9b/src/ameba/rule/lint/shared_var_in_fiber.cr#L52" target="_blank">View source</a>]
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1071,7 +1056,7 @@ the second one.</p>
|
|||
|
||||
def <strong>description</strong> : String
|
||||
|
||||
<a class="method-permalink" href="#description:String-instance-method">#</a>
|
||||
<a class="method-permalink" href="#description%3AString-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1085,7 +1070,7 @@ the second one.</p>
|
|||
|
||||
def <strong>description=</strong>(description : String)
|
||||
|
||||
<a class="method-permalink" href="#description=(description:String)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#description%3D%28description%3AString%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1099,7 +1084,7 @@ the second one.</p>
|
|||
|
||||
def <strong>enabled</strong> : Bool
|
||||
|
||||
<a class="method-permalink" href="#enabled:Bool-instance-method">#</a>
|
||||
<a class="method-permalink" href="#enabled%3ABool-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1113,7 +1098,7 @@ the second one.</p>
|
|||
|
||||
def <strong>enabled=</strong>(enabled)
|
||||
|
||||
<a class="method-permalink" href="#enabled=(enabled)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#enabled%3D%28enabled%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1127,7 +1112,7 @@ the second one.</p>
|
|||
|
||||
def <strong>excluded</strong> : Array(String)?
|
||||
|
||||
<a class="method-permalink" href="#excluded:Array(String)?-instance-method">#</a>
|
||||
<a class="method-permalink" href="#excluded%3AArray%28String%29%3F-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1141,7 +1126,7 @@ the second one.</p>
|
|||
|
||||
def <strong>excluded=</strong>(excluded : Array(String)?)
|
||||
|
||||
<a class="method-permalink" href="#excluded=(excluded:Array(String)?)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#excluded%3D%28excluded%3AArray%28String%29%3F%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1155,7 +1140,7 @@ the second one.</p>
|
|||
|
||||
def <strong>severity</strong> : <a href="../../../Ameba/Severity.html">Ameba::Severity</a>
|
||||
|
||||
<a class="method-permalink" href="#severity:Ameba::Severity-instance-method">#</a>
|
||||
<a class="method-permalink" href="#severity%3AAmeba%3A%3ASeverity-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1169,7 +1154,7 @@ the second one.</p>
|
|||
|
||||
def <strong>severity=</strong>(severity)
|
||||
|
||||
<a class="method-permalink" href="#severity=(severity)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#severity%3D%28severity%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
@ -1183,13 +1168,13 @@ the second one.</p>
|
|||
|
||||
def <strong>test</strong>(source, node, scope : <a href="../../../Ameba/AST/Scope.html">AST::Scope</a>)
|
||||
|
||||
<a class="method-permalink" href="#test(source,node,scope:AST::Scope)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#test%28source%2Cnode%2Cscope%3AAST%3A%3AScope%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<div>
|
||||
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/9a91e42b/src/ameba/rule/lint/shared_var_in_fiber.cr#L63" target="_blank">View source</a>]
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/48b15b9b/src/ameba/rule/lint/shared_var_in_fiber.cr#L63" target="_blank">View source</a>]
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1199,13 +1184,13 @@ the second one.</p>
|
|||
|
||||
def <strong>test</strong>(source)
|
||||
|
||||
<a class="method-permalink" href="#test(source)-instance-method">#</a>
|
||||
<a class="method-permalink" href="#test%28source%29-instance-method">#</a>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<div>
|
||||
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/9a91e42b/src/ameba/rule/lint/shared_var_in_fiber.cr#L59" target="_blank">View source</a>]
|
||||
[<a href="https://github.com/crystal-ameba/ameba/blob/48b15b9b/src/ameba/rule/lint/shared_var_in_fiber.cr#L59" target="_blank">View source</a>]
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue