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

Commit

Permalink
Fix indent style default (#6)
Browse files Browse the repository at this point in the history
Attempting to resolve bug with indent style (#5).
Added automatic npm publishing from travis-ci.
  • Loading branch information
TwitchBronBron committed Mar 14, 2018
1 parent 9328ae2 commit 44968a5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
language: node_js
node_js:
- "node"
after_success: npm run coverage
after_success: npm run coverage
deploy:
provider: npm
email: "bronley@gmail.com"
api_key: $NPM_TOKEN
skip_cleanup: true
on:
branch: master
tags: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A code formatter for Roku's BrightScript language

[![Build Status](https://travis-ci.org/TwitchBronBron/brightscript-formatter.svg?branch=master)](https://travis-ci.org/TwitchBronBron/brightscript-formatter)
[![Coverage Status](https://coveralls.io/repos/github/TwitchBronBron/brightscript-formatter/badge.svg?branch=master)](https://coveralls.io/github/TwitchBronBron/brightscript-formatter?branch=master)
![npm](https://img.shields.io/npm/v/brightscript-formatter.svg)

## Usage
```javascript
Expand Down
3 changes: 3 additions & 0 deletions dist/BrightScriptFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ var BrightScriptFormatter = /** @class */ (function () {
fullOptions[attrname] = options[attrname];
}
}
if (!fullOptions.indentStyle) {
fullOptions.indentStyle = 'spaces';
}
return fullOptions;
};
BrightScriptFormatter.prototype.isSingleLineIfStatement = function (lineTokens, allTokens) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"compile": "rimraf dist && tsc",
"prepublishOnly": "npm run compile",
"test": "nyc mocha src/**/*.spec.ts --compilers ts-node/register --require source-map-support/register --full-trace --bail",
"test": "nyc mocha src/**/*.spec.ts --full-trace --bail",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"nyc": {
Expand All @@ -18,7 +18,8 @@
".ts"
],
"require": [
"ts-node/register"
"ts-node/register",
"source-map-support/register"
],
"reporter": [
"text-summary",
Expand All @@ -43,7 +44,7 @@
},
"homepage": "https://github.com/TwitchBronBron/brightscript-formatter#readme",
"dependencies": {
"brightscript-parser": "^1.0.1"
"brightscript-parser": "^1.0.3-1"
},
"devDependencies": {
"@types/chai": "^4.1.2",
Expand All @@ -58,4 +59,4 @@
"tslint": "^5.9.1",
"typescript": "^2.7.2"
}
}
}
14 changes: 12 additions & 2 deletions src/BrightScriptFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('BrightScriptFormatter', () => {
expect(formatter.format(program)).to.equal(program);
});

it('works when specified as undefined', () => {
let program = `sub add(a,b)\n return a+b\nend sub`;
it('skips indentation when indentStyle:undefined', () => {
let program = ` sub add(a,b)\nreturn a+b\n end sub`;
expect(formatter.format(program, { indentStyle: undefined })).to.equal(program);
});

Expand Down Expand Up @@ -132,10 +132,12 @@ describe('BrightScriptFormatter', () => {
program = `lineups_index["audio"] = CreateObject("roAssociativeArray")\nlineups_index["video"] = CreateObject("roAssociativeArray")\nci = 0`;
expect(formatter.format(program)).to.equal(program);
});

it('handles single-line if-then statements', () => {
let program = `sub test()\n if true then break\nend sub`;
expect(formatter.format(program)).to.equal(program);
});

it('handles single-line if-then-else statements', () => {
let program = `sub test()\n if true then break else break\nend sub`;
expect(formatter.format(program)).to.equal(program);
Expand All @@ -145,6 +147,14 @@ describe('BrightScriptFormatter', () => {
let program = `sub test()\n if true then\n doSomething()\n end if\nend if\nend sub\nsub test2()\n doSomething()\nend sub`;
expect(formatter.format(program)).to.equal(program);
});

it('it works with identifiers that start with rem', () => {
expect(formatter.format(
` if (removeFoo <> invalid) then\n lineups["video"].push(invalid)`
)).to.equal(
`if (removeFoo <> invalid) then\n lineups["video"].push(invalid)`
);
});
});

describe('keywordCase', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/BrightScriptFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export interface FormattingOptions {
/**
* The type of indentation to use when indenting the beginning of lines.
*/
indentStyle?: 'tabs' | 'spaces' | null;
indentStyle?: 'tabs' | 'spaces' | 'existing';
/**
* The number of spaces to use when indentStyle is 'spaces'. Default is 4
*/
Expand Down

0 comments on commit 44968a5

Please sign in to comment.