From 93545599915f57fcb89cbf0d392b213e0ff2cce1 Mon Sep 17 00:00:00 2001 From: Will Douglas Date: Thu, 21 Nov 2019 16:22:48 -0700 Subject: [PATCH] Fix prettier 'no parser or filepath given' warning --- .prettierignore | 2 +- src/compiler.ts | 3 +- .../advanced/output.tsx | 10 +-- .../multiple/output.tsx | 8 +-- .../repeated/output.tsx | 10 +-- .../simple/output.tsx | 4 +- .../output.tsx | 8 +-- .../initial-state-and-proprypes/input.tsx | 2 +- .../initial-state-and-proprypes/output.tsx | 6 +- .../end-to-end/multiple-components/output.tsx | 10 +-- .../stateless-arrow-function/output.tsx | 2 +- test/end-to-end/stateless-function/output.tsx | 2 +- .../multiple-components/output.tsx | 4 +- .../set-state-advanced/output.tsx | 4 +- .../set-state-only/output.tsx | 2 +- .../static-proptypes-getter-simple/output.tsx | 2 +- .../static-proptypes-many-props/output.tsx | 68 +++++++++---------- .../static-proptypes-simple/output.tsx | 2 +- .../multiple-components/output.tsx | 8 +-- .../simple/output.tsx | 6 +- .../multiple/output.tsx | 10 +-- .../simple/output.tsx | 6 +- .../getter/output.tsx | 6 +- .../multiple-components/output.tsx | 12 ++-- .../multiple/output.tsx | 6 +- .../other-static-members/output.tsx | 6 +- .../simple/output.tsx | 6 +- .../multiple-components/output.tsx | 4 +- .../stateless-arrow-function/output.tsx | 2 +- .../stateless-function-many-props/output.tsx | 68 +++++++++---------- .../stateless-function/output.tsx | 2 +- test/transformers.test.ts | 18 +++-- 32 files changed, 158 insertions(+), 151 deletions(-) diff --git a/.prettierignore b/.prettierignore index 6835724..2941c35 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,3 @@ -test/ +test/**/input.* dist/ !test/transformers.test.ts diff --git a/src/compiler.ts b/src/compiler.ts index 4953a7c..33ec8b9 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -88,7 +88,7 @@ export function compile( export function getPrettierOptions(filePath: string, source: string, options: prettier.Options): prettier.Options { const resolvedOptions = prettier.resolveConfig.sync(filePath); if (resolvedOptions) { - _.defaults(resolvedOptions, options); + _.defaults(resolvedOptions, { ...options, filepath: filePath }); return resolvedOptions; } const { amount: indentAmount, type: indentType } = detectIndent(source); @@ -97,6 +97,7 @@ export function getPrettierOptions(filePath: string, source: string, options: pr const quotations = getQuotation(source); _.defaults(Object.assign({}, options), { + filepath: filePath, tabWidth: indentAmount, useTabs: indentType && indentType === 'tab', printWidth: sourceWidth, diff --git a/test/collapse-intersection-interfaces-transform/advanced/output.tsx b/test/collapse-intersection-interfaces-transform/advanced/output.tsx index a579223..a272d5a 100644 --- a/test/collapse-intersection-interfaces-transform/advanced/output.tsx +++ b/test/collapse-intersection-interfaces-transform/advanced/output.tsx @@ -1,7 +1,7 @@ type Foo = { - foo: string, - stuff: boolean, - other: () => void, - bar: number, - [key: string]: number, + foo: string; + stuff: boolean; + other: () => void; + bar: number; + [key: string]: number; }; diff --git a/test/collapse-intersection-interfaces-transform/multiple/output.tsx b/test/collapse-intersection-interfaces-transform/multiple/output.tsx index f6d0c1d..cd722f1 100644 --- a/test/collapse-intersection-interfaces-transform/multiple/output.tsx +++ b/test/collapse-intersection-interfaces-transform/multiple/output.tsx @@ -1,8 +1,8 @@ type Foo = { - foo: string, - bar: number, + foo: string; + bar: number; }; type Bar = { - foo: number, - bar: string, + foo: number; + bar: string; }; diff --git a/test/collapse-intersection-interfaces-transform/repeated/output.tsx b/test/collapse-intersection-interfaces-transform/repeated/output.tsx index cc2144f..727c327 100644 --- a/test/collapse-intersection-interfaces-transform/repeated/output.tsx +++ b/test/collapse-intersection-interfaces-transform/repeated/output.tsx @@ -1,11 +1,11 @@ type A = { - foo: string, + foo: string; }; type B = { - foo: string | number, - bar: number, + foo: string | number; + bar: number; }; type C = { - foo: string | number, - bar: number, + foo: string | number; + bar: number; }; diff --git a/test/collapse-intersection-interfaces-transform/simple/output.tsx b/test/collapse-intersection-interfaces-transform/simple/output.tsx index d4374e3..97d43d9 100644 --- a/test/collapse-intersection-interfaces-transform/simple/output.tsx +++ b/test/collapse-intersection-interfaces-transform/simple/output.tsx @@ -1,4 +1,4 @@ type Foo = { - foo: string, - bar: number, + foo: string; + bar: number; }; diff --git a/test/end-to-end/initial-state-and-proprypes-and-set-state/output.tsx b/test/end-to-end/initial-state-and-proprypes-and-set-state/output.tsx index 95fae0f..b120653 100644 --- a/test/end-to-end/initial-state-and-proprypes-and-set-state/output.tsx +++ b/test/end-to-end/initial-state-and-proprypes-and-set-state/output.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; type MyComponentProps = { - baz: string, + baz: string; }; type MyComponentState = { - dynamicState: number, - foo: number, - bar: string, + dynamicState: number; + foo: number; + bar: string; }; export default class MyComponent extends React.Component { state = { foo: 1, bar: 'str' }; diff --git a/test/end-to-end/initial-state-and-proprypes/input.tsx b/test/end-to-end/initial-state-and-proprypes/input.tsx index 087310a..3878d48 100644 --- a/test/end-to-end/initial-state-and-proprypes/input.tsx +++ b/test/end-to-end/initial-state-and-proprypes/input.tsx @@ -8,5 +8,5 @@ export default class MyComponent extends React.Component { } MyComponent.propTypes = { - baz: React.PropTypes.string.isRequired; + baz: React.PropTypes.string.isRequired } diff --git a/test/end-to-end/initial-state-and-proprypes/output.tsx b/test/end-to-end/initial-state-and-proprypes/output.tsx index 912e3b8..93ed422 100644 --- a/test/end-to-end/initial-state-and-proprypes/output.tsx +++ b/test/end-to-end/initial-state-and-proprypes/output.tsx @@ -1,10 +1,10 @@ import * as React from 'react'; type MyComponentProps = { - baz: string, + baz: string; }; type MyComponentState = { - foo: number, - bar: string, + foo: number; + bar: string; }; export default class MyComponent extends React.Component { state = { foo: 1, bar: 'str' }; diff --git a/test/end-to-end/multiple-components/output.tsx b/test/end-to-end/multiple-components/output.tsx index 94cddf4..d0fc5d4 100644 --- a/test/end-to-end/multiple-components/output.tsx +++ b/test/end-to-end/multiple-components/output.tsx @@ -1,18 +1,18 @@ type HelloProps = { - message?: string, + message?: string; }; const Hello: React.FC = ({ message }) => { return
hello {message}
; }; type HeyProps = { - message?: string, + message?: string; }; const Hey: React.FC = ({ name }) => { return
hey, {name}
; }; type MyComponentState = { - foo: number, - bar: number, + foo: number; + bar: number; }; export default class MyComponent extends React.Component<{}, MyComponentState> { render() { @@ -23,7 +23,7 @@ export default class MyComponent extends React.Component<{}, MyComponentState> { } } type AnotherComponentProps = { - foo: string, + foo: string; }; export class AnotherComponent extends React.Component { render() { diff --git a/test/end-to-end/stateless-arrow-function/output.tsx b/test/end-to-end/stateless-arrow-function/output.tsx index cc7e40e..c0cdd67 100644 --- a/test/end-to-end/stateless-arrow-function/output.tsx +++ b/test/end-to-end/stateless-arrow-function/output.tsx @@ -1,5 +1,5 @@ type HelloProps = { - message?: string, + message?: string; }; const Hello: React.FC = ({ message }) => { return
hello {message}
; diff --git a/test/end-to-end/stateless-function/output.tsx b/test/end-to-end/stateless-function/output.tsx index 41e7e7e..a3fe575 100644 --- a/test/end-to-end/stateless-function/output.tsx +++ b/test/end-to-end/stateless-function/output.tsx @@ -1,5 +1,5 @@ type HelloProps = { - message?: string, + message?: string; }; export const Hello: React.FC = ({ message }) => { return
hello {message}
; diff --git a/test/react-js-make-props-and-state-transform/multiple-components/output.tsx b/test/react-js-make-props-and-state-transform/multiple-components/output.tsx index c5fdde8..35c9ddb 100644 --- a/test/react-js-make-props-and-state-transform/multiple-components/output.tsx +++ b/test/react-js-make-props-and-state-transform/multiple-components/output.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -type MyComponentState = { foo: number, bar: number }; +type MyComponentState = { foo: number; bar: number }; export default class MyComponent extends React.Component<{}, MyComponentState> { render() { return