rrd108 / vue-mess-detector

A static code analysis tool for detecting code smells and best practice violations in Vue.js and Nuxt.js projects
MIT License
177 stars 6 forks source link

Nullish coalescing operator (??) will trigger "nestedTernary" #360

Closed zymbth closed 1 hour ago

zymbth commented 4 hours ago

Describe the bug Nullish coalescing operator (??) will trigger the detection of rule "rrd ~ nested Ternary"

To Reproduce Steps to reproduce the behavior:

  1. What is the exact code you are analyzing?

const testFunc = (arr: string[]) => arr ?? []

  1. What is the output you are getting?
-  rrd ~ nested Ternary
   src\views\xxx.vue
   👉 Break the nested ternary into standalone ternaries, if statements, && operators, or a dedicated function. See: https://vue-mess-detector.webmania.cc/rules/rrd/nested-ternary.html
   line #25 has nested ternary 🚨

Expected behavior Nullish coalescing operator (??) should avoid triggering the nestedTernary detection.

Used version number of vue-mess-detector: 0.57.0

Used version number of node & yarn: node@18.20.4, pnpm@9.8.0

Additional context vue-mess-detector.json:

{
  "apply": "vue-essential,vue-recommended,vue-strong,rrd,security",
  "ignore": "multiAttributeElements,ifWithoutCurlyBraces"
}
David-Pena commented 4 hours ago

Thanks for reporting!

Failing test added in last commit for reference 🫡

David-Pena commented 1 hour ago

By the way, using both --apply and --ignore flags should not be used at the same time 👀 https://github.com/rrd108/vue-mess-detector/issues/363

Again, thanks for reporting

David-Pena commented 1 hour ago

This is fixed in last commit https://github.com/rrd108/vue-mess-detector/commit/04eac5405a8f2041d68d0553f2cb7d8e6f6dbb3e

You can try it out via before its released thanks to pkg.pr.new via npm i https://pkg.pr.new/rrd108/vue-mess-detector@04eac54