-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tsfmt): support newline char settings from tsconfig.json
- Loading branch information
Showing
14 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict"; | ||
|
||
import * as ts from "typescript"; | ||
|
||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
|
||
import {Options} from "../"; | ||
import {getConfigFileName} from "../utils"; | ||
|
||
interface TsconfigSettings { | ||
compilerOptions: { | ||
newLine: string; | ||
}; | ||
} | ||
|
||
export default function makeFormatCodeOptions(fileName: string, opts: Options, formatOptions: ts.FormatCodeOptions): ts.FormatCodeOptions { | ||
"use strict"; | ||
|
||
let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName)); | ||
let configFileName = getConfigFileName(baseDir, "tsconfig.json"); | ||
if (!configFileName) { | ||
return formatOptions; | ||
} | ||
if (opts.verbose) { | ||
console.log(`read ${configFileName} for ${fileName}`); | ||
} | ||
|
||
let config: TsconfigSettings = JSON.parse(<any>fs.readFileSync(configFileName, "utf-8")); | ||
if (!config.compilerOptions || !config.compilerOptions.newLine) { | ||
return formatOptions; | ||
} | ||
|
||
if (config.compilerOptions.newLine.toLowerCase() === "crlf") { | ||
formatOptions.NewLineCharacter = "\r\n"; | ||
} else if (config.compilerOptions.newLine.toLowerCase() === "lf") { | ||
formatOptions.NewLineCharacter = "\n"; | ||
} | ||
|
||
return formatOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class TestCLI { | ||
method() { | ||
|
||
} | ||
} | ||
class TestCLI { | ||
method() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"IndentSize": 4, | ||
"TabSize": 4, | ||
"NewLineCharacter": "\r\n", | ||
"ConvertTabsToSpaces": true, | ||
"InsertSpaceAfterCommaDelimiter": true, | ||
"InsertSpaceAfterSemicolonInForStatements": true, | ||
"InsertSpaceBeforeAndAfterBinaryOperators": true, | ||
"InsertSpaceAfterKeywordsInControlFlowStatements": true, | ||
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false, | ||
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, | ||
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, | ||
"PlaceOpenBraceOnNewLineForFunctions": false, | ||
"PlaceOpenBraceOnNewLineForControlBlocks": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Sample { | ||
hello(word: string = "world"): string { return "Hello, " + word; } | ||
} | ||
|
||
var s: Sample = new Sample(); | ||
if (s === s) { console.log(s.hello()); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"IndentSize": 4, | ||
"TabSize": 4, | ||
"NewLineCharacter": "\n", | ||
"ConvertTabsToSpaces": true, | ||
"InsertSpaceAfterCommaDelimiter": true, | ||
"InsertSpaceAfterSemicolonInForStatements": true, | ||
"InsertSpaceBeforeAndAfterBinaryOperators": true, | ||
"InsertSpaceAfterKeywordsInControlFlowStatements": true, | ||
"InsertSpaceAfterFunctionKeywordForAnonymousFunctions": false, | ||
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, | ||
"InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, | ||
"PlaceOpenBraceOnNewLineForFunctions": false, | ||
"PlaceOpenBraceOnNewLineForControlBlocks": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Sample { | ||
hello(word: string = "world"): string { return "Hello, " + word; } | ||
} | ||
|
||
var s: Sample = new Sample(); | ||
if (s === s) { console.log(s.hello()); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Sample { | ||
hello(word:string="world"):string{return "Hello, " + word;} | ||
} | ||
|
||
var s:Sample=new Sample(); | ||
if(s===s){console.log(s.hello());} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"newLine": "CRLF" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Sample { | ||
hello(word:string="world"):string{return "Hello, " + word;} | ||
} | ||
|
||
var s:Sample=new Sample(); | ||
if(s===s){console.log(s.hello());} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"newLine": "LF" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters