-
Notifications
You must be signed in to change notification settings - Fork 887
Support linting vue/html file #2099
Comments
@nrip-monotype, you can use TSLint with Vue single file components by configuring module: {
rules: [
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: /(node_modules)/,
options: {
configFile: 'tslint.json'
}
},
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
isolatedModules: true
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
ts: 'ts-loader!tslint-loader'
}
}
},
}
}
} |
@romandragan, your suggestion works, but seems to have issues with
Is seen by tslint as:
If i set |
@lucastheisen, same issue for me 😞 Trying to find a solution... |
@romandragan's setup worked for me, but something to note is that the module: {
rules: [
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: /(node_modules)/,
options: {
configFile: 'tslint.json'
}
},
{
test: /\.ts$/,
exclude: /node_modules|vue\/src/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
isolatedModules: true,
typeCheck: true // This is ok.
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
ts: 'ts-loader!tslint-loader' // Can't append `?typeCheck` here.
}
}
},
}
}
} Trying to use type-checked rules in vue-loader yields an error like this:
|
I'm also getting the same |
I'm getting this
|
@aromancev, what version of webpack are you using? Do you have |
@romandragan, here is the npm config im using:
And this is the webpack config:
ts-loader and tslint-loader both installed and work fine since i get correct lint from *.ts files. |
As a workaround we can separate TypeScript logic from .vue file and remove |
@romandragan this works, but it would be nice to lint code inside |
@adidahiya any plan for this feature? |
If you are using Webpack, I've got Also, if you are using VSCode editor, check out the TSLint Vue extension. |
I have created a pull request that implements a plugin feature in tslint, and wrote the first plugin able to parse "vue" single file components. #3596 This is a work in progress, but feel free to try. You can add the plugin with |
Vue-loader can actually extract JavaScript or TypeScript from vue files, so parsing vue files is not a problem for webpack. However, TSLint still throws "Invalid source file" because file names are ended with ".vue" if typeCheck is enabled... In addition, we can make TSLint stop complaining consecutive blank lines by allowing consective blank lines at the beginning or the end of vue files, because vue-loader does not delete lines irrelevant to TypeScript but clear them instead to maintain correct line numbers. |
I'm currently working on a linter that could solve these problems without the need for webpack: https://github.com/ajafff/wotan It has the ability to transform files using a processor (similar to ESLint processors). A vue processor extracts the TypeScript code from the SFC, the linter only lints the code, then the processor maps the errors to the correct location in the original file. This even works with type checking. It also allows automatic fixing. Same file as above automatically fixed: https://github.com/ajafff/wotan/blob/master/baselines/integration/processors/vue/default/hello.vue#L28 Once I have fixed fimbullinter/wotan#32 I will publish a release so you can try it on your real world code. |
Does anyone know how I would set up |
I took a bit longer than I thought, but here it is: https://www.npmjs.com/package/@fimbul/wotan You can even use the linter runtime ( To lint Vue files, use |
Is there a schedule when will tslint support linting vue/html file? @Toilal |
I'm back with even greater news for everyone on this thread: The latest version of wotan can execute TSLint rules according to your
|
Thanks for the solution. But it's just a Webpack specific solution. It would be great if there was a generic solution that's not dependant on a build tool so that we could tslint Vue files compiled with Fusebox (or any other build tool). |
Another solution for webpack. I have created a simple loader which trims all whitespaces from a "file" provided by vue-loader and then add white space for a linter. webpack.config.js:
and then remove-whitespace-ts-loader: |
It works fine and permits not to modify sources, thanks |
Just so I am on the same page, is this not going to be fixed unless it is done as a PR? |
Besides |
mark |
Some more news here? 🤙 |
If someone want to use cli to lint your .vue file, you can try vue-tslint. It's not perfect, but it works... |
Note that @romandragan 's solution is now not best-practice (not sure if it was so previously). Instead, add For those using Vue CLI, add a config.module.rule('ts')
.use('tslint-loader')
.loader('tslint-loader'); statement to your vue.config.js module.exports = {
chainWebpack: (config) => {
config.devtool('source-map');
config.module.rule('ts')
.use('tslint-loader')
.loader('tslint-loader');
},
pluginOptions: {
apollo: {
enableMocks: true,
enableEngine: true
}
}
} |
This worked for me
|
Per #4379, a Vue-specific workaround isn't going to be able to land in TSLint core:
|
This comment has been minimized.
This comment has been minimized.
@akoidan please bring up issues like that with the wotan project, not tslint |
Feature Request
4.3.1
2.1.5
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
Tries to lint the whole file and fails.
Expected behavior
check for code inside script tags only, similar to eslint.
The text was updated successfully, but these errors were encountered: