Skip to content

script-indent make me crazy!!!!!!! #362

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

Closed
wengpengfeijava opened this issue Jan 25, 2018 · 21 comments
Closed

script-indent make me crazy!!!!!!! #362

wengpengfeijava opened this issue Jan 25, 2018 · 21 comments

Comments

@wengpengfeijava
Copy link

Tell us about your environment

  • ESLint Version: ^4.15.0
  • eslint-plugin-vue Version: ^4.0.0
  • Node Version: ^8.9.0
  • IDE: webstorm 2017.2.5

Please show your full configuration:

// https://eslint.org/docs/user-guide/configuring
module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true
  },
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/essential',
    // https://github.com/standard/standard/blob/master/docs/RULES-en.md
    'standard'
  ],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  // add your custom rules here
  rules: {
    // // 没找到解决方案, 一格式化webstorm script标签下面就会缩进,一缩进,eslint就报警。
    // // 只能从根源把他且了。
    // 'indent': ['off'],
    // allow async-await
    'generator-star-spacing': 'off',
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  }
}

What did you do? Please include the actual source code causing the issue.

<template>
  <div id="app">
    
  </div>
</template>

<script>
 export default {
   name: 'App'
 }
</script>

What did you expect to happen?

<template>
  <div id="app">
    
  </div>
</template>

<script>
  // attension here. it is about 2 indent before javascript code
   export default {
     name: 'App'
   }
</script>

What actually happened? Please include the actual, raw output from ESLint.

This happend when i command in npm run dev

    http://eslint.org/docs/rules/indent  Expected indentation of 0 spaces but found 2  
  src\App.vue:10:1
    export default {
   ^

    http://eslint.org/docs/rules/indent  Expected indentation of 2 spaces but found 4  
  src\App.vue:11:1
      name: 'App'
   ^

    http://eslint.org/docs/rules/indent  Expected indentation of 0 spaces but found 2  
  src\App.vue:12:1
    }
   ^

As you can see above. This is not my expect things. Does any config to avoid these happen?

Otherwise, i may closing the indent config.although it is not a good experience.

@mysticatea
Copy link
Member

Thank you for the report.

But it looks to be the errors of core indent rule rather than our vue/script-indent rule.

If you use vue/script-indent rule with baseIndent is 1, it would let you use one indentation in the <script> tags.

Note the vue/script-indent rule in the current version has a bug around property shorthand.

@wengpengfeijava
Copy link
Author

J just try to configuring rules as

'vue/script-indent': ['warn', 2, {
  'baseIndent': 1
}]
<script>
   // attension here. it is about 2 indent before javascript code
  export default {
     name: 'App'
   }
</script>

It still show the error

    http://eslint.org/docs/rules/indent  Expected indentation of 0 spaces but found 2  
  src\App.vue:10:1
    export default {
   ^
  ...

Instead, I did removed the indent before the javascript code.

It showed warnings below

    https://google.com/#q=vue%2Fscript-indent  Expected indentation of 2 spaces but found 0 spaces  
  src\App.vue:10:1
  export default {
   ^

    https://google.com/#q=vue%2Fscript-indent  Expected indentation of 4 spaces but found 2 spaces  
  src\App.vue:11:1
    name: 'App'
   ^

I do really have no ideas about these , please help me! (⊙o⊙)

@mysticatea
Copy link
Member

'indent': 'off',
'vue/script-indent': ['warn', 2, {
  'baseIndent': 1
}]

@wengpengfeijava
Copy link
Author

All right! It seems to be possible. thank you very much .

@wengpengfeijava
Copy link
Author

wengpengfeijava commented Jan 25, 2018

I spent much time to know why dose these code warned me

const router = [];

new Vue({
     router
})

I awake to know that you've said

Note the vue/script-indent rule in the current version has a bug around property shorthand.

So , i am still perplexed.Forgive me! I am still have no idea... (⊙o⊙)

@mysticatea
Copy link
Member

That bug has been fixed in #346, but we have not released it yet. Please wait for the next release...

Closing since it's fixed on master branch.

@michalsnik
Copy link
Member

Sorry for late release.. Enjoy :) https://github.com/vuejs/eslint-plugin-vue/releases/tag/v4.2.1

@wengpengfeijava
Copy link
Author

Thank you for your bug fixed.

@BarryZhan
Copy link

If you are using webstorm, you can File => Setting => Editor => Code Style => HTML add Do not indent children of rule to script

@leeuwd
Copy link

leeuwd commented Jul 20, 2018

When working with *.vue files, this seems a better option to me: to disable the indent rule only for Vue files and set a base indent:

module.exports = {
  root: true,
  env: {
    node: true,
  },
  'extends': [
    'plugin:vue/strongly-recommended'
  ],
  rules: {
    'indent': ['error', 2],
    'vue/script-indent': [
      'error',
      2,
      { 'baseIndent': 1 }
    ],
  },
  'overrides': [
    {
      'files': ['*.vue'],
      'rules': {
        'indent': 'off'
      }
    }
  ]
};

@Grawl
Copy link

Grawl commented Nov 26, 2018

Just faced this problem

changed this:

		"vue/script-indent": [
			"error",
			"tab",
			{
				"baseIndent": 1
			}
		]

to this:

		"vue": {
			"script-indent": [
				"error",
				"tab",
				{
					"baseIndent": 1
				}
			]
		}

and problem solved

@begueradj
Copy link

@mysticatea
I want to get indentation errors instead of warnings, I did this but I am still getting warnings instead:

rules: {                                                                                                                                       
    "vue/script-indent": ["error", 2, {                                                                                                          
      "baseIndent": 0,                                                                                                                           
      "switchCase": 0,                                                                                                                           
      "ignores": []                                                                                                                              
    }]                                                                                                                                           
  }  

What am I missing? Thank you

@apoorvpatne10
Copy link

Why not just include /* eslint-disable */ to ignore all warnings? Worked for me.

@Grawl
Copy link

Grawl commented Jun 18, 2019

this is not best solution

@apoorvpatne10
Copy link

I never said it's the best solution. It seems to work well for me, and might work for others too.

@Grawl
Copy link

Grawl commented Jun 21, 2019

ofcourse it works

@Ezra-Siton-UIX
Copy link

Ezra-Siton-UIX commented Apr 11, 2020

Why this issue is closed? Mega bug - still happens.

My solution - remove this plugin and wait for better options (Or fixing this issues - one extra space in your code throw mega error no way to compile ? This does not make sense):

npm remove @vue/cli-plugin-eslint 

@Tofandel
Copy link

Tofandel commented May 7, 2020

@apoorvpatne10 Why use eslint in the first place if you need to disable it in all your files 🤯

@begueradj You need to use the indent rule I think

'indent': ['error', 2],

@MaximSemenov
Copy link

MaximSemenov commented May 23, 2020

If you are using WebStorm or PhpStrom by JetBrains open setting by

Cmd + ' , ' (on Mac)

Editor->Code Style -> Javascript

Select checkbox Use tab character'

Screenshot 2020-05-23 at 13 42 35

Do not let ESLint to decide how many tabs should be and keep it simple like so

"indent": [ "error", "tab" ],

ESlint just checks that tabs are used

@SmelayaPanda
Copy link

SmelayaPanda commented Aug 3, 2020

If you are using webstorm, you can File => Setting => Editor => Code Style => HTML add Do not indent children of rule to script
@BarryZhan

For last Webstorm versions File => Setting => Editor => Code Style => Vue add Indent children of top level tag: script, style`
Screenshot 2020-08-03 at 12 33 34

@manojbaishya
Copy link

manojbaishya commented Oct 9, 2022

This bug still exists when using Volar with Vite and format document.

.eslintrc.cjs

/* eslint-env node */
module.exports = {
    root: true,
    extends: [
        "eslint:recommended",
        'plugin:vue/base',
        'plugin:vue/vue3-essential',
        'plugin:vue/vue3-recommended',
        'plugin:vue/vue3-strongly-recommended',
        '@vue/typescript/recommended',
        "@vue/eslint-config-typescript/recommended",
    ],
    rules: {
        "indent": ["error", 4],
        "vue/html-indent": ["error", 4, {
            "attribute": 1,
            "baseIndent": 1,
            "closeBracket": 0,
            "alignAttributesVertically": true,
            "ignores": []
        }],
        "vue/script-indent": ["error", 4, {
            "baseIndent": 1,
            "switchCase": 1,
            "ignores": []
        }],
    },
    overrides: [
        {
            files: ['*.vue'],
            rules: {
                indent: 'off'
            }
        }
    ]
};

Before fixing the problems:

image

After fixing using Code Actions:

image
image

Using Volar Document Formatter -> Back to the same problem!

image
image

Any way to make Volar compatible with the “vue/script-indent” rule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests