Bug 527490 - Eclipse JSP Formatter using tabs instead of spaces in JSP Scriptlet tags when <script> tags are present
Summary: Eclipse JSP Formatter using tabs instead of spaces in JSP Scriptlet tags when...
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Victor Rubezhny CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-20 08:54 EST by Joey Mauck CLA
Modified: 2019-11-02 09:19 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joey Mauck CLA 2017-11-20 08:54:06 EST
I want to format my JSP page. I am using the JSP Editor.

My Eclipse Settings are the following: 
General > Editors > Text Editors:
Displayed tab width: 4
Insert spaces for tabs is selected

Java > Code Style > Formatter : Click Edit > Indentation > General settings:
Tab policy: Spaces Only
Indentation size: 4
Tab size: 4

JavaScript > Code Style > Formatter : Click Edit > Indentation > General settings:
Tab policy: Spaces Only
Indentation size: 4
Tab size: 4

Web > CSS Files > Editor:
Indent using spaces is selected
Indentation size: 4

Web > HTML Files > Editor:
Indent using spaces is selected
Indentation size: 4

Web > JSP Files > Editor:
Format JSP XML documents as HTML is selected

XML > XML Files > Editor:
Indent using spaces is selected
Indentation size: 4

How to reproduce this bug:
1. Open a new JSP file
2. Replace the contents of the JSP with the following HTML:

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%
StringBuilder test = new StringBuilder("This line does not have tabs on it!\n");
test.append("This line will have tabs on it.\n");
test.append("This line will too!\n");
%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<script type="text/javascript">
function () {
    alert('');
}
</script>
</head>
<body>
<%=test%>
</body>
</html>

(Take note of the message appended in the StringBuilder test object)
3. CTRL + SHIFT + F (Format the page, below is a result of the format)

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%
    StringBuilder test = new StringBuilder("This line does not have tabs on it!\n");
				test.append("This line will have tabs on it.\n");
				test.append("This line will too!\n");
%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<script type="text/javascript">
function () {
    alert('');
}
</script>
</head>
<body>
    <%=test%>
</body>
</html>

3.5 You can notice that there is unwanted space in the lines with test.append, that unwanted space happens to be tab characters.

After some more investigation, I found the issue might be with the <script> tags in the html, so when I commented out the <script> tags, you can see the following happened:

1. Open a new JSP file
2. Replace the contents of the JSP with the following HTML:

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%
StringBuilder test = new StringBuilder("This line does not have tabs on it!\n");
test.append("This line will NOT have tabs on it.\n");
test.append("This line will NOT have tabs on it too!\n");
%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<!-- <script type="text/javascript">
function () {
    alert('');
}
</script> -->
</head>
<body>
<%=test%>
</body>
</html>

(Take note of the message appended in the StringBuilder test object)
3. CTRL + SHIFT + F (Format the page, below is a result of the format)

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%
    StringBuilder test = new StringBuilder("This line does not have tabs on it!\n");
    test.append("This line will NOT have tabs on it.\n");
    test.append("This line will NOT have tabs on it too!\n");
%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<!-- <script type="text/javascript">
function () {
    alert('');
}
</script> -->
</head>
<body>
    <%=test%>
</body>
</html>

You can see that there are no tabs anymore, but unfortunately, I am not in a position where I can remove <script> tags and/or JSP Scriptlet tags. If there is a setting that fixes this issue, then let me know, otherwise I believe this is a bug.