Skip to content

Commit

Permalink
feat(tsfmt): don't use default export in our code
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 22, 2017
1 parent 1520cf8 commit 6d04913
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LanguageServiceHost implements ts.LanguageServiceHost {
getDefaultLibFileName = (_options: ts.CompilerOptions) => "lib";
}

export default function format(fileName: string, text: string, options = createDefaultFormatCodeSettings()) {
export function format(fileName: string, text: string, options = createDefaultFormatCodeSettings()) {
const host = new LanguageServiceHost();
host.addFile(fileName, text);

Expand Down
28 changes: 14 additions & 14 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as ts from "typescript";
import formatter from "./formatter";
import { format } from "./formatter";
import { createDefaultFormatCodeSettings, parseJSON } from "./utils";

export { parseJSON };

import * as fs from "fs";
import * as path from "path";

import base from "./provider/base";
import tsconfigjson from "./provider/tsconfigjson";
import editorconfig, { postProcess as editorconfigPostProcess } from "./provider/editorconfig";
import tslintjson, { postProcess as tslintPostProcess } from "./provider/tslintjson";
import vscodesettings from "./provider/vscodesettings";
import * as base from "./provider/base";
import * as tsconfigjson from "./provider/tsconfigjson";
import * as editorconfig from "./provider/editorconfig";
import * as tslintjson from "./provider/tslintjson";
import * as vscodesettings from "./provider/vscodesettings";

const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json")).toString());
export const version = packageJson.version;
Expand Down Expand Up @@ -144,21 +144,21 @@ export function processString(fileName: string, content: string, opts: Options):

let processor = new Processor();
if (opts.tsfmt) {
processor.addOptionModify(base);
processor.addOptionModify(base.makeFormatCodeOptions);
}
if (opts.tsconfig) {
processor.addOptionModify(tsconfigjson);
processor.addOptionModify(tsconfigjson.makeFormatCodeOptions);
}
if (opts.editorconfig) {
processor.addOptionModify(editorconfig);
processor.addPostProcess(editorconfigPostProcess);
processor.addOptionModify(editorconfig.makeFormatCodeOptions);
processor.addPostProcess(editorconfig.postProcess);
}
if (opts.tslint) {
processor.addOptionModify(tslintjson);
processor.addPostProcess(tslintPostProcess);
processor.addOptionModify(tslintjson.makeFormatCodeOptions);
processor.addPostProcess(tslintjson.postProcess);
}
if (opts.vscode) {
processor.addOptionModify(vscodesettings);
processor.addOptionModify(vscodesettings.makeFormatCodeOptions);
}
processor.addPostProcess((_fileName: string, formattedCode: string, _opts: Options, formatSettings: ts.FormatCodeSettings) => {
// replace newline code. maybe NewLineCharacter params affect to only "new" newline by language service.
Expand All @@ -169,7 +169,7 @@ export function processString(fileName: string, content: string, opts: Options):
let formatSettings = createDefaultFormatCodeSettings();
return processor.processFormatCodeOptions(fileName, opts, formatSettings)
.then(formatSettings => {
let formattedCode = formatter(fileName, content, formatSettings);
let formattedCode = format(fileName, content, formatSettings);

// apply post process logic
return processor.postProcess(fileName, formattedCode, opts, formatSettings);
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface TsfmtSettings {
convertTabsToSpaces?: boolean;
}

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName: string | null;
if (opts.tsfmtFile && path.isAbsolute(opts.tsfmtFile)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/editorconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Options } from "../";

let emitBaseDirWarning = false;

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): Promise<ts.FormatCodeSettings> {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): Promise<ts.FormatCodeSettings> {

if (opts.verbose && opts.baseDir && !emitBaseDirWarning) {
console.log("editorconfig is not supported baseDir options");
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/tsconfigjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from "path";
import { Options } from "../";
import { getConfigFileName, readTsconfig } from "../utils";

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {

let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName: string | null;
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/tslintjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface AdditionalFormatSettings {
$noConsecutiveBlankLines: boolean;
}

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {

let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName: string | null;
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/vscodesettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface VSCodeSettings {
// insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces, insertSpaceAfterTypeAssertion, insertSpaceBeforeFunctionParenthesis
}

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {
export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings {

let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName));
let configFileName = getConfigFileName(baseDir, "./.vscode/settings.json");
Expand Down

0 comments on commit 6d04913

Please sign in to comment.