Skip to content

style(*): Automate Code Formatting #90

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 5 commits into from
Jul 25, 2017
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
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build:package": "gulp build && cd dist/package && npm install --production && npm shrinkwrap && npm pack && shx mv *.tgz ../",
"test": "gulp build && gulp build:tests && gulp test && gulp test:integration",
"dev": "gulp dev",
"commitmsg": "validate-commit-msg"
"commitmsg": "validate-commit-msg",
"precommit": "lint-staged"
},
"main": "index.js",
"devDependencies": {
Expand Down Expand Up @@ -69,8 +70,10 @@
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.30",
"karma-typescript": "^3.0.4",
"lint-staged": "^4.0.0",
"merge2": "^1.0.3",
"mkdirp": "^0.5.1",
"prettier": "^1.5.1",
"require-dir": "^0.3.1",
"rimraf": "^2.6.1",
"shx": "^0.2.2",
Expand Down Expand Up @@ -98,5 +101,11 @@
"cz-customizable": {
"config": "./.cz-config.js"
}
},
"lint-staged": {
"**/*.ts": [
"prettier --write --single-quote",
"git add"
]
}
}
7 changes: 2 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
* limitations under the License.
*/
// Import the createFirebaseNamespace function
import {
createFirebaseNamespace,
FirebaseNamespace
} from './app/firebase_app';
import { createFirebaseNamespace, FirebaseNamespace } from './app/firebase_app';

// Export a single instance of firebase app
const firebase: FirebaseNamespace = createFirebaseNamespace();

export default firebase;
export default firebase;
38 changes: 19 additions & 19 deletions src/app/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
* }
* }
*/
export type ErrorList<T> = {[code: string]: string};
export type ErrorList<T> = { [code: string]: string };

const ERROR_NAME = 'FirebaseError';

export interface StringLike {
toString: () => string;
}

let captureStackTrace: (obj: Object, fn?: Function) => void =
(Error as any).captureStackTrace;
let captureStackTrace: (obj: Object, fn?: Function) => void = (Error as any)
.captureStackTrace;

// Export for faking in tests
export function patchCapture(captureFake?: any): any {
Expand All @@ -73,24 +73,23 @@ export function patchCapture(captureFake?: any): any {

export interface FirebaseError {
// Unique code for error - format is service/error-code-string
code: string,
code: string;

// Developer-friendly error message.
message: string,
message: string;

// Always 'FirebaseError'
name: string,
name: string;

// Where available - stack backtrace in a string
stack: string,
stack: string;
}

export class FirebaseError implements FirebaseError {
public stack: string;
public name: string;

constructor(public code: string,
public message: string) {
constructor(public code: string, public message: string) {
let stack: string;
// We want the stack value, if implemented by Error
if (captureStackTrace) {
Expand All @@ -116,31 +115,32 @@ FirebaseError.prototype.constructor = FirebaseError;

export class ErrorFactory<T extends string> {
// Matches {$name}, by default.
public pattern = /\{\$([^}]+)}/g
public pattern = /\{\$([^}]+)}/g;

constructor(private service: string,
private serviceName: string,
private errors: ErrorList<T>) {
constructor(
private service: string,
private serviceName: string,
private errors: ErrorList<T>
) {
// empty
}

create(code: T, data?: {[prop: string]: StringLike}): FirebaseError {
create(code: T, data?: { [prop: string]: StringLike }): FirebaseError {
if (data === undefined) {
data = {};
}

let template = this.errors[(code as string)];
let template = this.errors[code as string];

let fullCode = this.service + '/' + code;
let message: string;

if (template === undefined) {
message = "Error";
message = 'Error';
} else {
message = template.replace(this.pattern, (match, key) => {
let value = data![key];
return value !== undefined ? value.toString()
: '<' + key + '?>';
return value !== undefined ? value.toString() : '<' + key + '?>';
});
}

Expand All @@ -159,4 +159,4 @@ export class ErrorFactory<T extends string> {

return err;
}
}
}
Loading