Skip to content

Commit cbb561c

Browse files
committed
refactor(tsfmt): restructured for TypeScript 2.0.0
1 parent 376bf33 commit cbb561c

21 files changed

+224
-222
lines changed

.npmignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
.git/
22

3-
# for WebStorm
4-
.idea/
5-
63
# for npm
74
node_modules/
85
npm-shrinkwrap.json
96

107
# for grunt
11-
typings/
128
.tscache/
139

1410
# codes

.travis.yml

-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,5 @@ node_js:
33
- 4
44
sudo: false
55

6-
before_install:
7-
- npm install -g grunt-cli
8-
9-
before_script:
10-
- npm run setup
11-
126
notifications:
137
email: true

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"typescript.tsdk": "./node_modules/typescript/lib/"
4+
}

Gruntfile.js

+3-28
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@ module.exports = function (grunt) {
1111
}
1212
},
1313

14-
ts: {
15-
default: {
16-
tsconfig: {
17-
tsconfig: "./tsconfig.json",
18-
updateFiles:false
19-
}
20-
}
21-
},
22-
tsconfig: {
23-
main: {
24-
}
14+
exec: {
15+
tsc: "tsc -p ./"
2516
},
2617
tslint: {
2718
options: {
@@ -36,19 +27,7 @@ module.exports = function (grunt) {
3627
]
3728
}
3829
},
39-
dtsm: {
40-
main: {
41-
options: {
42-
config: "dtsm.json"
43-
}
44-
}
45-
},
4630
clean: {
47-
typings: {
48-
src: [
49-
"typings/"
50-
]
51-
},
5231
clientScript: {
5332
src: [
5433
// client
@@ -107,13 +86,9 @@ module.exports = function (grunt) {
10786
}
10887
});
10988

110-
grunt.registerTask(
111-
'setup',
112-
['clean:typings', 'dtsm']);
113-
11489
grunt.registerTask(
11590
'default',
116-
['clean:clientScript', 'tsconfig', 'ts', 'tslint']);
91+
['clean:clientScript', 'exec:tsc', 'tslint']);
11792

11893
grunt.registerTask(
11994
'test',

_tslint.json

+111-39
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,152 @@
11
{
22
"rules": {
3-
"ban": [true,
4-
["angular", "forEach"]
3+
"align": [
4+
false,
5+
"parameters",
6+
"arguments",
7+
"statements"
58
],
9+
"ban": false,
610
"class-name": true,
7-
"comment-format": [false,
8-
"check-space",
9-
"check-lowercase"
11+
"comment-format": [
12+
true,
13+
"check-space"
1014
],
1115
"curly": true,
12-
"eofline": false,
16+
"eofline": true,
1317
"forin": false,
14-
"indent": [true, 4],
15-
"interface-name": false,
16-
"jsdoc-format": true,
18+
"indent": [
19+
false,
20+
"spaces"
21+
],
22+
"interface-name": [
23+
true,
24+
"never-prefix"
25+
],
26+
"jsdoc-format": false,
1727
"label-position": true,
1828
"label-undefined": true,
19-
"max-line-length": [false, 140],
29+
"max-line-length": [
30+
false,
31+
140
32+
],
33+
"member-access": false,
34+
"member-ordering": [
35+
false,
36+
"public-before-private",
37+
"static-before-instance"
38+
],
39+
"new-parens": true,
40+
"no-angle-bracket-type-assertion": false,
2041
"no-any": false,
2142
"no-arg": true,
2243
"no-bitwise": true,
23-
"no-console": [false,
44+
"no-conditional-assignment": true,
45+
"no-consecutive-blank-lines": false,
46+
"no-console": [
47+
true,
2448
"debug",
2549
"info",
2650
"time",
2751
"timeEnd",
2852
"trace"
2953
],
30-
"no-consecutive-blank-lines": false,
3154
"no-construct": true,
3255
"no-constructor-vars": false,
33-
"no-debugger": false,
56+
"no-debugger": true,
3457
"no-duplicate-key": true,
3558
"no-duplicate-variable": true,
36-
"no-empty": true,
59+
"no-empty": false,
3760
"no-eval": true,
61+
"no-inferrable-types": false,
62+
"no-internal-module": true,
63+
"no-invalid-this": false,
64+
"no-mergeable-namespace": false,
65+
"no-namespace": [
66+
true,
67+
"allow-declarations"
68+
],
69+
"no-null-keyword": false,
70+
"no-reference": true,
71+
"no-require-imports": false,
72+
"no-shadowed-variable": false,
3873
"no-string-literal": false,
39-
"trailing-comma": [true, {
40-
"singleline": "never",
41-
"multiline": "always"
42-
}],
43-
"no-trailing-whitespace": true,
44-
"no-unreachable": true,
74+
"no-switch-case-fall-through": false,
75+
"no-trailing-whitespace": false,
76+
"no-unreachable": false,
4577
"no-unused-expression": false,
78+
"no-unused-new": false,
4679
"no-unused-variable": false,
4780
"no-use-before-declare": true,
81+
"no-var-keyword": true,
4882
"no-var-requires": false,
49-
"one-line": [true,
83+
"object-literal-sort-keys": false,
84+
"one-line": [
85+
true,
86+
"check-open-brace",
5087
"check-catch",
5188
"check-else",
52-
"check-open-brace",
89+
"check-finally",
5390
"check-whitespace"
5491
],
55-
"quotemark": [false, "double"],
56-
"radix": false,
57-
"semicolon": true,
58-
"triple-equals": [true, "allow-null-check"],
59-
"typedef": [false,
60-
"callSignature",
61-
"catchClause",
62-
"indexSignature",
92+
"quotemark": [
93+
true,
94+
"double",
95+
"avoid-escape"
96+
],
97+
"radix": true,
98+
"semicolon": [true, "always"],
99+
"switch-default": true,
100+
"trailing-comma": [
101+
true,
102+
{
103+
"multiline": "always",
104+
"singleline": "never"
105+
}
106+
],
107+
"triple-equals": [
108+
true,
109+
"allow-null-check"
110+
],
111+
"typedef": [
112+
false,
113+
"call-signature",
63114
"parameter",
64-
"propertySignature",
65-
"variableDeclarator"
115+
"property-declaration",
116+
"variable-declaration",
117+
"member-variable-declaration"
66118
],
67-
"typedef-whitespace": [false,
68-
["callSignature", "noSpace"],
69-
["catchClause", "noSpace"],
70-
["indexSignature", "space"]
119+
"typedef-whitespace": [
120+
false,
121+
{
122+
"call-signature": "nospace",
123+
"index-signature": "nospace",
124+
"parameter": "nospace",
125+
"property-declaration": "nospace",
126+
"variable-declaration": "nospace"
127+
},
128+
{
129+
"call-signature": "space",
130+
"index-signature": "space",
131+
"parameter": "space",
132+
"property-declaration": "space",
133+
"variable-declaration": "space"
134+
}
71135
],
72-
"use-strict": [true,
136+
"use-isnan": true,
137+
"use-strict": [
138+
false,
73139
"check-module",
74140
"check-function"
75141
],
76-
"variable-name": true,
77-
"whitespace": [false,
142+
"variable-name": [
143+
true,
144+
"check-format",
145+
"allow-leading-underscore",
146+
"ban-keywords"
147+
],
148+
"whitespace": [
149+
true,
78150
"check-branch",
79151
"check-decl",
80152
"check-operator",

dtsm.json

-29
This file was deleted.

lib/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as path from "path";
1818
import * as expand from "glob-expand";
1919

2020
import * as lib from "./";
21-
import {getConfigFileName} from "./utils";
21+
import { getConfigFileName } from "./utils";
2222

2323
let packageJson = JSON.parse(fs.readFileSync(__dirname + "/../package.json").toString());
2424

@@ -53,7 +53,7 @@ let root = commandpost
5353
.action((opts, args) => {
5454
let replace = !!opts.replace;
5555
let verify = !!opts.verify;
56-
let baseDir = opts.baseDir ? opts.baseDir[0] : null;
56+
let baseDir = opts.baseDir ? opts.baseDir[0] : void 0;
5757
let stdin = !!opts.stdin;
5858
let tsconfig = !!opts.tsconfig;
5959
let tslint = !!opts.tslint;
@@ -75,7 +75,7 @@ let root = commandpost
7575
}
7676

7777
if (files.length === 0 && !opts.stdin) {
78-
process.stdout.write(root.helpText() + '\n');
78+
process.stdout.write(root.helpText() + "\n");
7979
return;
8080
}
8181

@@ -154,7 +154,7 @@ function showResultHandler(resultMap: lib.ResultMap): Promise<any> {
154154
}
155155
});
156156
}
157-
return null;
157+
return Promise.resolve(null);
158158
}
159159

160160
function errorHandler(err: any): Promise<any> {

lib/formatter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import * as ts from "typescript";
4-
import {createDefaultFormatCodeOptions} from "./utils";
4+
import { createDefaultFormatCodeOptions } from "./utils";
55

66
// from https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#pretty-printer-using-the-ls-formatter
77

lib/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import * as ts from "typescript";
44
import formatter from "./formatter";
5-
import {createDefaultFormatCodeOptions} from "./utils";
5+
import { createDefaultFormatCodeOptions } from "./utils";
66

77
import * as fs from "fs";
88

99
import base from "./provider/base";
1010
import tsconfigjson from "./provider/tsconfigjson";
1111
import editorconfig from "./provider/editorconfig";
12-
import tslintjson, {postProcess as tslintPostProcess} from "./provider/tslintjson";
12+
import tslintjson, { postProcess as tslintPostProcess } from "./provider/tslintjson";
1313

1414
export interface Options {
1515
dryRun?: boolean;
@@ -33,7 +33,7 @@ export interface ResultMap {
3333

3434
export interface Result {
3535
fileName: string;
36-
options: ts.FormatCodeOptions;
36+
options: ts.FormatCodeOptions | null;
3737
message: string;
3838
error: boolean;
3939
src: string;
@@ -73,7 +73,7 @@ export function processStream(fileName: string, input: NodeJS.ReadableStream, op
7373

7474
input.setEncoding("utf8");
7575

76-
let promise = new Promise<string>((resolve, reject) => {
76+
let promise = new Promise<string>((resolve, _reject) => {
7777
let fragment = "";
7878
input.on("data", (chunk: string) => {
7979
fragment += chunk;
@@ -122,7 +122,7 @@ export function processString(fileName: string, content: string, opts: Options):
122122
// replace newline code. maybe NewLineCharacter params affect to only "new" newline by language service.
123123
formattedCode = formattedCode.replace(/\r?\n/g, formatOptions.NewLineCharacter);
124124

125-
let message: string;
125+
let message = "";
126126
let error = false;
127127
if (opts && opts.verify) {
128128
if (content !== formattedCode) {

0 commit comments

Comments
 (0)