-
-
Notifications
You must be signed in to change notification settings - Fork 963
feat(lint/vue): implement useVueMultiWordComponentNames
#7373
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
44ed11f
feat(analyze/vue): add helpers for grabbing the name of the component
dyc3 7b4b5ee
feat(lint/vue): implement `useVueMultiWordComponentNames`
dyc3 0213bfa
fix: diagnostic ranges are now in the right place
dyc3 71c20e6
fix docs
dyc3 70484c8
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
crates/biome_js_analyze/src/frameworks/vue/vue_component/component_name.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| use std::ops::Deref; | ||
|
|
||
| use biome_analyze::QueryMatch; | ||
|
|
||
| use super::*; | ||
|
|
||
| impl AnyVueComponent { | ||
| /// Try to infer the component's name from its definition. | ||
| pub fn component_name(&self) -> Option<(TokenText, TextRange)> { | ||
| let object_expression = match self { | ||
| Self::OptionsApi(c) => c | ||
| .definition_expression() | ||
| .and_then(|e| e.inner_expression()) | ||
| .and_then(|e| e.as_js_object_expression().cloned()), | ||
| Self::CreateApp(c) => c | ||
| .definition_expression() | ||
| .and_then(|e| e.inner_expression()) | ||
| .and_then(|e| e.as_js_object_expression().cloned()), | ||
| Self::DefineComponent(c) => c | ||
| .definition_expression() | ||
| .and_then(|e| e.inner_expression()) | ||
| .and_then(|e| e.as_js_object_expression().cloned()), | ||
| // <script setup> components are named by the file name, so we can't infer it here. | ||
| Self::Setup(_) => None, | ||
| }?; | ||
|
|
||
| // Find `name` property | ||
| for member in object_expression.members().into_iter().flatten() { | ||
| if let AnyJsObjectMember::JsPropertyObjectMember(property) = member { | ||
| if property | ||
| .name() | ||
| .ok() | ||
| .and_then(|n| n.name()) | ||
| .is_none_or(|n| n != "name") | ||
| { | ||
| continue; | ||
| }; | ||
|
|
||
| if let Ok(value_expr) = property.value() { | ||
| let value_expr = value_expr.omit_parentheses(); | ||
| if let Some(str_lit) = value_expr | ||
| .as_any_js_literal_expression() | ||
| .and_then(|e| e.as_js_string_literal_expression()) | ||
| && let Ok(token_text) = str_lit.inner_string_text() | ||
| { | ||
| return Some((token_text, str_lit.syntax().text_range())); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /// A Vue component name, either extracted from the component definition or inferred from the file path. | ||
| #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum VueComponentName<'a> { | ||
| FromComponent((TokenText, TextRange)), | ||
| FromPath(&'a str), | ||
| } | ||
|
|
||
| impl PartialEq<str> for VueComponentName<'_> { | ||
| fn eq(&self, other: &str) -> bool { | ||
| match self { | ||
| VueComponentName::FromComponent((name, _)) => *name == other, | ||
| VueComponentName::FromPath(name) => *name == other, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl PartialOrd<str> for VueComponentName<'_> { | ||
| fn partial_cmp(&self, other: &str) -> Option<std::cmp::Ordering> { | ||
| match self { | ||
| VueComponentName::FromComponent((name, _)) => name.text().partial_cmp(other), | ||
| VueComponentName::FromPath(name) => (*name).partial_cmp(other), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Deref for VueComponentName<'_> { | ||
| type Target = str; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| match self { | ||
| VueComponentName::FromComponent((name, _)) => name.text(), | ||
| VueComponentName::FromPath(name) => name, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl AsRef<str> for VueComponentName<'_> { | ||
| fn as_ref(&self) -> &str { | ||
| match self { | ||
| VueComponentName::FromComponent((name, _)) => name.text(), | ||
| VueComponentName::FromPath(name) => name, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.