2017-02-03 26 views
0

在我.eslintrc我有以下幾點:ESLint總是扔鍵間距誤差

'key-spacing': [ 'error', { 
    'singleLine': { 
     'beforeColon' : false, 
     'afterColon' : true 
    }, 
    'multiLine': { 
     'beforeColon' : false, 
     'afterColon' : true, 
     'align'   : 'colon' 
    } 
}] 

,目的是爲了確保在對象賦值,以下是真實的:

  1. 單行分配,每個冒號前沒有空格,但是後面有一個。
  2. 在多行分配中,冒號水平排列,而 每個冒號前後都有一個空格。

奇怪的是以下三個代碼片段:

1從我app.vue文件。

export default { 
    name  : 'app', 
    components : { 
     todos 
    } 
} 

2 [來自我的main.js文件]。

new Vue({ 
    el  : '#app', 
    render : h => h(App) 
}) 

3 [來自我的Hello.spec.js文件]。

const vm = new Vue({ 
    el  : document.createElement('div'), 
    render : h => h(Hello) 
}) 

上的鍵間距eslint規則中的每個引發錯誤:

/Users/autoboxer/development/learning-vue/src/app.vue 
    12:3 error Missing space after key 'name' key-spacing 

/Users/autoboxer/development/learning-vue/src/main.js 
    6:2 error Missing space after key 'el' key-spacing 

/Users/autoboxer/development/learning-vue/test/unit/specs/Hello.spec.js 
    7:4 error Missing space after key 'el' key-spacing 

我無法從我的設置弄清楚爲什麼他們會造成列出的錯誤,因爲有必要的空間後,每個指定的字,但任何幫助,將不勝感激。

+1

使用標籤,也許? –

+0

我正在使用選項卡。奇怪的是,它只是抱怨每種情況下的頂線。所有這三個文件都應該引出兩個錯誤,但是第一個對象成員是唯一抱怨的對象。 – autoboxer

+0

這是問題所在,我需要使用空格而不是製表符對齊它們。 – autoboxer

回答

2

此規則的配置非常複雜。我知道你在尋找的是這樣的:

'key-spacing': [ 'error', { 
    'singleLine': { 
     'beforeColon' : false, 
     'afterColon' : true 
    }, 
    "align": { 
     "beforeColon" : true, 
     "afterColon" : true, 
     "on"   : "colon" 
    } 
}] 

然而,即使有這樣的配置,ESLint不允許的冒號任意位置。它們必須儘可能接近對象中最長的鍵名。因此,通過上述配置,您的代碼必須更改爲:

export default { 
    name  : 'app', 
    components : { 
     todos 
    } 
} 

這將正確使用我提供的配置。

+0

謝謝伊利亞,那絕對是我面臨的一半問題。另一半是我使用製表符而不是空格。由於難以確定與製表符對齊,因此無法使用它們。在這個問題中概述:https://github.com/eslint/eslint/issues/1727 – autoboxer