Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@amousa11
Copy link
Contributor

@amousa11 amousa11 commented Jun 27, 2025

Summary

Port vue/no-deprecated-data-object-declaration and /vue/no-shared-component-data from eslint-plugin-vue -#6300

closes #6300

Test Plan

@changeset-bot
Copy link

changeset-bot bot commented Jun 27, 2025

⚠️ No Changeset found

Latest commit: cd8cf5e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Jun 27, 2025
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filtering needs to be a little more careful to prevent false positives. Could be nice to bring over test cases from the source rule.

Comment on lines 62 to 78
fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let member = ctx.query();

if let Ok(member_name) = member.name() {
if let Some(name) = member_name.name() {
if name.trim() == "data" {
if let Ok(value) = member.value() {
match value {
AnyJsExpression::JsIdentifierExpression(_)
| AnyJsExpression::JsArrowFunctionExpression(_)
| AnyJsExpression::JsFunctionExpression(_) => return None,
_ => return Some(()),
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be filtered so that it only runs in .vue files.

Comment on lines 65 to 78
if let Ok(member_name) = member.name() {
if let Some(name) = member_name.name() {
if name.trim() == "data" {
if let Ok(value) = member.value() {
match value {
AnyJsExpression::JsIdentifierExpression(_)
| AnyJsExpression::JsArrowFunctionExpression(_)
| AnyJsExpression::JsFunctionExpression(_) => return None,
_ => return Some(()),
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to make sure that the data member is at the specific level that we are expecting. This would be a false positive:

{
    methods: {
        foo() {
            const bar = {
                data: {}
            }
        }
    }
}

Copy link
Contributor Author

@amousa11 amousa11 Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d1c004b - I'm hoping this covers all the cases we need. Let me know if i'm still missing any here. I added this example + the test cases from both eslint rules in the snapshot tests

@dyc3 dyc3 added the D-Vue Domains: Vue label Jun 27, 2025
@amousa11 amousa11 changed the title Port vue/no-deprecated-data-object-declaration/vue/no-shared-component-data from eslint-plugin-vue feat(biome_js_analyze): noVueDataObjectDeclaration Jun 27, 2025
@amousa11 amousa11 requested a review from dyc3 July 1, 2025 05:32
@amousa11 amousa11 marked this pull request as ready for review July 1, 2025 05:35
Comment on lines 102 to 115
pub NoVueDataObjectDeclaration {
version: "next",
name: "noVueDataObjectDeclaration",
language: "vue",
recommended: true,
fix_kind: FixKind::Safe,
domains: &[RuleDomain::Vue],
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I missed this on my first pass -- This is missing the rule source that points to the original rule.

Comment on lines 122 to 124
// createApp(...), defineComponent(...)
AnyJsExpression::JsIdentifierExpression(_) => {
let options_argument = call.arguments().ok()?.args().elements().next()?.into_node();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the strings need to be checked here to make sure we don't hit false positives. As in, we need to make sure this is a call to createApp or defineComponent (PS -- you'll want to compare the TokenText, not a String).

That being said, I'm not sure if its worth invoking the semantic model here to make sure this is imported from vue. Since this rule is confined to the vue domain, I would think anyone calling these functions would be importing them from vue. So the simple string comparison will suffice.

Comment on lines 181 to 185
if let Ok(object_member_name) = property_object_member.name() {
if let Some(key_name) = object_member_name.name() {
if key_name.text().trim() == "data" {
if let Ok(value) = property_object_member.value() {
match value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You might want to try chaining .and_then() instead to reduce this indentation

Comment on lines 125 to 135
i Safe fix: Convert the data object to a function returning the data object
9 9 │ // app.component with object `data`
10 10 │ app.component('some-comp', {
11 │ - ··data:·{
11 │ + ··data:·function(){return{
12 12 │ foo: 'bar'
13 │ - ··}
13 │ + ··}}
14 14 │ });
15 15 │
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we try to make our fixes line up with what the formatter would output so the user doesn't have to run biome twice.

@dyc3
Copy link
Contributor

dyc3 commented Jul 7, 2025

@amousa11 Would you mind if I took over this PR? We have some more generic vue tooling coming in another PR that this would benefit from.

@amousa11
Copy link
Contributor Author

amousa11 commented Jul 8, 2025

@dyc3 No problem, I just pushed up my WIP based on your feedback. Can you link me to that PR for my own learning?

@dyc3
Copy link
Contributor

dyc3 commented Jul 9, 2025

@amousa11 The PR in question is #6757

I'll rebase this PR once that has landed and continue it from there.

@dyc3 dyc3 self-assigned this Jul 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

Walkthrough

A new lint rule, noVueDataObjectDeclaration, has been introduced to enforce that Vue component data properties are declared as functions rather than objects. This rule is fully integrated into the linting framework, configuration schema, diagnostics categories, and JSON-RPC backend types. The implementation includes the rule logic, configuration options (currently empty), and automatic fixes. Test cases for both valid and invalid Vue component patterns are provided. Type and schema definitions are updated to support the new rule, and Vue file handling in tests is refined to ensure correct preprocessing.

Assessment against linked issues

Objective Addressed Explanation
Port vue/no-deprecated-data-object-declaration/vue/no-shared-component-data as noVueDataObjectDeclaration rule (#6300)
Ensure rule only evaluates on .vue files (#6300)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were identified. All modifications are directly related to the introduction and integration of the noVueDataObjectDeclaration lint rule and its supporting infrastructure.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 370de76 and cd8cf5e.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/nursery/no_vue_data_object_declaration.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/src/lint/nursery/no_vue_data_object_declaration.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (26)
  • GitHub Check: Test Node.js API
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Check JS Files
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
crates/biome_js_analyze/src/lint/nursery/no_vue_data_object_declaration.rs (2)

133-133: Remove debug statements before merging.

These debug statements should be removed for production code.

-        dbg!("rule is running");
-        dbg!("found a component");
-        dbg!("found a data declaration");

Also applies to: 143-143, 149-149


153-162: Consider using combinators to reduce indentation.

The nested structure can be flattened using and_then chaining for better readability.

-        match data_decl {
-            AnyVueDataDeclarationsGroup::JsPropertyObjectMember(object_member) => object_member
-                .value()
-                .ok()
-                .and_then(|value| value.omit_parentheses().as_js_object_expression().cloned())
-                .map(|object_expression| State {
-                    data_decl_range,
-                    object_expression,
-                }),
-            AnyVueDataDeclarationsGroup::JsMethodObjectMember(_) => None,
-        }
+        match data_decl {
+            AnyVueDataDeclarationsGroup::JsPropertyObjectMember(object_member) => {
+                object_member
+                    .value()
+                    .ok()
+                    .and_then(|value| value.omit_parentheses().as_js_object_expression().cloned())
+                    .map(|object_expression| State {
+                        data_decl_range,
+                        object_expression,
+                    })
+            }
+            AnyVueDataDeclarationsGroup::JsMethodObjectMember(_) => None,
+        }

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 6, 2025

CodSpeed Performance Report

Merging #6574 will not alter performance

Comparing amousa11:feat-6300 (cd8cf5e) with main (9f4538a)

Summary

✅ 128 untouched benchmarks

@github-actions github-actions bot added the A-CLI Area: CLI label Aug 6, 2025
@dyc3 dyc3 changed the title feat(biome_js_analyze): noVueDataObjectDeclaration feat(analyze/js): add noVueDataObjectDeclaration Aug 6, 2025
@dyc3 dyc3 merged commit be42745 into biomejs:main Aug 6, 2025
30 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project D-Vue Domains: Vue L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port vue/no-deprecated-data-object-declaration/vue/no-shared-component-data from eslint-plugin-vue

2 participants