-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add fragment options to lint code fragment for Vue SFC performance #1180
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
Comments
Essentially, using Also, your proposed option would do exactly the same thing as if you had just not passed We don't really want to encode specific framework information into our tooling, nor do we want to add options which only apply to one framework. We avoid it explicitly with angular and react. I think that this is a change which would be better suited for the vue parser. |
I try to So I will be In trouble. |
Yeah, so you have to use eslint overrides to disable rules requiring type information on vue files. I think that's much better than silently not failing, and then potentially showing incorrect errors, or missing errors due to incomplete types. |
@bradzacher The Typescript code is circled in this image. The main code is needed about requiring type information rules, In |
I'm with you now - sorry, I'm not all that familiar with vue, because I've never used it. The problem still stands, however, that this will put you in a bad place with regards to those rules. If you create an isolated program for each of the fragments (yellow), essentially typescript will parse them and do this:
This means that, for example, many of the rules that require type information that currently exist (like |
In
will use
The code fragment can't use the rules that require type information on now, |
I don't think you're understanding me. I'm saying that right now, typescript will do its best to consume globally defined types, etc in the fragments. That's what you get as part of the watch program. When in isolated mode, typescript will not use any globally defined types. This means that it cannot possibly resolve a type for Sure if you're only doing very simple This is probably something that needs to be handled differently from the vue-eslint-parser side. |
The typescipt code is
Unless the main code of export default object add code fragments and add The former is a big thing, and more difficult problem. |
Jeez, there's so much tooling, and hacks required to make vue work... If there was some changes made to the way vue parser outputs the source code, then you could have full typing and make this work. <template>
<nav :class="[$style['app-navbar'], { [$style['server-is-on-local']]: serverIsOnLocal }]">
<div :class="$style.container">
<div :class="$style.left">
<slot name="left" />
</div>
<div :class="$style.right">
<slot name="right" />
</div>
</div>
</nav>
</template>
<script lang="ts">
import { Component, Prop, Vue, Emit, Mixins } from 'vue-property-decorator'
import ConfigStorage from '@/storages/ConfigStorage'
import AppMixin from '@/components/AppMixin'
@Component({
name: 'AppNavbar'
})
export default class AppNavbar extends Mixins(AppMixin) {
localeKey = 'AppNavbar' as const
get serverIsOnLocal () {
return ConfigStorage.getInstance().url.indexOf('localhost') >= 0
}
}
</script> transforms to function fragments(this: AppNavbar) {
propertyBind_class = [this.$style['app-navbar'], { [this.$style['server-is-on-local']]: this.serverIsOnLocal }];
propertyBind_class = this.$style.container;
propertyBind_class = this.$style.left;
propertyBind_class = this.$style.right;
}
import { Component, Prop, Vue, Emit, Mixins } from 'vue-property-decorator'
import ConfigStorage from '@/storages/ConfigStorage'
import AppMixin from '@/components/AppMixin'
@Component({
name: 'AppNavbar'
})
export default class AppNavbar extends Mixins(AppMixin) {
localeKey = 'AppNavbar' as const
get serverIsOnLocal () {
return ConfigStorage.getInstance().url.indexOf('localhost') >= 0
}
} It also seems like this is something that could be achieved via eslint processors: given the file above, a export = {
processors: {
'typescript-vue-preprocessor': {
preprocess(text, filename) {
const {fragments, script} = splitVueFile(text);
return [
fragments.map((frag, idx) => ({
text: frag,
filename: filename.replace(/.vue$/, `.${idx}.fragment.vue`,
})),
{
text: script,
filename,
},
];
}
}
}
} Then eslint would pass each file to the parser(s) separately, and because of the filenames, you could do this in your config {
"overrides": [
{
"files": ["*.fragment.vue"],
"parserOptions": {
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser"
// note - no project
}
},
"rules": {
// disable typecheck rules
}
}
]
} |
You code have some problem about no use vue class component. |
@bradzacher preprocessor is nice idea, but it has few drawbacks in what you can do in some of rules do cross checking between vue template and script code, for example: https://eslint.vuejs.org/rules/no-unused-components.html and i'm unsure if this will be still possible.
|
I think a solution for Vue SFC performance.
Solution
change
typescript-eslint/typescript-eslint project
fragment
boolean option in@typescript-eslint/parser
.fragment === true
usecreateIsolatedProgram
in@typescript-eslint/typescript-estree
.vue-eslint-parser project
Test result
I have 109 TypeScript files and 119 Vue SFC files in this tested project.
Test code project
yoyo930021/typescript-eslint #commit
yoyo930021/vue-eslint-parser #commit
The text was updated successfully, but these errors were encountered: