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

Fix FP S6582 (prefer-optional-chain): Update description and severity #4562

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ <h2>Why is this an issue?</h2>
<p>This rule flags logical operations that can be safely replaced with the <code>?.</code> optional chaining operator.</p>
<h2>How to fix it</h2>
<p>Replace with <code>?.</code> optional chaining the logical expression that checks for <code>null</code>/<code>undefined</code> before accessing the
property of an object.</p>
property of an object, the element of an array, or calling a function.</p>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
function foo(param) {
if (param &amp;&amp; param.value) {
bar(param.value);
}
function foo(obj, arr, fn) {
if (obj &amp;&amp; obj.value) {}
if (arr &amp;&amp; arr[0]) {}
if (fn &amp;&amp; fn(42)) {}
}
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
function foo(param) {
if (param?.value) {
bar(param.value);
}
function foo(obj, arr, fn) {
if (obj?.value) {}
if (arr?.[0]) {}
if (fn?.(42)) {}
}
</pre>
<h2>Resources</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"constantCost": "5min"
},
"tags": [],
"defaultSeverity": "Major",
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-6582",
"sqKey": "S6582",
"scope": "All",
Expand Down
Loading