fix(variable-declarator): indent first variable in one-var scenario, fixes #2072 (#2095)

master
Lucas Azzola 2017-06-11 14:19:50 +10:00 committed by Christopher Chedeau
parent fdb7467de7
commit a79a444bac
3 changed files with 39 additions and 1 deletions

View File

@ -1226,10 +1226,18 @@ function genericPrintNoParens(path, options, print, args) {
const hasValue = n.declarations.some(decl => decl.init);
let firstVariable;
if (printed.length === 1) {
firstVariable = printed[0];
} else if (printed.length > 1) {
// Indent first var to comply with eslint one-var rule
firstVariable = indent(printed[0]);
}
parts = [
isNodeStartingWithDeclare(n, options) ? "declare " : "",
n.kind,
printed.length ? concat([" ", printed[0]]) : "",
firstVariable ? concat([" ", firstVariable]) : "",
indent(
concat(
printed

View File

@ -13,6 +13,16 @@ var a, b, c;
let superSuperSuperLong1, superSuperSuperLong2, superSuperSuperLong3, superSuperSuperLong4;
for (var i = 0, len = arr.length; i < len; i++) {}
var templateTagsMapping = {
'%{itemIndex}': 'index',
'%{itemContentMetaTextViews}': 'views'
},
separator = '<span class="item__content__meta__separator">•</span>',
templateTagsList = $.map(templateTagsMapping, function(value, key) {
return key;
}),
data;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var assert = require("assert"),
lookup = require("../lookup");
@ -30,6 +40,16 @@ let superSuperSuperLong1,
for (var i = 0, len = arr.length; i < len; i++) {}
var templateTagsMapping = {
"%{itemIndex}": "index",
"%{itemContentMetaTextViews}": "views"
},
separator = '<span class="item__content__meta__separator">•</span>',
templateTagsList = $.map(templateTagsMapping, function(value, key) {
return key;
}),
data;
`;
exports[`string.js 1`] = `

View File

@ -10,3 +10,13 @@ var a, b, c;
let superSuperSuperLong1, superSuperSuperLong2, superSuperSuperLong3, superSuperSuperLong4;
for (var i = 0, len = arr.length; i < len; i++) {}
var templateTagsMapping = {
'%{itemIndex}': 'index',
'%{itemContentMetaTextViews}': 'views'
},
separator = '<span class="item__content__meta__separator">•</span>',
templateTagsList = $.map(templateTagsMapping, function(value, key) {
return key;
}),
data;