Skip to content

Commit 112a49a

Browse files
cirrasfourls
authored andcommitted
Detect tab-indented multiline strings in TabulationCharacter
1 parent 82d0ad1 commit 112a49a

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- Detect tab-indented multiline strings in `TabulationCharacter`.
1213
- Improve support for evaluating name references in compiler directive expressions.
1314

1415
### Fixed

delphi-checks/src/main/java/au/com/integradev/delphi/checks/TabulationCharacterCheck.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.sonar.plugins.communitydelphi.api.check.DelphiCheck;
2626
import org.sonar.plugins.communitydelphi.api.check.DelphiCheckContext;
2727
import org.sonar.plugins.communitydelphi.api.token.DelphiToken;
28+
import org.sonar.plugins.communitydelphi.api.token.DelphiTokenType;
2829
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2930

3031
@DeprecatedRuleKey(ruleKey = "TabulationCharactersRule", repositoryKey = "delph")
@@ -54,5 +55,21 @@ public void visitToken(DelphiToken token, DelphiCheckContext context) {
5455
if (token.isWhitespace()) {
5556
tabCount += countMatches(token.getImage(), '\t');
5657
}
58+
59+
if (token.getType() == DelphiTokenType.MULTILINE_STRING) {
60+
String lastLine = context.getFileLines().get(token.getEndLine() - 1);
61+
int tabs = 0;
62+
63+
for (int i = 0; i < lastLine.length(); ++i) {
64+
char c = lastLine.charAt(i);
65+
if (c == '\t') {
66+
++tabs;
67+
} else if (c == '\'') {
68+
break;
69+
}
70+
}
71+
72+
tabCount += tabs * (token.getEndLine() - token.getBeginLine());
73+
}
5774
}
5875
}

delphi-checks/src/test/java/au/com/integradev/delphi/checks/TabulationCharacterCheckTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,17 @@ void testFileWithMultipleTabsShouldAddIssue() {
5252
.appendDecl("\t"))
5353
.verifyIssueOnFile();
5454
}
55+
56+
@Test
57+
void testFileWithTabsInMultilineStringIndentationShouldAddIssue() {
58+
CheckVerifier.newVerifier()
59+
.withCheck(new TabulationCharacterCheck())
60+
.onFile(
61+
new DelphiTestUnitBuilder()
62+
.appendDecl("const")
63+
.appendDecl(" Foo = '''")
64+
.appendDecl("\t\tBar")
65+
.appendDecl("\t\t''';"))
66+
.verifyIssueOnFile();
67+
}
5568
}

0 commit comments

Comments
 (0)