Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Commit ddebd8c

Browse files
committed
Update test
1 parent e1e4a71 commit ddebd8c

File tree

31 files changed

+206
-195
lines changed

31 files changed

+206
-195
lines changed

src/compiler.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ export function compile(
5858
const { amount: indentAmount, type: indentType } = detectIndent(inputSource);
5959
const sourceWidth = getCodeWidth(inputSource, 80);
6060
const semi = getUseOfSemi(inputSource);
61-
61+
const quotations = getQuotation(inputSource);
6262
_.defaults(prettierOptions, {
6363
tabWidth: indentAmount,
6464
useTabs: indentType === 'tab',
6565
printWidth: sourceWidth,
6666
semi,
67+
singleQuote: quotations === 'single',
6768
});
6869

6970
return prettier.format(printed, prettierOptions);
@@ -79,10 +80,19 @@ function getCodeWidth(source: string, defaultWidth: number): number {
7980

8081
/**
8182
* Detect if a source file is using semicolon
82-
* TODO: use an actual parser. This is not a proper method
83+
* @todo: use an actual parser. This is not a proper method
8384
* @param source
8485
* @return true if code is using semicolons
8586
*/
8687
function getUseOfSemi(source: string): boolean {
8788
return source.indexOf(';') !== -1;
8889
}
90+
91+
/**
92+
* Detect if a source file is using single quotes or double quotes
93+
* @todo
94+
* @param source
95+
*/
96+
function getQuotation(source: string): 'single' | 'double' {
97+
return 'single';
98+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type Foo = {
2-
foo: string;
3-
stuff: boolean;
4-
other: () => void;
5-
bar: number;
6-
[key: string]: number;
2+
foo: string,
3+
stuff: boolean,
4+
other: () => void,
5+
bar: number,
6+
[key: string]: number
77
};
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
type Foo = {
2-
};
1+
type Foo = {};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
type Foo = {
2-
foo: string;
3-
bar: number;
2+
foo: string,
3+
bar: number
44
};

test/end-to-end/basic/output.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as React from 'react';
2-
export default class MyComponent extends React.Component<{
3-
}, {
4-
}> {
2+
export default class MyComponent extends React.Component<{}, {}> {
53
render() {
64
return <div />;
75
}

test/end-to-end/initial-state-and-proprypes-and-set-state/output.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
baz: string;
3+
baz: string
44
};
55
type MyComponentState = {
6-
dynamicState: number;
7-
foo: number;
8-
bar: string;
6+
dynamicState: number,
7+
foo: number,
8+
bar: string
99
};
10-
export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
10+
export default class MyComponent extends React.Component<
11+
MyComponentProps,
12+
MyComponentState
13+
> {
1114
state = { foo: 1, bar: 'str' };
1215
render() {
1316
return <div />;

test/end-to-end/initial-state-and-proprypes/output.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
baz: string;
3+
baz: string
44
};
55
type MyComponentState = {
6-
foo: number;
7-
bar: string;
6+
foo: number,
7+
bar: string
88
};
9-
export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
9+
export default class MyComponent extends React.Component<
10+
MyComponentProps,
11+
MyComponentState
12+
> {
1013
state = { foo: 1, bar: 'str' };
1114
render() {
1215
return <div />;

test/end-to-end/non-react/output.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
class Foo {
22
render() {
3-
return '100';
3+
return '100'
44
}
55
}
66
class Bar extends Foo {
7-
baz() {
8-
}
7+
baz() {}
98
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type HelloProps = {
2-
message?: string;
2+
message?: string
33
};
44
const Hello: React.SFC<HelloProps> = ({ message }) => {
5-
return <div>hello {message}</div>;
5+
return <div>hello {message}</div>;
66
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type HelloProps = {
2-
message?: string;
3-
};
2+
message?: string
3+
}
44
export const Hello: React.SFC<HelloProps> = ({ message }) => {
5-
return <div>hello {message}</div>;
6-
};
5+
return <div>hello {message}</div>
6+
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
interface IFoo {
2-
}
3-
class Foo {
4-
}
5-
class Bar extends Foo {
6-
}
7-
class Foo2 implements IFoo {
8-
}
9-
class Bar2 extends Foo implements IFoo {
10-
}
1+
interface IFoo {}
2+
class Foo {}
3+
class Bar extends Foo {}
4+
class Foo2 implements IFoo {}
5+
class Bar2 extends Foo implements IFoo {}

test/react-js-make-props-and-state-transform/propless-stateless/output.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as React from 'react';
2-
export default class MyComponent extends React.Component<{
3-
}, {
4-
}> {
2+
export default class MyComponent extends React.Component<{}, {}> {
53
render() {
64
return <div />;
75
}

test/react-js-make-props-and-state-transform/set-state-advanced/output.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number; bar: number; } & { baz: number; } & { something: { big: number; here: string; of: { a: number; }[]; }; };
3-
export default class MyComponent extends React.Component<{
4-
}, MyComponentState> {
2+
type MyComponentState = { foo: number, bar: number } & { baz: number } & {
3+
something: { big: number, here: string, of: { a: number }[] }
4+
};
5+
export default class MyComponent extends React.Component<{}, MyComponentState> {
56
render() {
6-
return <button onClick={this.onclick.bind(this)}/>;
7+
return <button onClick={this.onclick.bind(this)} />;
78
}
89
onclick() {
910
if (Math.random() > 0.5) {

test/react-js-make-props-and-state-transform/set-state-only/output.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number; bar: number; };
3-
export default class MyComponent extends React.Component<{
4-
}, MyComponentState> {
2+
type MyComponentState = { foo: number, bar: number };
3+
export default class MyComponent extends React.Component<{}, MyComponentState> {
54
render() {
6-
return <button onClick={this.onclick.bind(this)}/>;
5+
return <button onClick={this.onclick.bind(this)} />;
76
}
87
onclick() {
98
this.setState({ foo: 1, bar: 2 });

test/react-js-make-props-and-state-transform/state-in-class-member/output.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number; };
3-
export default class MyComponent extends React.Component<{
4-
}, MyComponentState> {
2+
type MyComponentState = { foo: number };
3+
export default class MyComponent extends React.Component<{}, MyComponentState> {
54
state = { foo: 1 };
65
render() {
76
return <div />;

test/react-js-make-props-and-state-transform/state-in-constructor/output.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number; };
3-
export default class MyComponent extends React.Component<{
4-
}, MyComponentState> {
2+
type MyComponentState = { foo: number };
3+
export default class MyComponent extends React.Component<{}, MyComponentState> {
54
constructor(props, context) {
65
super(props, context);
76
this.state = { foo: 1 };

test/react-js-make-props-and-state-transform/static-proptypes-getter-simple/output.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
foo: string;
3+
foo: string
44
};
5-
export default class MyComponent extends React.Component<MyComponentProps, {
6-
}> {
5+
export default class MyComponent extends React.Component<MyComponentProps, {}> {
76
static get propTypes() {
87
return {
9-
foo: React.PropTypes.string.isRequired,
8+
foo: React.PropTypes.string.isRequired
109
};
1110
}
1211
render() {

test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
any?: any;
4-
array?: any[];
5-
bool?: boolean;
6-
func?: (...args: any[]) => any;
7-
number?: number;
8-
object?: object;
9-
string?: string;
10-
node?: React.ReactNode;
11-
element?: JSX.Element;
12-
oneOf?: 'a' | 'b' | 'c';
13-
oneOfType?: string | number;
14-
arrayOf?: string[];
3+
any?: any,
4+
array?: any[],
5+
bool?: boolean,
6+
func?: (...args: any[]) => any,
7+
number?: number,
8+
object?: object,
9+
string?: string,
10+
node?: React.ReactNode,
11+
element?: JSX.Element,
12+
oneOf?: 'a' | 'b' | 'c',
13+
oneOfType?: string | number,
14+
arrayOf?: string[],
1515
objectOf?: {
16-
[key: string]: string;
17-
};
16+
[key: string]: string
17+
},
1818
shape?: {
19-
color?: string;
20-
fontSize?: number;
21-
};
22-
anyRequired: any;
23-
arrayRequired: any[];
24-
boolRequired: boolean;
25-
funcRequired: (...args: any[]) => any;
26-
numberRequired: number;
27-
objectRequired: object;
28-
stringRequired: string;
29-
nodeRequired: React.ReactNode;
30-
elementRequired: JSX.Element;
31-
oneOfRequired: 'a' | 'b' | 'c';
32-
oneOfTypeRequired: string | number;
33-
arrayOfRequired: string[];
19+
color?: string,
20+
fontSize?: number
21+
},
22+
anyRequired: any,
23+
arrayRequired: any[],
24+
boolRequired: boolean,
25+
funcRequired: (...args: any[]) => any,
26+
numberRequired: number,
27+
objectRequired: object,
28+
stringRequired: string,
29+
nodeRequired: React.ReactNode,
30+
elementRequired: JSX.Element,
31+
oneOfRequired: 'a' | 'b' | 'c',
32+
oneOfTypeRequired: string | number,
33+
arrayOfRequired: string[],
3434
objectOfRequired: {
35-
[key: string]: string;
36-
};
35+
[key: string]: string
36+
},
3737
shapeRequired: {
38-
color?: string;
39-
fontSize: number;
40-
};
38+
color?: string,
39+
fontSize: number
40+
}
4141
};
42-
export default class MyComponent extends React.Component<MyComponentProps, {
43-
}> {
42+
export default class MyComponent extends React.Component<MyComponentProps, {}> {
4443
static propTypes = {
4544
children: React.PropTypes.node,
4645
any: React.PropTypes.any,
@@ -55,13 +54,13 @@ export default class MyComponent extends React.Component<MyComponentProps, {
5554
oneOf: React.PropTypes.oneOf(['a', 'b', 'c']),
5655
oneOfType: React.PropTypes.oneOfType([
5756
React.PropTypes.string,
58-
React.PropTypes.number,
57+
React.PropTypes.number
5958
]),
6059
arrayOf: React.PropTypes.arrayOf(React.PropTypes.string),
6160
objectOf: React.PropTypes.objectOf(React.PropTypes.string),
6261
shape: React.PropTypes.shape({
6362
color: React.PropTypes.string,
64-
fontSize: React.PropTypes.number,
63+
fontSize: React.PropTypes.number
6564
}),
6665
anyRequired: React.PropTypes.any.isRequired,
6766
arrayRequired: React.PropTypes.array.isRequired,
@@ -75,14 +74,14 @@ export default class MyComponent extends React.Component<MyComponentProps, {
7574
oneOfRequired: React.PropTypes.oneOf(['a', 'b', 'c']).isRequired,
7675
oneOfTypeRequired: React.PropTypes.oneOfType([
7776
React.PropTypes.string,
78-
React.PropTypes.number,
77+
React.PropTypes.number
7978
]).isRequired,
8079
arrayOfRequired: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
8180
objectOfRequired: React.PropTypes.objectOf(React.PropTypes.string).isRequired,
8281
shapeRequired: React.PropTypes.shape({
8382
color: React.PropTypes.string,
84-
fontSize: React.PropTypes.number.isRequired,
85-
}).isRequired,
83+
fontSize: React.PropTypes.number.isRequired
84+
}).isRequired
8685
};
8786
render() {
8887
return <div />;

test/react-js-make-props-and-state-transform/static-proptypes-simple/output.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
foo: string;
3+
foo: string
44
};
5-
export default class MyComponent extends React.Component<MyComponentProps, {
6-
}> {
5+
export default class MyComponent extends React.Component<MyComponentProps, {}> {
76
static propTypes = {
8-
foo: React.PropTypes.string.isRequired,
7+
foo: React.PropTypes.string.isRequired
98
};
109
render() {
1110
return <div />;

test/react-move-prop-types-to-class-transform/simple/output.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
class SomeComponent extends React.Component<{
2-
foo: number;
3-
}, {
4-
bar: string;
5-
}> {
1+
class SomeComponent extends React.Component<
2+
{
3+
foo: number
4+
},
5+
{
6+
bar: string
7+
}
8+
> {
69
static propTypes = { foo: React.PropTypes.string };
710
render() {
811
return null;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import * as React from 'react';
2-
function Foo() {
3-
}
2+
function Foo() {}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
class SomeComponent extends React.Component<{
2-
foo: number;
3-
}, {
4-
bar: string;
5-
}> {
6-
}
1+
class SomeComponent extends React.Component<
2+
{
3+
foo: number
4+
},
5+
{
6+
bar: string
7+
}
8+
> {}

0 commit comments

Comments
 (0)