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

implements autofix in define-props-declaration (#2465) #2466

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

mpiniarski
Copy link

@mpiniarski mpiniarski commented May 27, 2024

Fixes #2465

@mpiniarski
Copy link
Author

@FloEdelmann can I get some attention to this PR?

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 the ping! I had an initial look now.

lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
tests/lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
@mpiniarski mpiniarski force-pushed the feature/#2465_autofix_in_define-props-declaration branch from 28aab32 to 7d9e731 Compare June 21, 2024 13:07
@mpiniarski
Copy link
Author

@FloEdelmann applied changes, please review again

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Thank you for working on that implementation!

It seems to be causing an error in CI. Could you please fix that as well?

docs/rules/define-props-declaration.md Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
@FloEdelmann
Copy link
Member

@ota-meshi Could you please clear the Netlify cache and restart the deployment? That would make the rule (and docs) changes easier to test.

@ota-meshi
Copy link
Member

I cleared the cache and restart. The PR status remains failed, but it seems to have worked.
https://deploy-preview-2466--eslint-plugin-vue.netlify.app/rules/define-props-declaration.html

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.

Some more small JSDoc suggestions, then this is good to go from my side! Thanks for the contribution!

lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
@mpiniarski mpiniarski force-pushed the feature/#2465_autofix_in_define-props-declaration branch from 9cca135 to e9d4400 Compare July 4, 2024 07:38
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
lib/rules/define-props-declaration.js Outdated Show resolved Hide resolved
@so1ve
Copy link
Member

so1ve commented Jul 9, 2024

Should we fix it to multi-line interface, then make the separator configurable?

@FloEdelmann
Copy link
Member

No, let's keep it single-line and leave the rest to other ESLint rules or formatters like Prettier.

tests/lib/rules/define-props-declaration.js Show resolved Hide resolved
*/
function getComponentPropData(prop, sourceCode) {
if (prop.propName === null) {
throw new Error('Unexpected prop with null name.')
Copy link
Member

Choose a reason for hiding this comment

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

Why does it need to throw an error here?
Can't we make it guard against those before processing the autofix?

Copy link
Author

@mpiniarski mpiniarski Jul 15, 2024

Choose a reason for hiding this comment

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

What do you mean?
I think it's more clear if we throw an error here.

Copy link
Member

Choose a reason for hiding this comment

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

I think that if we throw an error, the user's eslint command will fail.
Did you throw the error with that intention? If so, why is that?
If auto-fix is not possible, I think it should be handled so that auto-fix is not performed, rather than throwing an error.

Copy link
Author

Choose a reason for hiding this comment

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

I see. Let me catch errors and ignore them.

I prefer to leave a sign of an error somewhere, maybe in console.debug(), but it is up to you.

filename: 'test.vue',
code: `
<script setup lang="ts">
const props = defineProps([kind])
Copy link
Member

Choose a reason for hiding this comment

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

The array elements must be strings. The kind variable shouldn't auto-fix because we don't know what's actually in it.
Could you leave this test as a test case for when not to auto-fix and add a new test case using a string literal?

https://vuejs.org/guide/components/props.html#props-declaration

Copy link
Author

Choose a reason for hiding this comment

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

My bad, you're right. It does not default to a string. Leaving it unhandled then.

Copy link
Member

Choose a reason for hiding this comment

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

Could you please add the test case you requested earlier?

      <script setup lang="ts">
      const props = defineProps(['kind'])
      </script>

#2466 (comment)

@mpiniarski
Copy link
Author

@ota-meshi can you take a look?

*/
function getComponentPropData(prop, sourceCode) {
if (prop.type === 'array') {
throw new Error(`Unable to resolve types based on array prop declaration.`)
Copy link
Member

Choose a reason for hiding this comment

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

Could you please implement it so that the autofix stops without throwing an error?

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.

Add autofix to define-props-declaration: transform runtime syntax to type-based syntax
4 participants