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

Don't report user-defined createApp function in vue/one-component-per-file #2203

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

candy-Tong
Copy link

No description provided.

@candy-Tong candy-Tong force-pushed the master branch 2 times, most recently from ed050e9 to 257c814 Compare June 1, 2023 08:54
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 for implementing a fix! I have one comment, see below :)

lib/utils/index.js Outdated Show resolved Hide resolved
@FloEdelmann FloEdelmann changed the title fix: [one-component-per-file] do not check createApp function written by the developer #2201 Don't report user-defined createApp function in vue/one-component-per-file Jun 5, 2023
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.

Looks good to me now, thanks :)

@@ -2536,6 +2537,31 @@ function getVueComponentDefinitionType(node) {
if (callee.name === 'createApp') {
// for Vue.js 3.x
// createApp({})

const variable = findVariable(context.getScope(), callee)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the late reply. I am busy with office work.

I think it can be written more simply using tracker.iterateEsmReferences.

https://eslint-community.github.io/eslint-utils/api/scope-utils.html#tracker-iterateesmreferences

e.g.

          const tracker = new ReferenceTracker(context.getSourceCode().scopeManager.globalScope)
          const traceMap = utils.createCompositionApiTraceMap({
            [ReferenceTracker.ESM]: true,
            createApp: {
              [ReferenceTracker.CALL]: true
            }
          })
          if ([...tracker.iterateEsmReferences(traceMap)].every(({ node }) => node !== callee)) {
            return null;
          }

Copy link
Member

Choose a reason for hiding this comment

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

@candy-Tong Would you like to give this a try?

@ota-meshi ota-meshi marked this pull request as draft January 30, 2024 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[one-component-per-file] do not check createApp function written by the developer
3 participants