Support for `padded-blocks` corner cases
DevOpsCraftsman opened this issue · 3 comments
Versions:
prettier-eslint
version: ^15.0.1node
version: v16.16.0npm
(oryarn
) version: 8.19.1
Relevant code or config
const format = require("prettier-eslint");
const sourceCode = `
class User {
constructor() {}
}
if (true) {
console.log('okay')
}
`;
const options = {
text: sourceCode,
eslintConfig: {
parserOptions: {
ecmaVersion: 7,
},
rules: {
"padded-blocks": ["error", {"classes": "always"}]
},
},
};
format(options).then(console.log)
Output:
class User {
constructor() {}
}
if (true) {
console.log("okay")
}
Problem description:
prettier-eslint
is mentionned as a solution for the unsupported padded-blocks
option here.
But it doesn’t seems to work for all cases, new lines in the if
block are stripped by prettier
.
The wanted output is :
class User {
constructor() {}
}
if (true) {
console.log("okay")
}
The reason is that prettier
is formatting the if
block, even if it’s not mark as error or warn by eslint
.
And after that, eslint
does not complain, because nothing is enforced (except for classes).
As a notice: it could be seen as a more generic issue, that is: only run prettier for errors/warns.
I actually wanted to open this issue at first with this kind of title.
This problem could even be out-of-scope of this lib…
As a notice: it could be seen as a more generic issue, that is: only run prettier for errors/warns.
That's impossible considering how Prettier works. Prettier is made for formatting the whole code as it wants. If you want to get your desired output, you should enforce that rule using ESLint. e.g.
rules = {
"padded-blocks": "error" // default is "always", for all code blocks including if
}
...or just consider not using Prettier at all, if the above is not really what you want to do (that means you want some inconsistency maybe).
Stale issue