-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
conflict when use class-style component syntax and airbnb eslint rule #1203
Comments
This is a valid eslint warning https://eslint.org/docs/rules/class-methods-use-this . If you add something to your |
This rule is enforced by the Airbnb config, I don't think we'd want to disable specific rules when using an existing config, otherwise you lose the point of using a config. There will probably be a lot other cases that the user wants to tweak as well, so you'd just have to tweak it to your liking. |
Thanks for your responses. |
@weizhihuang you can always disable rules for one off cases where you want the linter to ignore it https://eslint.org/docs/user-guide/configuring.html#disabling-rules-with-inline-comments |
@dhensche well, I think I just disable this rule in .eslntrc |
@yyx990803 AirBnB exempts react lifecycle method names: https://github.com/airbnb/javascript/blob/8468ed842314a5d66816927ba6c35f018035cffc/packages/eslint-config-airbnb/rules/react.js#L21 Would you consider adding exceptions to Vue lifecycle method names as well? |
Also, for the DYI approach, I just modified my project's
|
For those still wrestling with this: adding the following to overrides: [
{
files: [ '*.vue'],
rules: {
'class-methods-use-this': ['error', {
exceptMethods: [
// vue lifecycle methods
'beforeCreate',
'created',
'beforeMount',
'mounted',
'beforeUpdate',
'updated',
'activated',
'deactivated',
'beforeDestroy',
'destroyed',
'errorCaptured',
],
}],
},
},
], |
Since React lifecycle are excepted by default it does seem reasonable that the Vue-generated linting configuration would provide first class support for Vue. Would it be possible for these exceptions to be included in the default generated configuration? |
Version
3.0.0-beta.6
Reproduction link
https://github.com/BGPSekai/T.Vey-frontend/blob/d09c83f82def85ace3f2739982648ee2629b1bb0/src/views/About.vue
Steps to reproduce
I create a project which select these options:
TypeScript
Progressive Web App (PWA) Support
Router
Vuex
CSS Pre-processors(SCSS)
Linter / Formatter(ESLint Airbnb config)(on save and fix on commit),
use class-style component syntax, Babel alongside TypeScript for auto-detected polyfills, then install it with Yarn.
Then I add lifecycle methods(like created) which code like this:
Then I run yarn serve(or lint), it occurred an error with eslint, it said:
error: Expected 'this' to be used by class method 'created' (class-methods-use-this)
What is expected?
I think it will be OK
What is actually happening?
It just couldn't pass the lint rule
Actually, it occurs when I use 3.0.0-beta.7, but I can't select this version in issue helper.
BTW, add this in .eslintrc can ignore this lint rule:
but I think this shouldn't occur after I build the project with vue-cli.
The text was updated successfully, but these errors were encountered: