Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added ignoredObjectNames option to vue/no-async-in-computed-properties #2927

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

Open
waynzh wants to merge 7 commits into master
base: master
Choose a base branch
Loading
from ignore-object-names

Conversation

Copy link
Member

@waynzh waynzh commented Sep 5, 2025

resolve #2917

Copy link

changeset-bot bot commented Sep 5, 2025
edited
Loading

🦋 Changeset detected

Latest commit: d5805cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Minor

Not sure what this means? Click here to learn what changesets are.

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

export default {
computed: {
foo: function () {
return z.a.b.c.d.e.f.method().catch(err => err).finally(() => {})
Copy link
Member

@FloEdelmann FloEdelmann Sep 5, 2025

Choose a reason for hiding this comment

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

For some more elaborate tests 😄

Suggested change
return z.a.b.c.d.e.f.method().catch(err => err).finally(() => {})
return z.a?.b!.['c'][d].e.f.method().catch(err => err).finally(() => {})

(The non-null assertion ! needs the typescript-eslint parser, so maybe this should be a separate test)

Copy link
Member Author

Choose a reason for hiding this comment

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

Just pushed a commit that adds a skipWrapper function to handle complex member expression chains with optional chaining support.

Decided not to use TypeScript AST node types directly since that could lead to a bunch of type conflicts...

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an ignoredObjectNames option to the vue/no-async-in-computed-properties rule to allow certain object names to be ignored when using promise-like methods. This is useful for validation libraries like Zod that use .then(), .catch(), and .finally() method names for non-promise purposes.

  • Adds schema validation for the new ignoredObjectNames array option
  • Implements logic to extract root object names from member expression chains and skip reporting when they match ignored names
  • Updates documentation with examples showing how to ignore Zod validation chains

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/rules/no-async-in-computed-properties.js Implements core logic for the ignoredObjectNames option with root object name extraction
tests/lib/rules/no-async-in-computed-properties.js Adds comprehensive test cases for valid and invalid usage with the new option
docs/rules/no-async-in-computed-properties.md Updates documentation with option details and Zod usage examples
.changeset/cute-bears-sneeze.md Adds changelog entry for the minor version feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 46 to 76
function getRootObjectName(memberExpr) {
let current = memberExpr.object

while (current) {
switch (current.type) {
case 'MemberExpression': {
current = utils.skipChainExpression(current.object)
break
}
case 'CallExpression': {
const calleeExpr = utils.skipChainExpression(current.callee)
if (calleeExpr.type === 'MemberExpression') {
current = calleeExpr.object
} else if (calleeExpr.type === 'Identifier') {
return calleeExpr.name
} else {
return null
}
break
}
case 'Identifier': {
return current.name
}
default: {
return null
}
}
}

return null
}
Copy link
Preview

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

The function parameter memberExpr suggests it expects a MemberExpression, but the function accesses memberExpr.object without validation. If a non-MemberExpression node is passed, this will cause a runtime error when trying to access the object property.

Copilot uses AI. Check for mistakes.

return false
}

const rootObjectName = getRootObjectName(callee)
Copy link
Preview

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

The getRootObjectName function expects a MemberExpression but callee is already confirmed to be a MemberExpression at line 84. However, the function should validate its input parameter or the call should be made more explicit about the type being passed.

Copilot uses AI. Check for mistakes.

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Thanks!

waynzh reacted with heart emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

Copilot code review Copilot Copilot left review comments

@FloEdelmann FloEdelmann FloEdelmann approved these changes

@ota-meshi ota-meshi Awaiting requested review from ota-meshi

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Vue ESLint: false positive of vue/no-async-in-computed-properties due to using zod .catch inside a computed

AltStyle によって変換されたページ (->オリジナル) /