Do not indent for switch case with `;` (#1687)

The indentation detection didn't discard empty statements
master
Christopher Chedeau 2017-05-23 13:58:43 -07:00 committed by GitHub
parent bcc3eb9272
commit 47d9686402
4 changed files with 30 additions and 1 deletions

View File

@ -3,3 +3,4 @@
/tests/**/*.js
!/tests/**/jsfmt.spec.js
!/**/.eslintrc.js
/test.js

View File

@ -1423,8 +1423,13 @@ function genericPrintNoParens(path, options, print, args) {
.filter(e => e !== null)
);
}, "consequent");
const consequent = n.consequent.filter(
node => node.type !== "EmptyStatement"
);
parts.push(
n.consequent.length === 1 && n.consequent[0].type === "BlockStatement"
consequent.length === 1 && consequent[0].type === "BlockStatement"
? concat([" ", cons])
: indent(concat([hardline, cons]))
);

View File

@ -143,6 +143,24 @@ switch (a) {
`;
exports[`empty_statement.js 1`] = `
switch (error.code) {
case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: {
nls.localize('errorInvalidConfiguration', "Unable to write into settings. Correct errors/warnings in the file and try again.");
};
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
switch (error.code) {
case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: {
nls.localize(
"errorInvalidConfiguration",
"Unable to write into settings. Correct errors/warnings in the file and try again."
);
}
}
`;
exports[`empty_switch.js 1`] = `
switch (1) { default:; }
switch (1) {}

View File

@ -0,0 +1,5 @@
switch (error.code) {
case ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION: {
nls.localize('errorInvalidConfiguration', "Unable to write into settings. Correct errors/warnings in the file and try again.");
};
}