Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
Fix bug that would de-indent if a comment was at end of if statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Aug 31, 2019
1 parent e7aee25 commit c859772
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
},
"homepage": "https://github.com/RokuCommunity/brightscript-formatter#readme",
"dependencies": {
"@types/fs-extra": "^7.0.0",
"brightscript-parser": "1.2.0",
"child-process-promise": "^2.2.1",
"fs-extra": "^8.0.1",
"fs-extra": "^8.1.0",
"glob-promise": "^3.4.0",
"trim-right": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/chai": "^4.2.0",
"@types/fs-extra": "^7.0.0",
"@types/mocha": "^5.2.5",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/BrightScriptFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ describe('BrightScriptFormatter', () => {
});

describe('indentStyle', () => {
it('does not fail with comments next to if statement', () => {
let program = `sub a()\n if true then 'comment\n return true\n end if\nend sub`;
expect(formatter.format(program)).to.equal(program);
});
it('does not change correctly formatted programs', () => {
let program = `sub add(a, b)\n return a + b\nend sub`;
expect(formatter.format(program)).to.equal(program);
Expand Down
4 changes: 4 additions & 0 deletions src/BrightScriptFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ export class BrightScriptFormatter {
if (thenIndex === -1) {
return false;
}
//if there's a comment at the end, this is a multi-line if statement
if (this.tokenIndexOf(TokenType.remComment, lineTokens) > -1 || this.tokenIndexOf(TokenType.quoteComment, lineTokens) > -1) {
return false;
}

//see if there is anything after the "then". If so, assume it's a one-line if statement
for (let i = thenIndex + 1; i < lineTokens.length; i++) {
Expand Down

0 comments on commit c859772

Please sign in to comment.