Skip to content

Commit 09a2d0b

Browse files
authored
style: Run Prettier for TypeScript declaration files (#2142)
1 parent 1f30ebe commit 09a2d0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4958
-4643
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"require-atomic-updates": "off",
4141
"prefer-spread": "off",
4242
"prefer-rest-params": "off",
43+
"@typescript-eslint/triple-slash-reference": "off",
4344
"@typescript-eslint/no-empty-function": "off",
4445
"@typescript-eslint/no-explicit-any": "off",
4546
"@typescript-eslint/no-var-requires": "off",

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@semantic-release/github": "8.0.7",
5555
"@semantic-release/npm": "9.0.2",
5656
"@semantic-release/release-notes-generator": "10.0.3",
57+
"@types/facebook-js-sdk": "3.3.11",
5758
"babel-jest": "29.5.0",
5859
"babel-plugin-inline-package-json": "2.0.0",
5960
"babel-plugin-minify-dead-code-elimination": "0.5.2",
@@ -97,7 +98,7 @@
9798
},
9899
"scripts": {
99100
"build": "node build_releases.js",
100-
"build:types": "tsc",
101+
"build:types": "tsc && prettier --write 'types/{**/*,*}.ts' && npm run lint:fix",
101102
"release": "node build_releases.js && npm publish",
102103
"test": "cross-env PARSE_BUILD=node jest",
103104
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
@@ -118,7 +119,7 @@
118119
"pre-commit": "lint-staged",
119120
"release_docs": "./release_docs.sh",
120121
"gulp": "gulp",
121-
"prettier": "prettier --write '{src,integration}/{**/*,*}.{js,ts}' && npm run lint:fix",
122+
"prettier": "prettier --write '{src,integration,types}/{**/*,*}.{js,ts}' && npm run lint:fix",
122123
"cross-env": "cross-env"
123124
},
124125
"lint-staged": {

src/FacebookUtils.js renamed to src/FacebookUtils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
/**
2-
* @flow-weak
3-
*/
41
/* global FB */
52
import ParseUser from './ParseUser';
3+
import type { AuthProviderType } from './ParseUser';
64

75
let initialized = false;
86
let requestedPermissions;
97
let initOptions;
10-
const provider = {
8+
const provider: AuthProviderType = {
119
authenticate(options) {
1210
if (typeof FB === 'undefined') {
1311
options.error(this, 'Facebook SDK not found.');
@@ -38,7 +36,7 @@ const provider = {
3836

3937
restoreAuthentication(authData) {
4038
if (authData) {
41-
const newOptions = {};
39+
const newOptions: typeof initOptions = {};
4240
if (initOptions) {
4341
for (const key in initOptions) {
4442
newOptions[key] = initOptions[key];

src/LocalDatastore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const LocalDatastore = {
126126
},
127127

128128
// Retrieve all pointer fields from object recursively
129-
_getChildren(object: ParseObject) {
129+
_getChildren(object: ParseObject): any {
130130
const encountered = {};
131131
const json = object._toFullJSON(undefined, true);
132132
for (const key in json) {

src/ObjectStateMutations.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function estimateAttribute(
8686
if (pendingOps[i][attr]) {
8787
if (pendingOps[i][attr] instanceof RelationOp) {
8888
if (object.id) {
89-
value = pendingOps[i][attr].applyTo(value, object, attr);
89+
value = (pendingOps[i][attr] as RelationOp).applyTo(value, object, attr);
9090
}
9191
} else {
9292
value = pendingOps[i][attr].applyTo(value);
@@ -110,7 +110,7 @@ export function estimateAttributes(
110110
for (attr in pendingOps[i]) {
111111
if (pendingOps[i][attr] instanceof RelationOp) {
112112
if (object.id) {
113-
data[attr] = pendingOps[i][attr].applyTo(data[attr], object, attr);
113+
data[attr] = (pendingOps[i][attr] as RelationOp).applyTo(data[attr], object, attr);
114114
}
115115
} else {
116116
if (attr.includes('.')) {
@@ -129,7 +129,7 @@ export function estimateAttributes(
129129
}
130130
} else {
131131
if (Array.isArray(object[key])) {
132-
object[key] = [ ...object[key] ];
132+
object[key] = [...object[key]];
133133
} else {
134134
object[key] = { ...object[key] };
135135
}

src/ParseConfig.js renamed to src/ParseConfig.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import CoreManager from './CoreManager';
62
import decode from './decode';
73
import encode from './encode';
@@ -17,7 +13,6 @@ import type { RequestOptions } from './RESTController';
1713
*
1814
* @alias Parse.Config
1915
*/
20-
2116
class ParseConfig {
2217
attributes: { [key: string]: any };
2318
_escapedAttributes: { [key: string]: any };
@@ -123,7 +118,7 @@ class ParseConfig {
123118
}
124119
}
125120

126-
let currentConfig = null;
121+
let currentConfig: ParseConfig | null = null;
127122

128123
const CURRENT_CONFIG_KEY = 'currentConfig';
129124

@@ -195,7 +190,7 @@ const DefaultController = {
195190
});
196191
},
197192

198-
save(attrs: { [key: string]: any }, masterKeyOnlyFlags: { [key: string]: any }) {
193+
save(attrs?: { [key: string]: any }, masterKeyOnlyFlags?: { [key: string]: any }) {
199194
const RESTController = CoreManager.getRESTController();
200195
const encodedAttrs = {};
201196
for (const key in attrs) {

src/ParseObject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type FetchOptions = {
5858

5959
// Mapping of class names to constructors, so we can populate objects from the
6060
// server with appropriate subclasses of ParseObject
61-
const classMap = {};
61+
const classMap: AttributeMap = {};
6262

6363
// Global counter for generating unique Ids for non-single-instance objects
6464
let objectCount = 0;
@@ -412,7 +412,7 @@ class ParseObject {
412412
const pending = stateController.popPendingState(this._getStateIdentifier());
413413
for (attr in pending) {
414414
if (pending[attr] instanceof RelationOp) {
415-
changes[attr] = pending[attr].applyTo(undefined, this, attr);
415+
changes[attr] = (pending[attr] as RelationOp).applyTo(undefined, this, attr);
416416
} else if (!(attr in response)) {
417417
// Only SetOps and UnsetOps should not come back with results
418418
changes[attr] = pending[attr].applyTo(undefined);

src/ParseOp.js renamed to src/ParseOp.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import arrayContainsObject from './arrayContainsObject';
62
import decode from './decode';
73
import encode from './encode';
84
import CoreManager from './CoreManager';
95
import type ParseObject from './ParseObject';
6+
import type Pointer from './ParseObject';
107
import ParseRelation from './ParseRelation';
118
import unique from './unique';
129

13-
export function opFromJSON(json: { [key: string]: any }): ?Op {
10+
export function opFromJSON(json: { [key: string]: any }): Op | null {
1411
if (!json || !json.__op) {
1512
return null;
1613
}
@@ -58,12 +55,12 @@ export function opFromJSON(json: { [key: string]: any }): ?Op {
5855
export class Op {
5956
// Empty parent class
6057
applyTo(value: any): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
61-
mergeWith(previous: Op): ?Op {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
62-
toJSON(): any {}
58+
mergeWith(previous: Op): Op | void {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
59+
toJSON(offline?: boolean): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
6360
}
6461

6562
export class SetOp extends Op {
66-
_value: ?any;
63+
_value: any;
6764

6865
constructor(value: any) {
6966
super();
@@ -78,7 +75,7 @@ export class SetOp extends Op {
7875
return new SetOp(this._value);
7976
}
8077

81-
toJSON(offline?: boolean) {
78+
toJSON(offline?: boolean): any {
8279
return encode(this._value, false, true, undefined, offline);
8380
}
8481
}
@@ -108,7 +105,7 @@ export class IncrementOp extends Op {
108105
this._amount = amount;
109106
}
110107

111-
applyTo(value: ?any): number {
108+
applyTo(value: any): number {
112109
if (typeof value === 'undefined') {
113110
return this._amount;
114111
}
@@ -192,7 +189,7 @@ export class AddUniqueOp extends Op {
192189
}
193190
if (Array.isArray(value)) {
194191
const ParseObject = CoreManager.getParseObject();
195-
const toAdd = [];
192+
const toAdd: any[] = [];
196193
this._value.forEach(v => {
197194
if (v instanceof ParseObject) {
198195
if (!arrayContainsObject(value, v)) {
@@ -301,7 +298,7 @@ export class RemoveOp extends Op {
301298
}
302299

303300
export class RelationOp extends Op {
304-
_targetClassName: ?string;
301+
_targetClassName: string | null;
305302
relationsToAdd: Array<string>;
306303
relationsToRemove: Array<string>;
307304

@@ -340,7 +337,7 @@ export class RelationOp extends Op {
340337
return obj.id;
341338
}
342339

343-
applyTo(value: any, parent: ParseObject, key?: string): ?ParseRelation {
340+
applyTo(value: any, parent?: ParseObject, key?: string): ParseRelation {
344341
if (!value) {
345342
if (!parent || !key) {
346343
throw new Error(
@@ -426,17 +423,17 @@ export class RelationOp extends Op {
426423
}
427424

428425
toJSON(): { __op?: string; objects?: any; ops?: any } {
429-
const idToPointer = id => {
426+
const idToPointer = (id: string) => {
430427
return {
431428
__type: 'Pointer',
432429
className: this._targetClassName,
433430
objectId: id,
434431
};
435432
};
436433

437-
let adds = null;
438-
let removes = null;
439-
let pointers = null;
434+
let pointers: any = null;
435+
let adds: null | { __op: string; objects: null | Pointer[] } = null;
436+
let removes: null | { __op: string; objects: null | Pointer[] } = null;
440437

441438
if (this.relationsToAdd.length > 0) {
442439
pointers = this.relationsToAdd.map(idToPointer);

src/ParsePolygon.js renamed to src/ParsePolygon.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/**
2-
* @flow
3-
*/
4-
51
import ParseGeoPoint from './ParseGeoPoint';
2+
type Coordinate = [number, number];
3+
type Coordinates = Coordinate[];
64

75
/**
86
* Creates a new Polygon with any of the following forms:<br>
@@ -24,27 +22,27 @@ import ParseGeoPoint from './ParseGeoPoint';
2422
* @alias Parse.Polygon
2523
*/
2624
class ParsePolygon {
27-
_coordinates: Array<Array<number>>;
25+
_coordinates: Coordinates;
2826

2927
/**
30-
* @param {(number[][] | Parse.GeoPoint[])} coordinates An Array of coordinate pairs
28+
* @param {(Coordinates | Parse.GeoPoint[])} coordinates An Array of coordinate pairs
3129
*/
32-
constructor(coordinates: Array<Array<number>> | Array<ParseGeoPoint>) {
30+
constructor(coordinates: Coordinates | Array<ParseGeoPoint>) {
3331
this._coordinates = ParsePolygon._validate(coordinates);
3432
}
3533

3634
/**
3735
* Coordinates value for this Polygon.
3836
* Throws an exception if not valid type.
3937
*
40-
* @property {(number[][] | Parse.GeoPoint[])} coordinates list of coordinates
41-
* @returns {number[][]}
38+
* @property {(Coordinates | Parse.GeoPoint[])} coordinates list of coordinates
39+
* @returns {Coordinates}
4240
*/
43-
get coordinates(): Array<Array<number>> {
41+
get coordinates(): Coordinates {
4442
return this._coordinates;
4543
}
4644

47-
set coordinates(coords: Array<Array<number>> | Array<ParseGeoPoint>) {
45+
set coordinates(coords: Coordinates | Array<ParseGeoPoint>) {
4846
this._coordinates = ParsePolygon._validate(coords);
4947
}
5048

@@ -53,7 +51,7 @@ class ParsePolygon {
5351
*
5452
* @returns {object}
5553
*/
56-
toJSON(): { __type: string; coordinates: Array<Array<number>> } {
54+
toJSON(): { __type: string; coordinates: Coordinates } {
5755
ParsePolygon._validate(this._coordinates);
5856
return {
5957
__type: 'Polygon',
@@ -67,7 +65,7 @@ class ParsePolygon {
6765
* @param {(Parse.Polygon | object)} other
6866
* @returns {boolean}
6967
*/
70-
equals(other: any): boolean {
68+
equals(other: ParsePolygon | any): boolean {
7169
if (!(other instanceof ParsePolygon) || this.coordinates.length !== other.coordinates.length) {
7270
return false;
7371
}
@@ -138,14 +136,14 @@ class ParsePolygon {
138136
* @throws {TypeError}
139137
* @returns {number[][]} Array of coordinates if validated.
140138
*/
141-
static _validate(coords: Array<Array<number>> | Array<ParseGeoPoint>): Array<Array<number>> {
139+
static _validate(coords: Coordinates | Array<ParseGeoPoint>): Coordinates {
142140
if (!Array.isArray(coords)) {
143141
throw new TypeError('Coordinates must be an Array');
144142
}
145143
if (coords.length < 3) {
146144
throw new TypeError('Polygon must have at least 3 GeoPoints or Points');
147145
}
148-
const points = [];
146+
const points: Coordinates = [];
149147
for (let i = 0; i < coords.length; i += 1) {
150148
const coord = coords[i];
151149
let geoPoint;

0 commit comments

Comments
 (0)