SwiftLint/trailing_comma.html

437 lines
24 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<title>trailing_comma Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset="utf-8">
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="trailing_comma Reference"></a>
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
SwiftLintCore 0.52.2 Docs
</a>
(100% documented)
</p>
<div class="header-col--secondary">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</div>
<p class="header-col header-col--secondary">
<a class="header-link" href="https://github.com/realm/SwiftLint">
<img class="header-icon" src="img/gh.png" alt="GitHub"/>
View on GitHub
</a>
</p>
<p class="header-col header-col--secondary">
<a class="header-link" href="dash-feed://https%3A%2F%2Frealm.github.io%2FSwiftLint%2Fdocsets%2FSwiftLintCore.xml">
<img class="header-icon" src="img/dash.png" alt="Dash"/>
Install in Dash
</a>
</p>
</header>
<p class="breadcrumbs">
<a class="breadcrumb" href="index.html">SwiftLintCore Reference</a>
<img class="carat" src="img/carat.png" alt=""/>
trailing_comma Reference
</p>
<div class="content-wrapper">
<nav class="navigation">
<ul class="nav-groups">
<li class="nav-group-name">
<a class="nav-group-name-link" href="Rules.html">Rules</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="rule-directory.html">Rule Directory</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Reporters.html">Reporters</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/CSVReporter.html">CSVReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/CheckstyleReporter.html">CheckstyleReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/CodeClimateReporter.html">CodeClimateReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/EmojiReporter.html">EmojiReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/GitHubActionsLoggingReporter.html">GitHubActionsLoggingReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/HTMLReporter.html">HTMLReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JSONReporter.html">JSONReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/JUnitReporter.html">JUnitReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/MarkdownReporter.html">MarkdownReporter</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/CustomRuleTimer.html">CustomRuleTimer</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/DeclaredIdentifiersTrackingVisitor.html">DeclaredIdentifiersTrackingVisitor</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/LinterCache.html">LinterCache</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/RuleRegistry.html">RuleRegistry</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/RuleStorage.html">RuleStorage</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/SwiftLintFile.html">SwiftLintFile</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/ViolationsSyntaxVisitor.html">ViolationsSyntaxVisitor</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Global%20Variables.html">Global Variables</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Global%20Variables.html#/s:13SwiftLintCore9coreRulesSayAA4Rule_pXpGvp">coreRules</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Global%20Variables.html#/s:13SwiftLintCore13reportersListSayAA8Reporter_pXpGvp">reportersList</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/AccessControlLevel.html">AccessControlLevel</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/ExecutableInfo.html">ExecutableInfo</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/Issue.html">Issue</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/RuleIdentifier.html">RuleIdentifier</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/RuleKind.html">RuleKind</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/RuleListError.html">RuleListError</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/SwiftExpressionKind.html">SwiftExpressionKind</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Enums/ViolationSeverity.html">ViolationSeverity</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/Array.html">Array</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Functions.html">Functions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Functions.html#/s:13SwiftLintCore12reporterFrom10identifierAA8Reporter_pXpSS_tF">reporterFrom(identifier:)</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ASTRule.html">ASTRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/AnalyzerRule.html">AnalyzerRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols.html#/s:13SwiftLintCore17AnyCollectingRuleP">AnyCollectingRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/CacheDescriptionProvider.html">CacheDescriptionProvider</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/CollectingRule.html">CollectingRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ConfigurationProviderRule.html">ConfigurationProviderRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/CorrectableRule.html">CorrectableRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols.html#/s:13SwiftLintCore9OptInRuleP">OptInRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/Reporter.html">Reporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/Rule.html">Rule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/RuleConfiguration.html">RuleConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/SeverityBasedRuleConfiguration.html">SeverityBasedRuleConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols.html#/s:13SwiftLintCore17SourceKitFreeRuleP">SourceKitFreeRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/SubstitutionCorrectableASTRule.html">SubstitutionCorrectableASTRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/SubstitutionCorrectableRule.html">SubstitutionCorrectableRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/SwiftSyntaxCorrectableRule.html">SwiftSyntaxCorrectableRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/SwiftSyntaxRule.html">SwiftSyntaxRule</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ViolationsSyntaxRewriter.html">ViolationsSyntaxRewriter</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/ChildOptionSeverityConfiguration.html">ChildOptionSeverityConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/CollectedLinter.html">CollectedLinter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Command.html">Command</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Command/Action.html"> Action</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Command/Modifier.html"> Modifier</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Configuration.html">Configuration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Correction.html">Correction</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Example.html">Example</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/GitLabJUnitReporter.html">GitLabJUnitReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Linter.html">Linter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Location.html">Location</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/ReasonedRuleViolation.html">ReasonedRuleViolation</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RegexConfiguration.html">RegexConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Region.html">Region</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RelativePathReporter.html">RelativePathReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RuleDescription.html">RuleDescription</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RuleList.html">RuleList</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RuleListDocumentation.html">RuleListDocumentation</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/RuleParameter.html">RuleParameter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SeverityConfiguration.html">SeverityConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SeverityLevelsConfiguration.html">SeverityLevelsConfiguration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SonarQubeReporter.html">SonarQubeReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Stack.html">Stack</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/StyleViolation.html">StyleViolation</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SummaryReporter.html">SummaryReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SwiftLintSyntaxMap.html">SwiftLintSyntaxMap</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SwiftLintSyntaxToken.html">SwiftLintSyntaxToken</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/SwiftVersion.html">SwiftVersion</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Version.html">Version</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/XcodeReporter.html">XcodeReporter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/YamlParser.html">YamlParser</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section class="section">
<div class="section-content top-matter">
<h1 id='trailing-comma' class='heading'>Trailing Comma</h1>
<p>Trailing commas in arrays and dictionaries should be avoided/enforced.</p>
<ul>
<li><strong>Identifier:</strong> trailing_comma</li>
<li><strong>Enabled by default:</strong> Yes</li>
<li><strong>Supports autocorrection:</strong> Yes</li>
<li><strong>Kind:</strong> style</li>
<li><strong>Analyzer rule:</strong> No</li>
<li><strong>Minimum Swift compiler version:</strong> 5.0.0</li>
<li><strong>Default configuration:</strong> severity: warning, mandatory_comma: false</li>
</ul>
<h2 id='non-triggering-examples' class='heading'>Non Triggering Examples</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[:]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="mi">3</span><span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="kt">Void</span><span class="p">]()</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">example</span> <span class="o">=</span> <span class="p">[</span> <span class="mi">1</span><span class="p">,</span>
<span class="mi">2</span>
<span class="c1">// 3,</span>
<span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="nf">foo</span><span class="p">([</span><span class="mi">1</span><span class="p">:</span> <span class="s">"</span><span class="se">\(</span><span class="n">error</span><span class="se">)</span><span class="s">"</span><span class="p">])</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="kt">Int</span><span class="p">]()</span>
</code></pre>
<h2 id='triggering-examples' class='heading'>Triggering Examples</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="err"></span><span class="p">,]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="err"></span><span class="p">,</span> <span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span> <span class="err"></span><span class="p">,]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="mi">3</span><span class="err"></span><span class="p">,</span> <span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">Bar</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">:</span> <span class="mi">3</span><span class="err"></span><span class="p">,</span> <span class="p">]</span>
<span class="p">}</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="err"></span><span class="p">,]</span> <span class="o">+</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="err"></span><span class="p">,]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">example</span> <span class="o">=</span> <span class="p">[</span> <span class="mi">1</span><span class="p">,</span>
<span class="mi">2</span><span class="err"></span><span class="p">,</span>
<span class="c1">// 3,</span>
<span class="p">]</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="s">"אבג"</span><span class="p">,</span> <span class="s">"αβγ"</span><span class="p">,</span> <span class="s">"🇺🇸"</span><span class="err"></span><span class="p">,]</span>
</code></pre>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">C</span> <span class="p">{</span>
<span class="cp">#if true</span>
<span class="kd">func</span> <span class="nf">f</span><span class="p">()</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="err"></span><span class="p">,]</span>
<span class="p">}</span>
<span class="cp">#endif</span>
<span class="p">}</span>
</code></pre>
<pre class="highlight swift"><code><span class="nf">foo</span><span class="p">([</span><span class="mi">1</span><span class="p">:</span> <span class="s">"</span><span class="se">\(</span><span class="n">error</span><span class="se">)</span><span class="s">"</span><span class="err"></span><span class="p">,])</span>
</code></pre>
</div>
</section>
</article>
</div>
<section class="footer">
<p>© 2023 <a class="link" href="https://jpsim.com" target="_blank" rel="external noopener">JP Simard</a> under MIT.</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
</html>