Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bsfmt "source/**/*.brs" "!**/roku_modules/*.*"
| noBsfmt |`boolean` | `false` | Don't read a bsfmt.json file |
| bsfmtPath |`string` | `undefined` | Use a specified path to bsfmt.json instead of the default |
||||
All boolean, string, and integer [`bsfmt.json`](#bsfmtjson-options) options are supported as well. Complex options such as `keywordCaseOverride` or `typeCaseOverride` are not currently supported via the CLI and should be provided in the `bsfmt.json` or through the node API. Feel free to [open an issue](https://github.com/rokucommunity/brighterscript-formatter/issues/new) if you would like to see support for these options via the CLI.
All boolean, string, and integer [`bsfmt.json`](#bsfmtjson-options) options are supported as well. Complex options such as `keywordCaseOverride`, `typeCaseOverride`, `specificKeywordCaseOverride`, or `specificTypeCaseOverride` are not currently supported via the CLI and should be provided in the `bsfmt.json` or through the node API. Feel free to [open an issue](https://github.com/rokucommunity/brighterscript-formatter/issues/new) if you would like to see support for these options via the CLI.



Expand All @@ -83,7 +83,9 @@ All boolean, string, and integer [`bsfmt.json`](#bsfmtjson-options) options are
|compositeKeywords| `"split", "combine", "original"`| `"split"` | Forces all composite keywords (i.e. `elseif`, `endwhile`, etc...) to be consistent. If `"split"`, they are split into their alternatives (`else if`, `end while`). If `"combine"`', they are combined (`elseif`, `endwhile`). If `"original"` or falsey, they are not modified. |
|removeTrailingWhiteSpace|`boolean`|`true`| Remove (or don't remove) trailing whitespace at the end of each line |
|[keywordCaseOverride](#keywordCaseOverride)| `object`| `undefined`| Provides a way to override keyword case at the individual TokenType level|
|[typeCaseOverride](#typeCaseOverride)|`object`|`undefined`| Provides a way to override type keyword case at the individual TokenType level.Types are defined as keywords that are preceded by an `as` token.|
|[typeCaseOverride](#typeCaseOverride)|`object`|`undefined`| Provides a way to override type keyword case at the individual TokenType level. Types are defined as keywords that are preceded by an `as` token.|
|[specificKeywordCaseOverride](#specificKeywordCaseOverride)| `object`| `undefined`| Provides a way to override keyword case with a specific string at the individual keyword level|
|[specificTypeCaseOverride](#specificTypeCaseOverride)|`object`|`undefined`| Provides a way to override type keyword case with a specific string at the individual keyword level. Types are defined as keywords that are preceded by an `as` token. This accepts specific casing strings rather than case options like "upper" or "lower".|
|formatInteriorWhitespace|`boolean`|`true`| All whitespace between items is reduced to exactly 1 space character and certain keywords and operators are padded with whitespace. This is a catchall property that will also disable the following rules: `insertSpaceBeforeFunctionParenthesis`, `insertSpaceBetweenEmptyCurlyBraces`, `insertSpaceAroundParameterAssignment`, `insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces`|
|insertSpaceBeforeFunctionParenthesis|`boolean`|`false`| If true, a space is inserted to the left of an opening function declaration parenthesis. (i.e. `function main ()` or `function ()`). If false, all spacing is removed (i.e. `function main()` or `function()`).|
|insertSpaceBetweenEmptyCurlyBraces|`boolean`|`false`| If true, empty curly braces will contain exactly 1 whitespace char (i.e. `{ }`). If false, there will be zero whitespace chars between empty curly braces (i.e. `{}`) |
Expand Down Expand Up @@ -128,6 +130,33 @@ For more flexibility in how to format the case of types, you can specify the cas

A type is any token found directly after an `as` keyword.

### specificKeywordCaseOverride
For more flexibility in how to format the case of keywords, you can specify the case value preference for each individual keyword. Here's an example:

```js
{
"specificKeywordCaseOverride": {
"longinteger": "longInteger",
"endif": "EndIF"
}
}
```

The full list of keywords detected by this option can be found [here](https://github.com/rokucommunity/brighterscript-formatter/blob/095f9dc5ec418d46d3ea6197712f5d11f71d922f/src/Formatter.ts#L1145).

### specificTypeCaseOverride
For more flexibility in how to format the case of types, you can specify the case value preference for each individual type. Here's an example:

```js
{
"specificTypeCaseOverride": {
"longinteger": "LongInteger"
}
}
```

A type is any token found directly after an `as` keyword.

## Library

### General usage
Expand Down
10 changes: 9 additions & 1 deletion bsfmt.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@
"default": true,
"description": "Removes all trailing whitespace at the end of each line."
},
"specificKeywordCaseOverride": {
"type": "object",
"description": "Allows overriding specific keywords at the individual keyword level.\nExample {\"longinteger\": \"LongInteger\"} would make longinteger LongInteger"
},
"specificTypeCaseOverride": {
"type": "object",
"description": "Allows overriding specific types at the individual type level.\nExample {\"longinteger\": \"longInteger\"} would make longinteger longInteger"
},
"keywordCaseOverride": {
"type": "object",
"description": "Allows overriding case at the individual keyword level.\nExample {\"string\": \"title\"} would make string always lower case regardless of keywordCase",
"description": "Allows overriding case at the individual keyword level.\nExample {\"string\": \"title\"} would make string always title case regardless of keywordCase",
"properties": {
"endfunction": {
"type": "string",
Expand Down
12 changes: 12 additions & 0 deletions src/FormattingOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export interface FormattingOptions {
* Types are defined as keywords that are preceded by an `as` token.
*/
typeCaseOverride?: Record<string, FormattingOptions['keywordCase']>;
/**
* Provides a way to override keyword case with a specific string.
* The key should be the lowercased keyword, and the value should be the desired casing.
* e.g. { "longinteger": "LongInteger" }
*/
specificKeywordCaseOverride?: Record<string, string>;
/**
* Provides a way to override type keyword case with a specific string.
* The key should be the lowercased keyword, and the value should be the desired casing.
* e.g. { "longinteger": "LongInteger" }
*/
specificTypeCaseOverride?: Record<string, string>;
/**
* If true (the default), all whitespace between items are reduced to exactly 1 space character,
* and certain keywords and operators are padded with whitespace (i.e. `1+1` becomes `1 + 1`).
Expand Down
Loading