Skip to content

Commit

Permalink
fix(tsfmt): check rules.indent[1] is "tabs" fromt tslint fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed May 14, 2016
1 parent 539b71b commit 450c467
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/provider/tslintjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export default function makeFormatCodeOptions(fileName: string, opts: Options, f
if (!config.rules) {
return formatOptions;
}
if (config.rules.indent && config.rules.indent[0] && config.rules.indent[1] === "spaces") {
formatOptions.ConvertTabsToSpaces = true;
if (config.rules.indent && config.rules.indent[0]) {
if (config.rules.indent[1] === "spaces") {
formatOptions.ConvertTabsToSpaces = true;
} else if (config.rules.indent[1] === "tabs") {
formatOptions.ConvertTabsToSpaces = false;
}
}
if (config.rules.whitespace && config.rules.whitespace[0]) {
for (let p in config.rules.whitespace) {
Expand Down
17 changes: 17 additions & 0 deletions test/expected/tslint/indent-tabs/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"IndentSize": 4,
"TabSize": 4,
"IndentStyle": 2,
"NewLineCharacter": "\r\n",
"ConvertTabsToSpaces": false,
"InsertSpaceAfterCommaDelimiter": true,
"InsertSpaceAfterSemicolonInForStatements": true,
"InsertSpaceBeforeAndAfterBinaryOperators": true,
"InsertSpaceAfterKeywordsInControlFlowStatements": true,
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"PlaceOpenBraceOnNewLineForFunctions": false,
"PlaceOpenBraceOnNewLineForControlBlocks": false
}
6 changes: 6 additions & 0 deletions test/expected/tslint/indent-tabs/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Sample {
hello(word = "world") { return "Hello, " + word; }
}

var s = new Sample();
if (s === s) { console.log(s.hello()); }
6 changes: 6 additions & 0 deletions test/fixture/tslint/indent-tabs/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Sample {
hello(word="world"){return "Hello, " + word;}
}

var s=new Sample();
if(s===s){console.log(s.hello());}
5 changes: 5 additions & 0 deletions test/fixture/tslint/indent-tabs/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"indent": [true, "tabs"]
}
}

0 comments on commit 450c467

Please sign in to comment.