Skip to content

[WIP] Fix trailing newline and JSX formatting #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
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
8 changes: 4 additions & 4 deletions dtsm.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
},
"dependencies": {
"node/node.d.ts": {
"ref": "6f04d25ad38982d372cc3cda62fa4c0eef9e24d7"
"ref": "7c27233ae47768442b9b0a40d7f03fadf593fad2"
},
"es6-promise/es6-promise.d.ts": {
"ref": "6f04d25ad38982d372cc3cda62fa4c0eef9e24d7"
"ref": "7c27233ae47768442b9b0a40d7f03fadf593fad2"
},
"mocha/mocha.d.ts": {
"ref": "6f04d25ad38982d372cc3cda62fa4c0eef9e24d7"
"ref": "7c27233ae47768442b9b0a40d7f03fadf593fad2"
},
"power-assert/power-assert.d.ts": {
"ref": "6f04d25ad38982d372cc3cda62fa4c0eef9e24d7"
"ref": "7c27233ae47768442b9b0a40d7f03fadf593fad2"
}
}
}
4 changes: 2 additions & 2 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ function showResultHandler(resultMap: lib.ResultMap): Promise<any> {
Object.keys(resultMap)
.map(fileName => resultMap[fileName])
.filter(result => result.error)
.forEach(result => console.error(result.message));
.forEach(result => process.stderr.write(result.message));
process.exit(1);
} else {
Object.keys(resultMap)
.map(fileName => resultMap[fileName])
.forEach(result => {
if (result.message) {
console.log(result.message);
process.stdout.write(result.message.replace(/^\s+$/mg, "").replace(/\n\n^$/mg, ""));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import utils = require("./utils");

// Note: this uses ts.formatting which is part of the typescript 1.4 package but is not currently
// exposed in the public typescript.d.ts. The typings should be exposed in the next release.
function format(text: string, options = utils.createDefaultFormatCodeOptions()) {
function format(fileName: string, text: string, options = utils.createDefaultFormatCodeOptions()) {
"use strict";

// Parse the source text
var sourceFile = ts.createSourceFile("file.ts", text, ts.ScriptTarget.Latest, (<any>/* backward compat for typescript-1.4.1 */"0"));
var sourceFile = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, (<any>/* backward compat for typescript-1.4.1 */"0"));
fixupParentReferences(sourceFile);

// Get the formatting edits on the input sources
Expand Down
12 changes: 6 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../node_modules/typescript/bin/typescript.d.ts" />
/// <reference path="../node_modules/typescript/bin/lib.es6.d.ts" />
/// <reference path="../node_modules/typescript/lib/typescript.d.ts" />
/// <reference path="../node_modules/typescript/lib/lib.es6.d.ts" />

"use strict";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function processFiles(files: string[], opts: Options): Promise<ResultMap>
var result: Result = {
fileName: fileName,
options: null,
message: `${fileName} is not exists. process abort.`,
message: `${fileName} is not exists. process abort.\n`,
error: true,
src: "",
dest: ""
Expand Down Expand Up @@ -101,7 +101,7 @@ export function processString(fileName: string, content: string, opts: Options):
return Promise
.all(optGenPromises)
.then(() => {
var formattedCode = formatter(content, options);
var formattedCode = formatter(fileName, content, options);
if ((<any>formattedCode).trimRight) {
formattedCode = (<any>formattedCode).trimRight();
formattedCode += "\n";
Expand All @@ -112,13 +112,13 @@ export function processString(fileName: string, content: string, opts: Options):
var error = false;
if (opts && opts.verify) {
if (content !== formattedCode) {
message = `${fileName} is not formatted`;
message = `${fileName} is not formatted\n`;
error = true;
}
} else if (opts && opts.replace) {
if (content !== formattedCode) {
fs.writeFileSync(fileName, formattedCode);
message = `replaced ${fileName}`;
message = `replaced ${fileName}\n`;
}
} else if (opts && !opts.dryRun) {
message = formattedCode;
Expand Down
7 changes: 0 additions & 7 deletions lib/provider/tslintjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function getConfigFileName(baseFileName: string, configFileName: string): string

interface TslintSettings {
rules: {
indent: {
0: boolean;
1: number;
};
whitespace: {
0: boolean;
1: string;
Expand All @@ -53,9 +49,6 @@ export function makeFormatCodeOptions(fileName: string, options: ts.FormatCodeOp
if (!config.rules) {
return options;
}
if (config.rules.indent && config.rules.indent[0]) {
options.IndentSize = config.rules.indent[1];
}
if (config.rules.whitespace && config.rules.whitespace[0]) {
for (var p in config.rules.whitespace) {
var value = config.rules.whitespace[p];
Expand Down
1 change: 1 addition & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function createDefaultFormatCodeOptions(): ts.FormatCodeOptions {
InsertSpaceAfterKeywordsInControlFlowStatements: true,
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
PlaceOpenBraceOnNewLineForFunctions: false,
PlaceOpenBraceOnNewLineForControlBlocks: false
};
Expand Down
Loading