marcoroth/stimulus-lsp

Diagnostic: Warn if invalid Stimulus Values Type is used

Closed this issue · 1 comments

Sometimes it can be tricky to remember the Stimulus Values Syntax and what needs to go where. We can validate the type of the Stimulus Value.

For example, you might pass the type as a String instead of the object.

static values = {
  url: "String"
};     ^^^^^^^^ /*
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ The type of a Stimulus Value type cannot be `"String"`. It must be `Array`, `Object`, `Number`,      │
│ `String` or `Boolean`.                                                                               │
│ Stimulus LSP (stimulus.controller.value.type.invalid)                                                │
├──────────────────────────────────────────────────────────────────────────────────────────────────────┤
│  View Problem (⌥F8)   Quick-Fix... (⌘.)                                                              │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘
*/

The same diagnostic should be applied in the expanded object-form:

static values = {          
  url: {                     
    default: "Bob",          
    type: "String"             
  }        ^^^^^^ /*┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐      
};                  │ The type of a Stimulus Value type cannot be `"String"`. It must be `Array`, `Object`, `Number`,      │                 
                    │ `String` or `Boolean`.                                                                               │             
                    │ Stimulus LSP (stimulus.controller.value.type.invalid)                                                │                                  
                    ├──────────────────────────────────────────────────────────────────────────────────────────────────────┤                   
                    │  View Problem (⌥F8)   Quick-Fix... (⌘.)                                                              │                              
                    └──────────────────────────────────────────────────────────────────────────────────────────────────────┘                                       */

Resolved via #212