Unstable indentation of comment around `else`
See original GitHub issueSeems close to issue #1161.
Prettier 1.19.1 Playground link
--parser babel
--use-tabs
Input:
// UI.js v3.4.0
/* eslint-env browser */
/* exported ui, _doc, getEL, createEL */
/* ui.js Locals */
var _doc = document;
function getEL(id){ return _doc.getElementById(id);}
function createEL(tagName){ return _doc.createElement(tagName);}
//---------------------------------------------------------------------------
// ★uiオブジェクト UserInterface側のオブジェクト
//---------------------------------------------------------------------------
/* extern */
window.ui = {
version : '<%= git.hash %>',
/* このサイトで使用するパズルのオブジェクト */
puzzle : null,
/* どの種類のパズルのメニューを表示しているか */
currentpid : '',
customAttr : function(el, name){
var value = "";
if(el.dataset!==void 0){ value = el.dataset[name];}
/* IE10, Firefox5, Chrome7, Safari5.1以下のフォールバック */
else{
var lowername = "data-";
for(var i=0;i<name.length;i++){
var ch = name[i] || name.charAt(i);
lowername += ((ch>="A" && ch<="Z") ? ("-" + ch.toLowerCase()) : ch);
}
value = el[lowername] || el.getAttribute(lowername) || "";
}
return value;
}
};
Output:
// UI.js v3.4.0
/* eslint-env browser */
/* exported ui, _doc, getEL, createEL */
/* ui.js Locals */
var _doc = document;
function getEL(id) {
return _doc.getElementById(id);
}
function createEL(tagName) {
return _doc.createElement(tagName);
}
//---------------------------------------------------------------------------
// ★uiオブジェクト UserInterface側のオブジェクト
//---------------------------------------------------------------------------
/* extern */
window.ui = {
version: "<%= git.hash %>",
/* このサイトで使用するパズルのオブジェクト */
puzzle: null,
/* どの種類のパズルのメニューを表示しているか */
currentpid: "",
customAttr: function(el, name) {
var value = "";
if (el.dataset !== void 0) {
value = el.dataset[name];
} else {
/* IE10, Firefox5, Chrome7, Safari5.1以下のフォールバック */
var lowername = "data-";
for (var i = 0; i < name.length; i++) {
var ch = name[i] || name.charAt(i);
lowername += ch >= "A" && ch <= "Z" ? "-" + ch.toLowerCase() : ch;
}
value = el[lowername] || el.getAttribute(lowername) || "";
}
return value;
}
};
Iterated Output: (comment after else indented further)
// UI.js v3.4.0
/* eslint-env browser */
/* exported ui, _doc, getEL, createEL */
/* ui.js Locals */
var _doc = document;
function getEL(id) {
return _doc.getElementById(id);
}
function createEL(tagName) {
return _doc.createElement(tagName);
}
//---------------------------------------------------------------------------
// ★uiオブジェクト UserInterface側のオブジェクト
//---------------------------------------------------------------------------
/* extern */
window.ui = {
version: "<%= git.hash %>",
/* このサイトで使用するパズルのオブジェクト */
puzzle: null,
/* どの種類のパズルのメニューを表示しているか */
currentpid: "",
customAttr: function(el, name) {
var value = "";
if (el.dataset !== void 0) {
value = el.dataset[name];
} else {
/* IE10, Firefox5, Chrome7, Safari5.1以下のフォールバック */
var lowername = "data-";
for (var i = 0; i < name.length; i++) {
var ch = name[i] || name.charAt(i);
lowername += ch >= "A" && ch <= "Z" ? "-" + ch.toLowerCase() : ch;
}
value = el[lowername] || el.getAttribute(lowername) || "";
}
return value;
}
};
Expected behavior: Probably get the second output directly.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Shouldn't change the indentation of comments #16 - GitHub
There's a workaround if your parser doesn't support comments the way you want: transform the comments into strings with a unique random prefix, ......
Read more >CLion inconsistent auto indentation for line comment
It seems like whenever I use = to initialize an variable, and then add comment at the end of the line, it will...
Read more >clang-format doesn't indent comments in front of an #ifdef
The comment belongs to the #if[def] usually but it's indented according to the local scope. Anything else would be just wrong and so...
Read more >List Indentation Very Unstable - Unpredictable Changes - Evernote ...
Hi, I primarily use Evernote for managing schedules and thus use the list formatting a lot for to-do-lists and similar types. Since the...
Read more >Preserve indentation of comments not working (since VS 2015)
Inside C++ code, Visual try to indent unrelated comments (~with an empty line in between) even if the option "Preserve indentation of comments"...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sosukesuzuki You link broken, playground
a minimal example to reproduce: Playground Input:
Output:
Second Output:
Expected(Same as Input):