Skip to content
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

Run eslint with --fix option #1628

Closed
lcaprini opened this issue Sep 9, 2017 · 2 comments
Closed

Run eslint with --fix option #1628

lcaprini opened this issue Sep 9, 2017 · 2 comments
Labels

Comments

@lcaprini
Copy link

lcaprini commented Sep 9, 2017

In my previous Vue projects I configured Webpack to run eslint with --fix option to autofix indent, spaces, etc.. but in Nuxt seems this option is missing.

For example, the followings are the rules is my .eslintrc.js

rules: {
    indent: ['error', 4],
    'space-before-function-paren': ['error', 'never'],
    'key-spacing': ['error', {
        beforeColon: true,
        afterColon: true,
        mode: 'minimum',
        align: {
            beforeColon: true,
            afterColon: true,
            on: 'colon'
        }
    }],
    semi: ['error', 'always'],
    'keyword-spacing': ['error', {
        before: true,
        after: true
    }],
    'brace-style': ['error', 'stroustrup']
},

For testing I change indentation in my error.vue to 2 spaces :

export default {
  name  : 'nuxt-error',
  props : ['error'],
  head() {
    return {
      title : this.error.message || 'An error occured'
    };
  }
};

So, if I use the npm run lint command (edited in "lint": "eslint --fix --ext .js,.vue --ignore-path .gitignore .",) all works fine, and the code now has 4 spaces indentation.

But if I use the npm dev command I have the following errors:

  17:1  error  Expected indentation of 4 spaces but found 2   indent
  18:1  error  Expected indentation of 4 spaces but found 2   indent
  19:1  error  Expected indentation of 4 spaces but found 2   indent
  20:1  error  Expected indentation of 8 spaces but found 4   indent
  21:1  error  Expected indentation of 12 spaces but found 6  indent
  22:1  error  Expected indentation of 8 spaces but found 4   indent
  23:1  error  Expected indentation of 4 spaces but found 2   indent

✖ 7 problems (7 errors, 0 warnings)
  7 errors, 0 warnings potentially fixable with the `--fix` option.

How can I configure eslint in Nuxt commands to turn on the fix helper?

Thank you

This question is available on Nuxt.js community (#c1453)
@lcaprini
Copy link
Author

lcaprini commented Sep 9, 2017

Solved adding fix option in nuxt.config.jsfile:

extend(config, ctx) {
    if (ctx.dev && ctx.isClient) {
        config.module.rules.push({
            enforce : 'pre',
            test    : /\.(js|vue)$/,
            loader  : 'eslint-loader',
            exclude : /(node_modules)/,
            options : {
                fix : true
            }
        });
    }
}

Thank you

@lcaprini lcaprini closed this as completed Sep 9, 2017
@lock
Copy link

lock bot commented Nov 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 3, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants