Skip to content

style: Run Prettier for TypeScript declaration files #2142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"require-atomic-updates": "off",
"prefer-spread": "off",
"prefer-rest-params": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@semantic-release/github": "8.0.7",
"@semantic-release/npm": "9.0.2",
"@semantic-release/release-notes-generator": "10.0.3",
"@types/facebook-js-sdk": "3.3.11",
"babel-jest": "29.5.0",
"babel-plugin-inline-package-json": "2.0.0",
"babel-plugin-minify-dead-code-elimination": "0.5.2",
Expand Down Expand Up @@ -97,7 +98,7 @@
},
"scripts": {
"build": "node build_releases.js",
"build:types": "tsc",
"build:types": "tsc && prettier --write 'types/{**/*,*}.ts' && npm run lint:fix",
"release": "node build_releases.js && npm publish",
"test": "cross-env PARSE_BUILD=node jest",
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
Expand All @@ -118,7 +119,7 @@
"pre-commit": "lint-staged",
"release_docs": "./release_docs.sh",
"gulp": "gulp",
"prettier": "prettier --write '{src,integration}/{**/*,*}.{js,ts}' && npm run lint:fix",
"prettier": "prettier --write '{src,integration,types}/{**/*,*}.{js,ts}' && npm run lint:fix",
"cross-env": "cross-env"
},
"lint-staged": {
Expand Down
8 changes: 3 additions & 5 deletions src/FacebookUtils.js → src/FacebookUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @flow-weak
*/
/* global FB */
import ParseUser from './ParseUser';
import type { AuthProviderType } from './ParseUser';

let initialized = false;
let requestedPermissions;
let initOptions;
const provider = {
const provider: AuthProviderType = {
authenticate(options) {
if (typeof FB === 'undefined') {
options.error(this, 'Facebook SDK not found.');
Expand Down Expand Up @@ -38,7 +36,7 @@ const provider = {

restoreAuthentication(authData) {
if (authData) {
const newOptions = {};
const newOptions: typeof initOptions = {};
if (initOptions) {
for (const key in initOptions) {
newOptions[key] = initOptions[key];
Expand Down
2 changes: 1 addition & 1 deletion src/LocalDatastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const LocalDatastore = {
},

// Retrieve all pointer fields from object recursively
_getChildren(object: ParseObject) {
_getChildren(object: ParseObject): any {
const encountered = {};
const json = object._toFullJSON(undefined, true);
for (const key in json) {
Expand Down
6 changes: 3 additions & 3 deletions src/ObjectStateMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function estimateAttribute(
if (pendingOps[i][attr]) {
if (pendingOps[i][attr] instanceof RelationOp) {
if (object.id) {
value = pendingOps[i][attr].applyTo(value, object, attr);
value = (pendingOps[i][attr] as RelationOp).applyTo(value, object, attr);
}
} else {
value = pendingOps[i][attr].applyTo(value);
Expand All @@ -110,7 +110,7 @@ export function estimateAttributes(
for (attr in pendingOps[i]) {
if (pendingOps[i][attr] instanceof RelationOp) {
if (object.id) {
data[attr] = pendingOps[i][attr].applyTo(data[attr], object, attr);
data[attr] = (pendingOps[i][attr] as RelationOp).applyTo(data[attr], object, attr);
}
} else {
if (attr.includes('.')) {
Expand All @@ -129,7 +129,7 @@ export function estimateAttributes(
}
} else {
if (Array.isArray(object[key])) {
object[key] = [ ...object[key] ];
object[key] = [...object[key]];
} else {
object[key] = { ...object[key] };
}
Expand Down
9 changes: 2 additions & 7 deletions src/ParseConfig.js → src/ParseConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @flow
*/

import CoreManager from './CoreManager';
import decode from './decode';
import encode from './encode';
Expand All @@ -17,7 +13,6 @@ import type { RequestOptions } from './RESTController';
*
* @alias Parse.Config
*/

class ParseConfig {
attributes: { [key: string]: any };
_escapedAttributes: { [key: string]: any };
Expand Down Expand Up @@ -123,7 +118,7 @@ class ParseConfig {
}
}

let currentConfig = null;
let currentConfig: ParseConfig | null = null;

const CURRENT_CONFIG_KEY = 'currentConfig';

Expand Down Expand Up @@ -195,7 +190,7 @@ const DefaultController = {
});
},

save(attrs: { [key: string]: any }, masterKeyOnlyFlags: { [key: string]: any }) {
save(attrs?: { [key: string]: any }, masterKeyOnlyFlags?: { [key: string]: any }) {
const RESTController = CoreManager.getRESTController();
const encodedAttrs = {};
for (const key in attrs) {
Expand Down
4 changes: 2 additions & 2 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type FetchOptions = {

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

// Global counter for generating unique Ids for non-single-instance objects
let objectCount = 0;
Expand Down Expand Up @@ -412,7 +412,7 @@ class ParseObject {
const pending = stateController.popPendingState(this._getStateIdentifier());
for (attr in pending) {
if (pending[attr] instanceof RelationOp) {
changes[attr] = pending[attr].applyTo(undefined, this, attr);
changes[attr] = (pending[attr] as RelationOp).applyTo(undefined, this, attr);
} else if (!(attr in response)) {
// Only SetOps and UnsetOps should not come back with results
changes[attr] = pending[attr].applyTo(undefined);
Expand Down
31 changes: 14 additions & 17 deletions src/ParseOp.js → src/ParseOp.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* @flow
*/

import arrayContainsObject from './arrayContainsObject';
import decode from './decode';
import encode from './encode';
import CoreManager from './CoreManager';
import type ParseObject from './ParseObject';
import type Pointer from './ParseObject';
import ParseRelation from './ParseRelation';
import unique from './unique';

export function opFromJSON(json: { [key: string]: any }): ?Op {
export function opFromJSON(json: { [key: string]: any }): Op | null {
if (!json || !json.__op) {
return null;
}
Expand Down Expand Up @@ -58,12 +55,12 @@ export function opFromJSON(json: { [key: string]: any }): ?Op {
export class Op {
// Empty parent class
applyTo(value: any): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
mergeWith(previous: Op): ?Op {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
toJSON(): any {}
mergeWith(previous: Op): Op | void {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
toJSON(offline?: boolean): any {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
}

export class SetOp extends Op {
_value: ?any;
_value: any;

constructor(value: any) {
super();
Expand All @@ -78,7 +75,7 @@ export class SetOp extends Op {
return new SetOp(this._value);
}

toJSON(offline?: boolean) {
toJSON(offline?: boolean): any {
return encode(this._value, false, true, undefined, offline);
}
}
Expand Down Expand Up @@ -108,7 +105,7 @@ export class IncrementOp extends Op {
this._amount = amount;
}

applyTo(value: ?any): number {
applyTo(value: any): number {
if (typeof value === 'undefined') {
return this._amount;
}
Expand Down Expand Up @@ -192,7 +189,7 @@ export class AddUniqueOp extends Op {
}
if (Array.isArray(value)) {
const ParseObject = CoreManager.getParseObject();
const toAdd = [];
const toAdd: any[] = [];
this._value.forEach(v => {
if (v instanceof ParseObject) {
if (!arrayContainsObject(value, v)) {
Expand Down Expand Up @@ -301,7 +298,7 @@ export class RemoveOp extends Op {
}

export class RelationOp extends Op {
_targetClassName: ?string;
_targetClassName: string | null;
relationsToAdd: Array<string>;
relationsToRemove: Array<string>;

Expand Down Expand Up @@ -340,7 +337,7 @@ export class RelationOp extends Op {
return obj.id;
}

applyTo(value: any, parent: ParseObject, key?: string): ?ParseRelation {
applyTo(value: any, parent?: ParseObject, key?: string): ParseRelation {
if (!value) {
if (!parent || !key) {
throw new Error(
Expand Down Expand Up @@ -426,17 +423,17 @@ export class RelationOp extends Op {
}

toJSON(): { __op?: string; objects?: any; ops?: any } {
const idToPointer = id => {
const idToPointer = (id: string) => {
return {
__type: 'Pointer',
className: this._targetClassName,
objectId: id,
};
};

let adds = null;
let removes = null;
let pointers = null;
let pointers: any = null;
let adds: null | { __op: string; objects: null | Pointer[] } = null;
let removes: null | { __op: string; objects: null | Pointer[] } = null;

if (this.relationsToAdd.length > 0) {
pointers = this.relationsToAdd.map(idToPointer);
Expand Down
28 changes: 13 additions & 15 deletions src/ParsePolygon.js → src/ParsePolygon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* @flow
*/

import ParseGeoPoint from './ParseGeoPoint';
type Coordinate = [number, number];
type Coordinates = Coordinate[];

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

/**
* @param {(number[][] | Parse.GeoPoint[])} coordinates An Array of coordinate pairs
* @param {(Coordinates | Parse.GeoPoint[])} coordinates An Array of coordinate pairs
*/
constructor(coordinates: Array<Array<number>> | Array<ParseGeoPoint>) {
constructor(coordinates: Coordinates | Array<ParseGeoPoint>) {
this._coordinates = ParsePolygon._validate(coordinates);
}

/**
* Coordinates value for this Polygon.
* Throws an exception if not valid type.
*
* @property {(number[][] | Parse.GeoPoint[])} coordinates list of coordinates
* @returns {number[][]}
* @property {(Coordinates | Parse.GeoPoint[])} coordinates list of coordinates
* @returns {Coordinates}
*/
get coordinates(): Array<Array<number>> {
get coordinates(): Coordinates {
return this._coordinates;
}

set coordinates(coords: Array<Array<number>> | Array<ParseGeoPoint>) {
set coordinates(coords: Coordinates | Array<ParseGeoPoint>) {
this._coordinates = ParsePolygon._validate(coords);
}

Expand All @@ -53,7 +51,7 @@ class ParsePolygon {
*
* @returns {object}
*/
toJSON(): { __type: string; coordinates: Array<Array<number>> } {
toJSON(): { __type: string; coordinates: Coordinates } {
ParsePolygon._validate(this._coordinates);
return {
__type: 'Polygon',
Expand All @@ -67,7 +65,7 @@ class ParsePolygon {
* @param {(Parse.Polygon | object)} other
* @returns {boolean}
*/
equals(other: any): boolean {
equals(other: ParsePolygon | any): boolean {
if (!(other instanceof ParsePolygon) || this.coordinates.length !== other.coordinates.length) {
return false;
}
Expand Down Expand Up @@ -138,14 +136,14 @@ class ParsePolygon {
* @throws {TypeError}
* @returns {number[][]} Array of coordinates if validated.
*/
static _validate(coords: Array<Array<number>> | Array<ParseGeoPoint>): Array<Array<number>> {
static _validate(coords: Coordinates | Array<ParseGeoPoint>): Coordinates {
if (!Array.isArray(coords)) {
throw new TypeError('Coordinates must be an Array');
}
if (coords.length < 3) {
throw new TypeError('Polygon must have at least 3 GeoPoints or Points');
}
const points = [];
const points: Coordinates = [];
for (let i = 0; i < coords.length; i += 1) {
const coord = coords[i];
let geoPoint;
Expand Down
Loading
Loading