-
Notifications
You must be signed in to change notification settings - Fork 268
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
Fixing an issue with eslint not working in vscode #12746
Conversation
- Using rulesdir in the package scripts made it so the rules were only present when running them in the cli and showed errors in editors. This now allows the rules to run in the editor since I made a plugin using a local dependency - I also made is so lint rules can be run from root on pkg/rancher-components Fixes rancher#12670
12e3e89
to
c05f3ca
Compare
@@ -116,7 +118,7 @@ export default defineComponent({ | |||
isDisabled, | |||
validationMessage, | |||
requiredField | |||
} = useLabeledFormElement(props, emit); | |||
} = useLabeledFormElement(props, emit as emitMethodType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the emits will change the type of emit passed to the setup method. In this case it will be a union type of 'change' | 'update:value' | 'blur' | 'update:validation'
which surprisingly doesn't match the string type expected by useLabeledFormElement
. So I extracted the type and then cast appropriately here. I couldn't figure out a generic type that would work.
@@ -297,7 +297,7 @@ describe('stringList.vue', () => { | |||
await inputField.trigger('keydown.enter'); | |||
await wrapper.vm.$nextTick(); | |||
|
|||
const emitted = (wrapper.emitted('change') || [])[1][0][0]; | |||
const emitted = (wrapper.emitted('change') || [])[0][0][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When emits
is specified the value returned by emitted() omits the event type so I had to go through and subtract 1 from each index to account for the lack of event type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good development. This behavior was quite confusing while we were fixing the unit tests and it was unclear that omitting emits options was the root cause.
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lint rules in root require us to have an ending black newline at the end of each file.
@@ -70,7 +70,9 @@ export const labeledFormElementProps = { | |||
} | |||
}; | |||
|
|||
export const useLabeledFormElement = (props: LabeledFormElementProps, emit: (event: string, ...args: any[]) => void): UseLabeledFormElement => { | |||
export type emitMethodType = (event: string, ...args: any[]) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explained above, I needed to be able to type case the emit method elsewhere so I extracted the definition.
@@ -200,7 +200,8 @@ | |||
"webpack-virtual-modules": "0.4.3", | |||
"worker-loader": "3.0.8", | |||
"yaml-lint": "1.7.0", | |||
"yarn": "1.22.18" | |||
"yarn": "1.22.18", | |||
"eslint-plugin-local-rules": "link:./eslint-plugin-local-rules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make the local rules a linked dev dependency. This allows eslint to search for the rules as a plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to consider documenting this somewhere. I can see how someone might encounter this link in the future and have questions about why we are doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great - I have one suggestion about typing emits options in composables.
@@ -48,7 +48,8 @@ | |||
"sass-loader": "~12.0.0", | |||
"typescript": "4.5.5", | |||
"vue": "~3.2.13", | |||
"vue-template-compiler": "2.7.16" | |||
"vue-template-compiler": "2.7.16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vue-template-compiler
is very odd.. I've created an issue to address this and other dependencies that might not be needed after the Vue3 migration #12751
export type emitMethodType = (event: string, ...args: any[]) => void; | ||
|
||
export const useLabeledFormElement = (props: LabeledFormElementProps, emit: emitMethodType): UseLabeledFormElement => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we might be able to more explicitly type the emits by using defineEmits
:
export type emitMethodType = (event: string, ...args: any[]) => void; | |
export const useLabeledFormElement = (props: LabeledFormElementProps, emit: emitMethodType): UseLabeledFormElement => { | |
const labeledFormElementEmits = defineEmits(['update:validation']); | |
export const useLabeledFormElement = (props: LabeledFormElementProps, emit: typeof labeledFormElementEmits): UseLabeledFormElement => { |
This should accomplish two things:
- Simplify consumption of
useLabeledFormElement
by removing the requirement to type emits asemitMethodType
- Enforces that consumers define
update:validation
in their emits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, I had to also add the defineEmits import and remove the emitMethodType in the other file so I added it as a part of my commit instead of committing the suggestion.
@@ -297,7 +297,7 @@ describe('stringList.vue', () => { | |||
await inputField.trigger('keydown.enter'); | |||
await wrapper.vm.$nextTick(); | |||
|
|||
const emitted = (wrapper.emitted('change') || [])[1][0][0]; | |||
const emitted = (wrapper.emitted('change') || [])[0][0][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good development. This behavior was quite confusing while we were fixing the unit tests and it was unclear that omitting emits options was the root cause.
@@ -200,7 +200,8 @@ | |||
"webpack-virtual-modules": "0.4.3", | |||
"worker-loader": "3.0.8", | |||
"yaml-lint": "1.7.0", | |||
"yarn": "1.22.18" | |||
"yarn": "1.22.18", | |||
"eslint-plugin-local-rules": "link:./eslint-plugin-local-rules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to consider documenting this somewhere. I can see how someone might encounter this link in the future and have questions about why we are doing this.
c05f3ca
to
8625190
Compare
Added the |
8625190
to
c77ee88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #12670
Summary
Fixes #
Occurred changes and/or fixed issues
Technical notes summary
Areas or cases that should be tested
Areas which could experience regressions
Screenshot/Video
Checklist