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

Commit 1e2c28a

Browse files
authored
Fix prettier 'no parser or filepath given' warning (#5)
1 parent 5af6c5b commit 1e2c28a

File tree

32 files changed

+158
-151
lines changed

32 files changed

+158
-151
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
test/
1+
test/**/input.*
22
dist/
33
!test/transformers.test.ts

src/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function compile(
8888
export function getPrettierOptions(filePath: string, source: string, options: prettier.Options): prettier.Options {
8989
const resolvedOptions = prettier.resolveConfig.sync(filePath);
9090
if (resolvedOptions) {
91-
_.defaults(resolvedOptions, options);
91+
_.defaults(resolvedOptions, { ...options, filepath: filePath });
9292
return resolvedOptions;
9393
}
9494
const { amount: indentAmount, type: indentType } = detectIndent(source);
@@ -97,6 +97,7 @@ export function getPrettierOptions(filePath: string, source: string, options: pr
9797
const quotations = getQuotation(source);
9898

9999
_.defaults(Object.assign({}, options), {
100+
filepath: filePath,
100101
tabWidth: indentAmount,
101102
useTabs: indentType && indentType === 'tab',
102103
printWidth: sourceWidth,
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
type Foo = {
2-
foo: string,
3-
bar: number,
2+
foo: string;
3+
bar: number;
44
};
55
type Bar = {
6-
foo: number,
7-
bar: string,
6+
foo: number;
7+
bar: string;
88
};
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
type A = {
2-
foo: string,
2+
foo: string;
33
};
44
type B = {
5-
foo: string | number,
6-
bar: number,
5+
foo: string | number;
6+
bar: number;
77
};
88
type C = {
9-
foo: string | number,
10-
bar: number,
9+
foo: string | number;
10+
bar: number;
1111
};
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/initial-state-and-proprypes-and-set-state/output.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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
};
1010
export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
1111
state = { foo: 1, bar: 'str' };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export default class MyComponent extends React.Component {
88
}
99

1010
MyComponent.propTypes = {
11-
baz: React.PropTypes.string.isRequired;
11+
baz: React.PropTypes.string.isRequired
1212
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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
};
99
export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
1010
state = { foo: 1, bar: 'str' };

test/end-to-end/multiple-components/output.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
type HelloProps = {
2-
message?: string,
2+
message?: string;
33
};
44
const Hello: React.FC<HelloProps> = ({ message }) => {
55
return <div>hello {message}</div>;
66
};
77
type HeyProps = {
8-
message?: string,
8+
message?: string;
99
};
1010
const Hey: React.FC<HeyProps> = ({ name }) => {
1111
return <div>hey, {name}</div>;
1212
};
1313
type MyComponentState = {
14-
foo: number,
15-
bar: number,
14+
foo: number;
15+
bar: number;
1616
};
1717
export default class MyComponent extends React.Component<{}, MyComponentState> {
1818
render() {
@@ -23,7 +23,7 @@ export default class MyComponent extends React.Component<{}, MyComponentState> {
2323
}
2424
}
2525
type AnotherComponentProps = {
26-
foo: string,
26+
foo: string;
2727
};
2828
export class AnotherComponent extends React.Component<AnotherComponentProps, {}> {
2929
render() {

test/end-to-end/stateless-arrow-function/output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type HelloProps = {
2-
message?: string,
2+
message?: string;
33
};
44
const Hello: React.FC<HelloProps> = ({ message }) => {
55
return <div>hello {message}</div>;

test/end-to-end/stateless-function/output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type HelloProps = {
2-
message?: string,
2+
message?: string;
33
};
44
export const Hello: React.FC<HelloProps> = ({ message }) => {
55
return <div>hello {message}</div>;

test/react-js-make-props-and-state-transform/multiple-components/output.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number, bar: number };
2+
type MyComponentState = { foo: number; bar: number };
33
export default class MyComponent extends React.Component<{}, MyComponentState> {
44
render() {
55
return <button onClick={this.onclick.bind(this)} />;
@@ -9,7 +9,7 @@ export default class MyComponent extends React.Component<{}, MyComponentState> {
99
}
1010
}
1111
type AnotherComponentProps = {
12-
foo: string,
12+
foo: string;
1313
};
1414
export class AnotherComponent extends React.Component<AnotherComponentProps, {}> {
1515
static propTypes = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number, bar: number } & { baz: number } & {
3-
something: { big: number, here: string, of: { a: number }[] },
2+
type MyComponentState = { foo: number; bar: number } & { baz: number } & {
3+
something: { big: number; here: string; of: { a: number }[] };
44
};
55
export default class MyComponent extends React.Component<{}, MyComponentState> {
66
render() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
type MyComponentState = { foo: number, bar: number };
2+
type MyComponentState = { foo: number; bar: number };
33
export default class MyComponent extends React.Component<{}, MyComponentState> {
44
render() {
55
return <button onClick={this.onclick.bind(this)} />;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
foo: string,
3+
foo: string;
44
};
55
export default class MyComponent extends React.Component<MyComponentProps, {}> {
66
static get propTypes() {

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
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
};
4242
export default class MyComponent extends React.Component<MyComponentProps, {}> {
4343
static propTypes = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
type MyComponentProps = {
3-
foo: string,
3+
foo: string;
44
};
55
export default class MyComponent extends React.Component<MyComponentProps, {}> {
66
static propTypes = {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {
99
static propTypes = { foo: React.PropTypes.string };
1010
render() {
@@ -13,7 +13,7 @@ class SomeComponent extends React.Component<
1313
}
1414
SomeComponent.propTypes = { foo: React.PropTypes.string };
1515
class AnotherComponent extends React.Component<{
16-
baz: number,
16+
baz: number;
1717
}> {
1818
static propTypes = { baz: React.PropTypes.string };
1919
render() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {
99
static propTypes = { foo: React.PropTypes.string };
1010
render() {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: string,
4-
baz: string,
3+
foo: string;
4+
baz: string;
55
},
66
{
7-
bar: string,
8-
},
7+
bar: string;
8+
}
99
> {}
1010
class AnotherComponent extends React.Component<{
11-
lol: number,
11+
lol: number;
1212
}> {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {}
99
class AnotherComponent extends React.Component<
1010
{
11-
foo: number,
11+
foo: number;
1212
},
1313
{
14-
bar: string,
15-
},
14+
bar: string;
15+
}
1616
> {}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class SomeComponent extends React.Component<
22
{
3-
foo: number,
3+
foo: number;
44
},
55
{
6-
bar: string,
7-
},
6+
bar: string;
7+
}
88
> {}

0 commit comments

Comments
 (0)