File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " prettier-eslint" ,
3
3
"version" : " 0.0.0-development" ,
4
- "description" :
5
- " Formats your JavaScript using prettier followed by eslint --fix" ,
4
+ "description" : " Formats your JavaScript using prettier followed by eslint --fix" ,
6
5
"main" : " dist/index.js" ,
7
6
"scripts" : {
8
7
"start" : " nps" ,
9
8
"test" : " nps test" ,
10
9
"precommit" : " opt --in pre-commit --exec \" npm start validate\" "
11
10
},
12
- "files" : [" dist" ],
11
+ "files" : [
12
+ " dist"
13
+ ],
13
14
"keywords" : [],
14
15
"author" : " Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)" ,
15
16
"license" : " MIT" ,
22
23
"loglevel-colored-level-prefix" : " ^1.0.0" ,
23
24
"prettier" : " ^1.6.0" ,
24
25
"pretty-format" : " ^20.0.3" ,
25
- "require-relative" : " ^0.8.7"
26
+ "require-relative" : " ^0.8.7" ,
27
+ "typescript" : " ^2.4.2" ,
28
+ "typescript-eslint-parser" : " ^7.0.0"
26
29
},
27
30
"devDependencies" : {
28
31
"all-contributors-cli" : " ^4.4.0" ,
Original file line number Diff line number Diff line change @@ -170,6 +170,14 @@ const tests = [
170
170
} ,
171
171
output : '{ "foo": "bar" }' ,
172
172
} ,
173
+ {
174
+ title : 'TypeScript example' ,
175
+ input : {
176
+ text : 'function Foo (this: void) { return this; }' ,
177
+ filePath : path . resolve ( './test.ts' ) ,
178
+ } ,
179
+ output : 'function Foo(this: void) {\n return this;\n}' ,
180
+ } ,
173
181
]
174
182
175
183
beforeEach ( ( ) => {
Original file line number Diff line number Diff line change 1
1
/* eslint no-console:0, global-require:0, import/no-dynamic-require:0 */
2
- /* eslint complexity: [1, 6 ] */
2
+ /* eslint complexity: [1, 7 ] */
3
3
import fs from 'fs'
4
4
import path from 'path'
5
5
import requireRelative from 'require-relative'
@@ -87,12 +87,18 @@ async function format(options) {
87
87
88
88
const isCss = / \. ( c s s | l e s s | s c s s ) $ / . test ( filePath )
89
89
const isJson = / \. j s o n $ / . test ( filePath )
90
+ const isTypeScript = / \. t s x ? $ / . test ( filePath )
90
91
91
92
if ( isCss ) {
92
93
formattingOptions . prettier . parser = 'postcss'
93
94
} else if ( isJson ) {
94
95
formattingOptions . prettier . parser = 'json'
95
96
formattingOptions . prettier . trailingComma = 'none'
97
+ } else if ( isTypeScript ) {
98
+ formattingOptions . prettier . parser = 'typescript'
99
+ // XXX: It seems babylon is getting a TypeScript plugin.
100
+ // Should that be used instead?
101
+ formattingOptions . eslint . parser = 'typescript-eslint-parser'
96
102
}
97
103
98
104
const prettify = createPrettify ( formattingOptions . prettier , prettierPath )
You can’t perform that action at this time.
0 commit comments