Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How to tell a JavaScript formatter to add blank lines between function definitions?

I have some JS files which I want to format nicer with a CLI formatter tool like Prettier. I tried Prettier itself, but I was surprised to find that it doesn't add blank lines between function definitions. I think this would enhance visual structure significantly.

An example might clarify what I'm after. Given the input source code:

import {foo, bar} from "./myfoobar.js"
export var myfirstfunc = function (para) {
  ...
}
// mysecondfunc does wonderful things
export var mysecondfunc = function (more, para) {
  ...
}

I would like to see the following output code with blank lines:

import {foo, bar} from "./myfoobar.js"

export var myfirstfunc = function (para) {
  ...
}

// mysecondfunc does wonderful things
export var mysecondfunc = function (more, para) {
  ...
}

In my test Prettier doesn't do this. Is there a way to tell Prettier -- or another formatter -- to do this kind of visual structuring?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can achieve something similar to this by using ESLint's padding-line-between-statements rule. Any sort of STATEMENT_TYPE (such as export, import, var) can be specified to require a blank line between it and another given STATEMENT_TYPE (or wildcard, to match anything).

The following config:

padding-line-between-statements: [
    "error",
    { blankLine: "always", prev: "export", next: "*" },
    { blankLine: "always", prev: "import", next: "*" },
    { blankLine: "always", prev: "var", next: "*" },
]

results in automatically fixed code of:

import {foo, bar} from "./myfoobar.js"

export var myfirstfunc = function (para) {
}

// mysecondfunc does wonderful things
export var mysecondfunc = function (more, para) {
}

Demo

Any IDE that supports ESLint's auto-fixing (such as VSCode) should be able to implement this.

Feel free to tweak with the config settings objects to require spaces between different types of statements as desired.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda