-
Notifications
You must be signed in to change notification settings - Fork 6
Integrate linting with official ESLint TypeScript plugin #18
Comments
TSLint is going to be deprecated so it probably doesn't make sense to use tslint-loader. I'm using eslint (and therefore eslint-loader) with the Once that plugin is configured, eslint-loader's text regex can be updated to include typescript files as well:
It's pretty slow in my experience, so I only use it for |
@GordonBlahut Thanks for suggesting |
Noticed the same problem, resorted to exclude I'll leave some link here to help setup of ESLint with TS support, which is the new preferred way, TSLint is going to be deprecated. https://github.com/typescript-eslint/typescript-eslint |
@FerrielMelarpis can you please rename the issue to something like "Integrate linting with official ESLint TypeScript plugin"? |
Thanks @IlCallo |
That would be a good thing :) |
Awesome, glad to see some progress on it. I can take a look at any PRs as needed. I'll keep an eye on this issue and it's progress. |
Some discoveries I made, while exploring ESLint typescript plugin:
I'll add more while I proceed in the study |
This is the Still, is something to work on. Note that you should change Interesting link: vuejs/eslint-plugin-vue#811 Current `.eslintrc.js` proposal for ESLint + TypeScript + Vue + Prettiermodule.exports = {
root: true,
// Must use parserOptions instead of "parser" to allow vue-eslint-parser to keep working
// See https://eslint.vuejs.org/user-guide/#how-to-use-custom-parser
parserOptions: {
parser: '@typescript-eslint/parser',
sourceType: 'module',
project: './tsconfig.json',
},
env: {
browser: true,
},
// Order here IS important
// See https://github.com/vuejs/eslint-plugin-vue/issues/811#issuecomment-467753982
extends: [
// Base ESLint recommended rules
'eslint:recommended',
// ESLint typescript rules
// See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
// `plugin:vue/base` is the default, consider switching to `plugin:vue/strongly-recommended`
// or `plugin:vue/recommended` for stricter rules.
// See https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
'plugin:vue/recommended',
// Usage with Prettier, provided by 'eslint-config-prettier'.
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage-with-prettier
'prettier',
'prettier/@typescript-eslint',
'prettier/vue',
],
plugins: [
// Required to apply rules which need type information
'@typescript-eslint',
// Required to lint *.vue files
// See https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-file
'vue',
],
globals: {
ga: true, // Google Analytics
cordova: true,
__statics: true,
process: true,
},
// add your custom rules here
rules: {
'prefer-promise-reject-errors': 'off',
// allow console.log during development only
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// allow debugger during development only
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// Custom
'vue/component-name-in-template-casing': ['error', 'kebab-case'],
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/explicit-function-return-type': 'off',
},
}; Important dependencies I currently have installed and their version (I may have missed some)
I tested all dependencies with ESLint 6 and they seem to work without problems, but not all of them already released ES6 battle-tested version (many already committed the change but did not published a release). |
Other caveats:
In conclusion: next major (2.0.0) will probably be much more useful than current version. Integration guidelines? Most of those files are from other extensions (testing, etc). @rstoenescu may I ask also your opinion on this? |
This is due to limitations of ESlint. ESlint will generate the AST for every single file that it lints and then
My workaround is to separate formatting and linting. I agree that we should be able to integrate a linting in this plugin but we should be keen to put the caveats on the documentation. FWIW, it would only be slow on initial compilation so a small price to pay for small to a medium codebase to keep them type-safe. |
Love to see the discussion and looking forward to making some progress on getting ESLint in place. Once some of the these pressing issues are completed I'm going to start a PR to add a Typescript section to the Quasar Docs, I would love your input on it when I do. If interested I will mention both of you so you can help review and contribute content. |
@outofmemoryagain Glad to hear that 👍I'll spend some time to review that PR. |
Yeah, ty! :)
That's the same thought I had, hence the I checked exactly what It just adds We already added This would also allow to write them down with a sensible order. Total extended rules, with ESLint + TypeScript + Vue + Prettier extends: [
// Base ESLint recommended rules
'eslint:recommended',
// ESLint typescript rules
// See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
// `plugin:vue/base` is the default, consider switching to `plugin:vue/strongly-recommended`
// or `plugin:vue/recommended` for stricter rules.
// See https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
'plugin:vue/recommended',
// Usage with Prettier, provided by 'eslint-config-prettier'.
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage-with-prettier
'prettier',
'prettier/@typescript-eslint',
'prettier/vue',
], I don't know how is the order "composable" at creation time tho |
Nope! ESLint doesn't actually generate any ASTs or anything of the sort. In the default use case it defers this work to When you kick off a lint with It's been hard to dig into why people are seeing slowness (because most of our users have private codebases that they can't share...). Some of it is attributed to |
@bradzacher That's interesting to know. I can maybe investigate further and see if there's something I can do to make my builds faster without removing the benefit of linting with type-checking.
What would |
Yup - within the tsconfig, you provide the Because you provide this up front, the typescript compiler treats all of these files as belonging to a single project, meaning it doesn't double parse any files. (note that i'm not 100% on this next bit btw - I haven't dug into the parser enough to understand exactly) |
Resolved by #22. Any remaining features or issues should be created as new issues to track individual tasks. |
When you opt-in to eslint feature of quasar-cli, it will inject the
eslint-loader
to the webpack config. Problem is even if the<script>
useslang="ts"
on a SFC, it will still run against it.Sample error when using
vue-property-decorator
Cannot recognize
readonly
as a keyword since it is only recognized by typescript.Not sure if the best option is to useinvestigatetslint-loader
.typescript-eslint
The text was updated successfully, but these errors were encountered: