Eslint-plugin-vue: vue/script-indent 配置问题

Created on 19 Jan 2018  ·  28Comments  ·  Source: vuejs/eslint-plugin-vue

我尝试 增加如下配置到 rules中

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

在main.js中使用如下代码

new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})

在components行会报如下错误
[eslint] Expected indentation of 4 spaces but found 2 spaces. (vue/script-indent)

如果使用如下缩进就不会出错

new Vue({
  el: '#app',
  router,
    components: {App},
  template: '<App/>'
})

但这跟standard的配置时相悖的

bug duplicate

Most helpful comment

@wengpengfeijava 改一下webstorm规则就好了, File => Setting => Editor => Code Style => HTML 找到 add Do not indent children of 的选项,添加 script 标签就完美解决缩进问题。

All 28 comments

在我的团队中,一部分人使用webstorm,一部分人使用vscode,
插件的默认配置在vscode中表现良好,但在webstorm中,进行代码格式化时,script内的代码标签会缩进两行。

Thank you for this issue.

I can't read Chinese, but I guess this is a duplicate of #344 and #347.
PR #346 has fixed it. Please wait for the next release.

@ldwqh0 你好,我也遇到了这个问题,请问您解决了这个问题没有?怎么解决的?

没有解决,我现在临时的做发是让大家不用WebStorm的格式化功能。改用webstorm的eslint自动修复功能来格式化代码,但效果不是很好,但最起码不会报错。
其实这个问题的核心就是

加了这个玩意儿简直是存心让我们前端不好过啊~, script 标签下面不能缩进, 一缩进就跪, 总不能改webstorm的配置吧。都不知道怎么处理了 。

我们再这里讨论的的热火朝天,可惜这个issue closed.
我们来发起另外一场讨论。
你们是希望script标签里面的内容缩进呢还是不缩进呢?

还有,我的E文不太好,你们谁翻译一下,让作者看看。

我把eslint的缩进给禁了

要用这个配置,在当前版本只能禁用,冲突了。

看来只能这么干了, 为什么script下面不能缩进呢,瞎折腾 。

不是不能缩进,webstorm的缩进规则和eslint的冲突了,
比如

webstorm格式化

<script>
    exports default {
    }
</script>

eslint-vue

<script>
exports default {
}
</script>

这两个的区别

我习惯写完代码格式化啊 ,我一格式化,save就警告了。找了一早上的文档试试能不能不这样,没找到。

@BusyHe
嗯,是这样。我本身更支持ws的缩进,对es6的支持堪称完美。
vs code在格式化的路上,还有很长的路要走。

我怎么觉得是他们的bug呢 。

用蹩脚英语问了下,大概这么处理。 #362

这就是我最头上的处理方式,但会有问题,

new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})

router那一行会报错

/* eslint-disable no-new */
new Vue({ el: '#app', router, components: { App }, template: '<App/>' }) 

我这么写完美的避开了错误。。。

但是。。好像还是坑 诶

这么写没问题,

/* eslint-disable no-new */
new Vue({
  router: router
})

这么写就会有问题

/* eslint-disable no-new */
new Vue({
  router
})

image 我算是知道这哥们说的这句话的意思了。。

所以这个问题解决了吗?
我现在已经是碰到这个问题,提示:

http://eslint.org/docs/rules/indent Expected indentation of 0 spaces but found 2

这是我的配置,在最近的项目中,好像没有什么问题了。

 parserOptions: {
    parser: 'babel-eslint'
  },
  extends: [
    'standard',
    'plugin:vue/strongly-recommended'
  ],
'rules': {
    // allow paren-less arrow functions
    'arrow-parens': 0,
    // allow async-await
    'generator-star-spacing': 0,
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    'vue/max-attributes-per-line': ['error', {
      'singleline': 3,
      'multiline': {
        'max': 1,
        'allowFirstLine': true
      }
    }],
    'vue/script-indent': ['error', 2, {'baseIndent': 1}],
    'indent': 'off'
  }

我的代码长这样

import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false
console.log('Created By [email protected]')
/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: {
    App
  },
  template: '<App/>'
})

@wengpengfeijava 改一下webstorm规则就好了, File => Setting => Editor => Code Style => HTML 找到 add Do not indent children of 的选项,添加 script 标签就完美解决缩进问题。

@ldwqh0 因为你设置了:

'indent': 'off'

所以没检测

"vetur.format.styleInitialIndent": false,
"vetur.format.scriptInitialIndent": false