简体   繁体   中英

Configure ESLint to allow a blank lines before blocks

My ESLint config is such that if I change this

if (something) {
    doSomething()
} else {
    doSomethingElse()
}

to

if (something) {
    doSomething()

} else {
    doSomethingElse()
}

I get this error:

Block must not be padded by blank lines padded-blocks

I would like to change my ESLint config to allow a single blank line before a block (as above). I tried add the following to my .eslintrc.js

rules: {
  'vue/html-closing-bracket-newline': 'off',
  'vue/max-attributes-per-line': 'off',
  'vue/attributes-order': 'off',
  'vue/singleline-html-element-content-newline': 'off',
  'no-debugger': 'off',
  'padded-blocks': ['error', {
    blocks: 'never',
    classes: 'never',
    switches: 'never',
  }, {
    allowSingleLineBlocks: true,
  }]
}

But it didn't work (blank lines still cause the same error). How can I configure ESLint to allow a blank line before a block?

ESLint doesn't have built-in support. The padded-blocks rule can only force spaces at the start and end but not for only either. You could, however, create your own custom rule based on the logic that governs it in the first place though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM