Skip to content

Commit a52799f

Browse files
damassiorta
authored andcommitted
Add Prettier, Lint Staged to help maintain repo consistency (DefinitelyTyped#35672)
* [Toolchain] Add Prettier * [Toolchain] Add lint-staged * [Toolchain] Apply prettier to some types * Switch to using precise commits so that only changed code is ran through prettier
1 parent 7dab068 commit a52799f

15 files changed

+261
-213
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ insert_final_newline = true
77

88
[{*.json,*.yml,*.ts,*.tsx,*.md}]
99
indent_style = space
10+

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.json

.prettierrc.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json.schemastore.org/prettierrc",
3+
4+
"parser": "typescript",
5+
"printWidth": 120,
6+
"semi": true,
7+
"singleQuote": true,
8+
"tabWidth": 4,
9+
"trailingComma": "es5",
10+
11+
"overrides": [
12+
{
13+
"files": ["*.md"],
14+
"options": {
15+
"tabWidth": 2
16+
}
17+
}
18+
]
19+
}
20+

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
},
2424
"devDependencies": {
2525
"dtslint": "latest",
26+
"husky": ">=1",
27+
"precise-commits": "^1.0.2",
28+
"prettier": "^1.17.1",
2629
"types-publisher": "github:Microsoft/types-publisher#production"
2730
},
28-
"dependencies": {}
31+
"dependencies": {},
32+
"husky": {
33+
"hooks": {
34+
"pre-commit": "precise-commits"
35+
}
36+
}
2937
}

types/react-relay/classic.d.ts

+32-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as React from "react";
2-
import * as RelayRuntimeTypes from "relay-runtime";
1+
import * as React from 'react';
2+
import * as RelayRuntimeTypes from 'relay-runtime';
33

44
// ~~~~~~~~~~~~~~~~~~~~~
55
// Maybe Fix
@@ -19,7 +19,7 @@ export interface RelayQuery {
1919
export interface FragmentResolver {
2020
dispose(): void;
2121
resolve(
22-
fragment: RelayQuery["Fragment"],
22+
fragment: RelayQuery['Fragment'],
2323
dataIDs: RelayRuntimeTypes.DataID | RelayRuntimeTypes.DataID[]
2424
): StoreReaderData | StoreReaderData[] | undefined | null;
2525
}
@@ -29,18 +29,18 @@ export interface RelayEnvironmentInterface {
2929
querySet: RelayRuntimeTypes.RelayQuerySet,
3030
onReadyStateChange: RelayRuntimeTypes.ReadyStateChangeCallback
3131
): RelayRuntimeTypes.Abortable;
32-
getFragmentResolver(fragment: RelayQuery["Fragment"], onNext: () => void): FragmentResolver;
32+
getFragmentResolver(fragment: RelayQuery['Fragment'], onNext: () => void): FragmentResolver;
3333
getStoreData(): RelayStoreData;
3434
primeCache(
3535
querySet: RelayRuntimeTypes.RelayQuerySet,
3636
onReadyStateChange: RelayRuntimeTypes.ReadyStateChangeCallback
3737
): RelayRuntimeTypes.Abortable;
3838
read(
39-
node: RelayQuery["Node"],
39+
node: RelayQuery['Node'],
4040
dataID: RelayRuntimeTypes.DataID,
4141
options?: StoreReaderOptions
4242
): StoreReaderData | void;
43-
readQuery(root: RelayQuery["Root"], options?: StoreReaderOptions): StoreReaderData[] | void;
43+
readQuery(root: RelayQuery['Root'], options?: StoreReaderOptions): StoreReaderData[] | void;
4444
}
4545

4646
// ~~~~~~~~~~~~~~~~~~~~~
@@ -50,7 +50,7 @@ export type ClientMutationID = string;
5050

5151
/** Fragments are a hash of functions */
5252
export interface Fragments {
53-
[query: string]: ((variables?: RelayVariables) => string);
53+
[query: string]: (variables?: RelayVariables) => string;
5454
}
5555

5656
export interface CreateContainerOpts {
@@ -65,20 +65,20 @@ export interface RelayVariables {
6565

6666
/** add static getFragment method to the component constructor */
6767
export interface RelayContainerClass<T> extends React.ComponentClass<T> {
68-
getFragment: ((q: string, v?: RelayVariables) => string);
68+
getFragment: (q: string, v?: RelayVariables) => string;
6969
}
7070

7171
export interface RelayQueryRequestResolve {
7272
response: any;
7373
}
7474

7575
export type RelayMutationStatus =
76-
| "UNCOMMITTED" // Transaction hasn't yet been sent to the server. Transaction can be committed or rolled back.
77-
| "COMMIT_QUEUED" // Transaction was committed but another transaction with the same collision key is pending, so the transaction has been queued to send to the server.
78-
| "COLLISION_COMMIT_FAILED" // Transaction was queued for commit but another transaction with the same collision key failed. All transactions in the collision queue,
76+
| 'UNCOMMITTED' // Transaction hasn't yet been sent to the server. Transaction can be committed or rolled back.
77+
| 'COMMIT_QUEUED' // Transaction was committed but another transaction with the same collision key is pending, so the transaction has been queued to send to the server.
78+
| 'COLLISION_COMMIT_FAILED' // Transaction was queued for commit but another transaction with the same collision key failed. All transactions in the collision queue,
7979
// including this one, have been failed. Transaction can be recommitted or rolled back.
80-
| "COMMITTING" // Transaction is waiting for the server to respond.
81-
| "COMMIT_FAILED";
80+
| 'COMMITTING' // Transaction is waiting for the server to respond.
81+
| 'COMMIT_FAILED';
8282

8383
export class RelayMutationTransaction {
8484
applyOptimistic(): RelayMutationTransaction;
@@ -187,27 +187,25 @@ export interface RenderStateConfig {
187187
export type RenderCallback = (renderState: RenderStateConfig) => any;
188188

189189
export type ReadyStateEvent =
190-
| "ABORT"
191-
| "CACHE_RESTORED_REQUIRED"
192-
| "CACHE_RESTORE_FAILED"
193-
| "CACHE_RESTORE_START"
194-
| "NETWORK_QUERY_ERROR"
195-
| "NETWORK_QUERY_RECEIVED_ALL"
196-
| "NETWORK_QUERY_RECEIVED_REQUIRED"
197-
| "NETWORK_QUERY_START"
198-
| "STORE_FOUND_ALL"
199-
| "STORE_FOUND_REQUIRED";
200-
201-
export type OnReadyStateChange = (
202-
readyState: {
203-
ready: boolean;
204-
done: boolean;
205-
stale: boolean;
206-
error?: Error;
207-
events: ReadyStateEvent[];
208-
aborted: boolean;
209-
}
210-
) => void;
190+
| 'ABORT'
191+
| 'CACHE_RESTORED_REQUIRED'
192+
| 'CACHE_RESTORE_FAILED'
193+
| 'CACHE_RESTORE_START'
194+
| 'NETWORK_QUERY_ERROR'
195+
| 'NETWORK_QUERY_RECEIVED_ALL'
196+
| 'NETWORK_QUERY_RECEIVED_REQUIRED'
197+
| 'NETWORK_QUERY_START'
198+
| 'STORE_FOUND_ALL'
199+
| 'STORE_FOUND_REQUIRED';
200+
201+
export type OnReadyStateChange = (readyState: {
202+
ready: boolean;
203+
done: boolean;
204+
stale: boolean;
205+
error?: Error;
206+
events: ReadyStateEvent[];
207+
aborted: boolean;
208+
}) => void;
211209

212210
export interface RelayProp<V = any> {
213211
readonly route: { name: string }; // incomplete, also has params and queries

types/react-relay/compat.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export { QueryRenderer, fetchQuery, graphql } from "./index";
1+
export { QueryRenderer, fetchQuery, graphql } from './index';
22
import {
33
ConnectionConfig,
44
RelayPaginationProp as RelayModernPaginationProp,
55
RelayRefetchProp as RelayModernRefetchProp,
6-
} from "./index";
7-
export { ConcreteFragment, ConcreteRequest, ConcreteBatchRequest } from "relay-runtime";
8-
import * as RelayRuntimeTypes from "relay-runtime";
9-
import { RelayEnvironmentInterface } from "./classic";
6+
} from './index';
7+
export { ConcreteFragment, ConcreteRequest, ConcreteBatchRequest } from 'relay-runtime';
8+
import * as RelayRuntimeTypes from 'relay-runtime';
9+
import { RelayEnvironmentInterface } from './classic';
1010

1111
// ~~~~~~~~~~~~~~~~~~~~~
1212
// Maybe Fix

types/react-relay/index.d.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,31 @@ export {
2020
fetchRelayModernQuery as fetchQuery,
2121
GraphQLTaggedNode,
2222
requestRelaySubscription as requestSubscription,
23-
} from "relay-runtime";
23+
} from 'relay-runtime';
2424

25-
import * as React from "react";
26-
import * as RelayRuntimeTypes from "relay-runtime";
25+
import * as React from 'react';
26+
import * as RelayRuntimeTypes from 'relay-runtime';
2727

2828
// ~~~~~~~~~~~~~~~~~~~~~
2929
// Utility types
3030
// ~~~~~~~~~~~~~~~~~~~~~
3131

3232
export interface _RefType<T> {
33-
" $refType": T;
33+
' $refType': T;
3434
}
3535
export interface _FragmentRefs<T> {
36-
" $fragmentRefs": T;
36+
' $fragmentRefs': T;
3737
}
3838

3939
export type FragmentOrRegularProp<T> = T extends _RefType<infer U>
4040
? _FragmentRefs<U>
41-
: T extends ReadonlyArray<_RefType<infer U>> ? ReadonlyArray<_FragmentRefs<U>> : T;
41+
: T extends ReadonlyArray<_RefType<infer U>>
42+
? ReadonlyArray<_FragmentRefs<U>>
43+
: T;
4244

4345
export type MappedFragmentProps<T> = { [K in keyof T]: FragmentOrRegularProp<T[K]> };
4446

45-
export type RemoveRelayProp<P> = Pick<P, Exclude<keyof P, "relay">>;
47+
export type RemoveRelayProp<P> = Pick<P, Exclude<keyof P, 'relay'>>;
4648

4749
export interface ComponentRef {
4850
componentRef?: (ref: any) => void;
@@ -92,11 +94,11 @@ export const graphql: GraphqlInterface;
9294

9395
export interface QueryRendererProps<T extends RelayRuntimeTypes.OperationBase = RelayRuntimeTypes.OperationDefaults> {
9496
cacheConfig?: RelayRuntimeTypes.CacheConfig;
95-
dataFrom?: "NETWORK_ONLY"|"STORE_THEN_NETWORK";
97+
dataFrom?: 'NETWORK_ONLY' | 'STORE_THEN_NETWORK';
9698
environment: RelayRuntimeTypes.Environment;
9799
query?: RelayRuntimeTypes.GraphQLTaggedNode | null;
98-
render(readyState: ReadyState<T["response"]>): React.ReactNode;
99-
variables: T["variables"];
100+
render(readyState: ReadyState<T['response']>): React.ReactNode;
101+
variables: T['variables'];
100102
rerunParamExperimental?: RelayRuntimeTypes.RerunParam;
101103
}
102104
export interface ReadyState<T extends RelayRuntimeTypes.Variables = RelayRuntimeTypes.Variables> {
@@ -153,7 +155,7 @@ export function FragmentVariablesGetter(
153155
totalCount: number
154156
): RelayRuntimeTypes.Variables;
155157
export interface ConnectionConfig<P> {
156-
direction?: "backward" | "forward";
158+
direction?: 'backward' | 'forward';
157159
getConnectionFromProps?(props: P): ConnectionData | undefined | null;
158160
getFragmentVariables?: typeof FragmentVariablesGetter;
159161
getVariables(
@@ -196,6 +198,4 @@ export function createRefetchContainer<P>(
196198
// Context
197199
// ~~~~~~~~~~~~~~~~~~~~~
198200

199-
export const ReactRelayContext: React.Context<
200-
RelayRuntimeTypes.CRelayContext<RelayRuntimeTypes.Environment>
201-
>;
201+
export const ReactRelayContext: React.Context<RelayRuntimeTypes.CRelayContext<RelayRuntimeTypes.Environment>>;

types/react-relay/test/react-relay-classic-tests.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from "react";
2-
import * as Relay from "react-relay/classic";
1+
import * as React from 'react';
2+
import * as Relay from 'react-relay/classic';
33

4-
import { CompatContainer } from "./react-relay-compat-tests";
4+
import { CompatContainer } from './react-relay-compat-tests';
55

66
interface Props {
77
text: string;
@@ -25,13 +25,13 @@ export default class AddTweetMutation extends Relay.Mutation<Props, {}> {
2525
getConfigs() {
2626
return [
2727
{
28-
type: "RANGE_ADD",
29-
parentName: "user",
28+
type: 'RANGE_ADD',
29+
parentName: 'user',
3030
parentID: this.props.userId,
31-
connectionName: "tweets",
32-
edgeName: "tweetEdge",
31+
connectionName: 'tweets',
32+
edgeName: 'tweetEdge',
3333
rangeBehaviors: {
34-
"": "append",
34+
'': 'append',
3535
},
3636
},
3737
];
@@ -63,7 +63,7 @@ const ArtworkContainer = Relay.createContainer(Artwork, {
6363
artwork: () => Relay.QL`
6464
fragment on Artwork {
6565
title
66-
${CompatContainer.getFragment("whatever")}
66+
${CompatContainer.getFragment('whatever')}
6767
}
6868
`,
6969
},
@@ -72,13 +72,13 @@ const ArtworkContainer = Relay.createContainer(Artwork, {
7272
class StubbedArtwork extends React.Component {
7373
render() {
7474
const props = {
75-
artwork: { title: "CHAMPAGNE FORMICA FLAG" },
75+
artwork: { title: 'CHAMPAGNE FORMICA FLAG' },
7676
relay: {
7777
route: {
78-
name: "champagne",
78+
name: 'champagne',
7979
},
8080
variables: {
81-
artworkID: "champagne-formica-flag",
81+
artworkID: 'champagne-formica-flag',
8282
},
8383
setVariables: () => {},
8484
forceFetch: () => {},

types/react-relay/test/react-relay-compat-tests.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import * as React from "react";
1+
import * as React from 'react';
22
import {
33
QueryRenderer as CompatQueryRenderer,
44
createFragmentContainer as createFragmentContainerCompat,
55
commitMutation as commitMutationCompat,
66
CompatEnvironment,
77
RelayPaginationProp as RelayPaginationPropCompat,
8-
} from "react-relay/compat";
8+
} from 'react-relay/compat';
99

10-
import { configs, mutation, optimisticResponse } from "./react-relay-tests";
10+
import { configs, mutation, optimisticResponse } from './react-relay-tests';
1111

1212
// testting compat mutation with classic environment
1313
function markNotificationAsReadCompat(environment: CompatEnvironment, source: string, storyID: string) {
@@ -24,13 +24,13 @@ function markNotificationAsReadCompat(environment: CompatEnvironment, source: st
2424
optimisticResponse,
2525
variables,
2626
onCompleted: (response, errors) => {
27-
console.log("Response received from server.");
27+
console.log('Response received from server.');
2828
},
2929
onError: err => console.error(err),
3030
updater: (store, data) => {
3131
const field = store.get(storyID);
3232
if (field) {
33-
field.setValue(data.story, "story");
33+
field.setValue(data.story, 'story');
3434
}
3535
},
3636
});

0 commit comments

Comments
 (0)