stimulus-lsp icon indicating copy to clipboard operation
stimulus-lsp copied to clipboard

Code Action: Refactor shorthand-value definition to explicit version

Open marcoroth opened this issue 2 years ago • 1 comments

When a Stimulus value definition uses the shorthand-version we can offer a code action to expand the definition to the explicit version

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  static values = {
    name: String /* ┌───────────────────────────────────────────────────────────────────────┐
                    │  Quick-Fix... (⌘.)                                                    │
                    └───────────────────────────────────────────────────────────────────────┘
                      ┌────────────────────────────────────────────────────────────────┐
                      │ Quick-Fix                                                      │
                      ├────────────────────────────────────────────────────────────────┤
                      │ Implement default value for "name"                             │
                      ├────────────────────────────────────────────────────────────────┤
                      │ Refactor value definition to explicit version                  │
                      └────────────────────────────────────────────────────────────────┘  */


  }
}

Running either of the code actions should apply this diff:

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  static values = {
-    name: String
+    name: {
+      type: String,
+      default: ""
+    }
  }
}

marcoroth avatar Mar 05 '24 03:03 marcoroth

Depends on https://github.com/marcoroth/stimulus-parser/issues/79

marcoroth avatar Mar 05 '24 03:03 marcoroth