brighterscript-formatter
Advanced tools
Comparing version 1.1.1 to 1.1.3
@@ -9,2 +9,19 @@ # Changelog | ||
## [1.1.3] - 2020-05-01 | ||
### Fixed | ||
- Unwanted spacing between a negative sign and a number whenever preceeded by a comma (#8) | ||
- Remove whitespace preceeding a comma within a statement (#5) | ||
- Remove leading whitespace around `++` and `--` (#10) | ||
- bug when providing `nul` to keywordCaseOverride would case crash | ||
- Fix bug with titleCase not being properly handled. | ||
- Only indent once for left square bracket and left square curly brace on the same line (#6) | ||
## [1.1.2] - 2020-04-29 | ||
### Changed | ||
- upgraded to [brighterscript@0.8.2](https://github.com/rokucommunity/brighterscript/blob/master/CHANGELOG.md#082---2020-04-29) | ||
## [1.1.1] - 2020-04-27 | ||
@@ -47,2 +64,4 @@ ### Fixed | ||
[1.1.3]: https://github.com/RokuCommunity/brighterscript-formatter/compare/v1.1.2...v1.1.3 | ||
[1.1.2]: https://github.com/RokuCommunity/brighterscript-formatter/compare/v1.1.1...v1.1.2 | ||
[1.1.1]: https://github.com/RokuCommunity/brighterscript-formatter/compare/v1.1.0...v1.1.1 | ||
@@ -49,0 +68,0 @@ [1.1.0]: https://github.com/RokuCommunity/brighterscript-formatter/compare/v1.0.2...v1.1.0 |
@@ -217,4 +217,7 @@ "use strict"; | ||
} | ||
//if this is an indentor token, and is not being used as a key in an AA literal | ||
if (exports.IndentSpacerTokenKinds.includes(token.kind) && nextNonWhitespaceToken.kind !== brighterscript_1.TokenKind.Colon) { | ||
if ( | ||
//if this is an indentor token | ||
exports.IndentSpacerTokenKinds.includes(token.kind) && | ||
//is not being used as a key in an AA literal | ||
nextNonWhitespaceToken.kind !== brighterscript_1.TokenKind.Colon) { | ||
//skip indent for 'function'|'sub' used as type (preceeded by `as` keyword) | ||
@@ -228,2 +231,13 @@ if (exports.CallableKeywordTokenKinds.includes(token.kind) && | ||
foundIndentorThisLine = true; | ||
//don't double indent if square curly on same line | ||
if ( | ||
//if this is an open square | ||
token.kind === brighterscript_1.TokenKind.LeftSquareBracket && | ||
//the next token is an open curly | ||
nextNonWhitespaceToken.kind === brighterscript_1.TokenKind.LeftCurlyBrace && | ||
//both tokens are on the same line | ||
token.range.start.line === nextNonWhitespaceToken.range.start.line) { | ||
//skip the next token | ||
i++; | ||
} | ||
} | ||
@@ -241,2 +255,13 @@ else if ( | ||
} | ||
//don't double un-indent if this is a close curly and the next item is a close square | ||
if ( | ||
//is closing curly | ||
token.kind === brighterscript_1.TokenKind.RightCurlyBrace && | ||
//is closing square | ||
nextNonWhitespaceToken.kind === brighterscript_1.TokenKind.RightSquareBracket && | ||
//both tokens are on the same line | ||
token.range.start.line === nextNonWhitespaceToken.range.start.line) { | ||
//skip the next token | ||
i++; | ||
} | ||
//this is an interum token | ||
@@ -334,4 +359,7 @@ } | ||
var removeLeft = __spreadArrays(removeBoth, [ | ||
brighterscript_1.TokenKind.Comma, | ||
brighterscript_1.TokenKind.RightSquareBracket, | ||
brighterscript_1.TokenKind.RightParen | ||
brighterscript_1.TokenKind.RightParen, | ||
brighterscript_1.TokenKind.PlusPlus, | ||
brighterscript_1.TokenKind.MinusMinus | ||
]); | ||
@@ -608,5 +636,16 @@ var removeRight = __spreadArrays(removeBoth, [ | ||
for (var key in fullOptions.keywordCaseOverride) { | ||
keywordCaseOverride[key.toLowerCase()] = fullOptions.keywordCaseOverride[key].toLowerCase(); | ||
var value = fullOptions.keywordCaseOverride[key] | ||
? fullOptions.keywordCaseOverride[key].toLowerCase() | ||
: 'original'; | ||
keywordCaseOverride[key.toLowerCase()] = value; | ||
} | ||
fullOptions.keywordCaseOverride = keywordCaseOverride; | ||
var typeCaseOverride = {}; | ||
for (var key in fullOptions.typeCaseOverride) { | ||
var value = fullOptions.typeCaseOverride[key] | ||
? fullOptions.typeCaseOverride[key].toLowerCase() | ||
: 'original'; | ||
typeCaseOverride[key.toLowerCase()] = value; | ||
} | ||
fullOptions.typeCaseOverride = typeCaseOverride; | ||
return fullOptions; | ||
@@ -809,4 +848,5 @@ }; | ||
brighterscript_1.TokenKind.Colon, | ||
brighterscript_1.TokenKind.Semicolon | ||
brighterscript_1.TokenKind.Semicolon, | ||
brighterscript_1.TokenKind.Comma | ||
]; | ||
exports.CompositeKeywordStartingWords = ['end', 'exit', 'else', '#end', '#else']; |
@@ -68,2 +68,8 @@ "use strict"; | ||
}); | ||
it('removes leading space around increment and decrement operators', function () { | ||
formatEqual("i ++", "i++"); | ||
formatEqual("i++", "i++"); | ||
formatEqual("i --", "i--"); | ||
formatEqual("i--", "i--"); | ||
}); | ||
it('correctly formats negative numbers compared to subtraction', function () { | ||
@@ -76,2 +82,3 @@ chai_1.expect(formatter.format("name=2-1")).to.equal("name = 2 - 1"); | ||
chai_1.expect(formatter.format("num = - 1")).to.equal("num = -1"); | ||
chai_1.expect(formatter.format("call(a, -1)")).to.equal("call(a, -1)"); | ||
chai_1.expect(formatter.format("for i=-1 to -1 step -1")).to.equal("for i = -1 to -1 step -1"); | ||
@@ -137,2 +144,5 @@ }); | ||
}); | ||
it('removes leading space when comma appears next to an item', function () { | ||
formatEqual("action(\"value\" ,\"otherValue\")", "action(\"value\", \"otherValue\")"); | ||
}); | ||
it('disabling the rule works', function () { | ||
@@ -224,2 +234,8 @@ chai_1.expect(formatter.format("a=1")).to.equal('a = 1'); | ||
}); | ||
it('does not double-indent curly square on same line', function () { | ||
formatEqual("theVar = [{\n name = \"bob\"\n}]"); | ||
}); | ||
it.skip('works for arrays with objects in them on separate lines', function () { | ||
formatEqual("theVar = [\n {\n name = bob\"\n }\n]"); | ||
}); | ||
}); | ||
@@ -466,2 +482,28 @@ describe('indentSpaceCount', function () { | ||
}); | ||
describe('normalizeOptions', function () { | ||
it('does not fail with falsey value for `keywordCaseOverride`', function () { | ||
var options = formatter.normalizeOptions({ | ||
keywordCaseOverride: { | ||
function: 'title', | ||
sub: null | ||
} | ||
}); | ||
chai_1.expect(options.keywordCaseOverride).to.eql({ | ||
function: 'title', | ||
sub: 'original' | ||
}); | ||
}); | ||
it('does not fail with falsey value for `keywordCaseOverride`', function () { | ||
var options = formatter.normalizeOptions({ | ||
typeCaseOverride: { | ||
function: 'title', | ||
sub: null | ||
} | ||
}); | ||
chai_1.expect(options.typeCaseOverride).to.eql({ | ||
function: 'title', | ||
sub: 'original' | ||
}); | ||
}); | ||
}); | ||
describe('break composite keywords', function () { | ||
@@ -468,0 +510,0 @@ function format(text, kind) { |
@@ -49,2 +49,8 @@ /** | ||
/** | ||
* Provides a way to override keyword case at the individual TokenType level | ||
*/ | ||
typeCaseOverride?: { | ||
[id: string]: FormattingOptions['keywordCase']; | ||
}; | ||
/** | ||
* If true (the default), all whitespace between items is reduced to exactly 1 space character, | ||
@@ -51,0 +57,0 @@ * and certain keywords and operators are padded with whitespace (i.e. `1+1` becomes `1 + 1`) |
{ | ||
"name": "brighterscript-formatter", | ||
"version": "1.1.1", | ||
"version": "1.1.3", | ||
"description": "A formatter for BrighterScript, a superset of Roku's BrightScript language, written in JavaScript", | ||
@@ -18,3 +18,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"brighterscript": "^0.7.1", | ||
"brighterscript": "^0.8.2", | ||
"trim-right": "^1.0.1" | ||
@@ -21,0 +21,0 @@ }, |
99038
1617
+ Addedbrighterscript@0.8.2(transitive)
+ Addedvscode-jsonrpc@8.2.0(transitive)
+ Addedvscode-languageserver@6.1.1(transitive)
+ Addedvscode-languageserver-protocol@3.17.5(transitive)
+ Addedvscode-languageserver-textdocument@1.0.12(transitive)
+ Addedvscode-languageserver-types@3.17.5(transitive)
+ Addedvscode-uri@2.1.2(transitive)
- Removedbrighterscript@0.7.2(transitive)
- Removedvscode-jsonrpc@4.0.0(transitive)
- Removedvscode-languageserver@5.2.1(transitive)
- Removedvscode-languageserver-protocol@3.14.1(transitive)
- Removedvscode-languageserver-types@3.14.0(transitive)
- Removedvscode-uri@1.0.8(transitive)
Updatedbrighterscript@^0.8.2