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

Diagnostic: Warn if invalid Stimulus Values Type is used #168

Closed
marcoroth opened this issue Feb 16, 2024 · 1 comment · Fixed by #212
Closed

Diagnostic: Warn if invalid Stimulus Values Type is used #168

marcoroth opened this issue Feb 16, 2024 · 1 comment · Fixed by #212
Labels
diagnostic Feature that implements a `textDocument/diagnostic` request. enhancement New feature or request feature Issue that implements a new feature.

Comments

@marcoroth
Copy link
Owner

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... (⌘.)                                                              │                              
                    └──────────────────────────────────────────────────────────────────────────────────────────────────────┘                                       */
@marcoroth marcoroth added enhancement New feature or request feature Issue that implements a new feature. diagnostic Feature that implements a `textDocument/diagnostic` request. labels Feb 16, 2024
@marcoroth
Copy link
Owner Author

marcoroth commented Mar 5, 2024

Resolved via #212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic Feature that implements a `textDocument/diagnostic` request. enhancement New feature or request feature Issue that implements a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant