Skip to content

Commit

Permalink
chore(core): Add lint script and fix lint issues (#2168)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Nov 12, 2019
1 parent c57da0e commit f08e4a4
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 590 deletions.
846 changes: 287 additions & 559 deletions core/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"docs": "./node_modules/.bin/typedoc --exclude **/__test__/*.ts --json dist/docs.json --mode modules src/core-plugin-definitions.ts && node scripts/docs.js",
"build": "npm run clean && npm run transpile && npm run rollup && npm run minify",
"clean": "rimraf dist",
"lint": "tslint --project tsconfig.json",
"minify": "terser --mangle --compress --source-map \"content='dist/capacitor.js.map',url='capacitor.js.map'\" --comments '/^/*!/' --output dist/capacitor.js dist/capacitor.js",
"prepublishOnly": "npm run build",
"rollup": "rollup --config rollup.config.js",
Expand Down
2 changes: 1 addition & 1 deletion core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface PluginRegistry {

[pluginName: string]: {
[prop: string]: any;
}
};
}

export type ISODateString = string;
Expand Down
6 changes: 3 additions & 3 deletions core/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export interface Capacitor {
isNative?: boolean;
platform?: string;
isPluginAvailable: (name: string) => boolean;
convertFileSrc:(filePath: string) => string;
getPlatform:() => string;
convertFileSrc: (filePath: string) => string;
getPlatform: () => string;
toNative?: (pluginId: string, methodName: string, options: any, storedCallback?: StoredCallback) => void;
fromNative?: (result: PluginResult) => void;
withPlugin?: (pluginId: string, fn: Function) => void;
Expand Down Expand Up @@ -100,4 +100,4 @@ export interface WindowCapacitor {
window: any;
}

export { PluginRegistry };
export { PluginRegistry };
2 changes: 1 addition & 1 deletion core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const extend = (target: any, ...objs: any[]) => {

export const uuid4 = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
2 changes: 1 addition & 1 deletion core/src/web-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CapacitorWeb {
isNative = false;

constructor() {
// Need to assign here to avoid having to define every plugin but still
// Need to assign here to avoid having to define every plugin but still
// get the typed benefits of the provided plugins in PluginRegistry
this.Plugins = {} as any;

Expand Down
2 changes: 1 addition & 1 deletion core/src/web/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AppPluginWeb extends WebPlugin implements AppPlugin {
return Promise.resolve({ url: '' });
}

handleVisibilityChange():void {
handleVisibilityChange(): void {
const data = {
isActive: document.hidden !== true
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/web/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class BrowserPluginWeb extends WebPlugin implements BrowserPlugin {
}

async open(options: BrowserOpenOptions): Promise<void> {
this._lastWindow = window.open(options.url, options.windowName || "_blank");
this._lastWindow = window.open(options.url, options.windowName || '_blank');
return Promise.resolve();
}

Expand Down
8 changes: 3 additions & 5 deletions core/src/web/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
CameraResultType
} from '../core-plugin-definitions';

//import '@ionic/pwa-elements';

export class CameraPluginWeb extends WebPlugin implements CameraPlugin {
constructor() {
super({
Expand Down Expand Up @@ -46,8 +44,8 @@ export class CameraPluginWeb extends WebPlugin implements CameraPlugin {
private _getCameraPhoto(photo: Blob, options: CameraOptions) {
return new Promise<CameraPhoto>((resolve, reject) => {
var reader = new FileReader();
var format = photo.type.split('/')[1]
if (options.resultType == CameraResultType.Uri) {
var format = photo.type.split('/')[1];
if (options.resultType === CameraResultType.Uri) {
resolve({
webPath: URL.createObjectURL(photo),
format: format
Expand All @@ -56,7 +54,7 @@ export class CameraPluginWeb extends WebPlugin implements CameraPlugin {
reader.readAsDataURL(photo);
reader.onloadend = () => {
const r = reader.result as string;
if (options.resultType == CameraResultType.DataUrl) {
if (options.resultType === CameraResultType.DataUrl) {
resolve({
dataUrl: r,
format: format
Expand Down
2 changes: 1 addition & 1 deletion core/src/web/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ClipboardPluginWeb extends WebPlugin implements ClipboardPlugin {
if (options.string || options.url) {
await navigator.clipboard.writeText(options.string || options.url);
} else if (options.image) {
return Promise.reject("Setting images not supported on the web");
return Promise.reject('Setting images not supported on the web');
}
return Promise.resolve();
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/web/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ export class DevicePluginWeb extends WebPlugin implements DevicePlugin {
async getLanguageCode(): Promise<DeviceLanguageCodeResult> {
return {
value: navigator.language
}
};
}

parseUa(_ua: string) {
let uaFields: any = {};
const start = _ua.indexOf('(')+1;
const start = _ua.indexOf('(') + 1;
let end = _ua.indexOf(') AppleWebKit');
if (_ua.indexOf(') Gecko') !== -1) {
end = _ua.indexOf(') Gecko');
}
const fields = _ua.substring(start, end);
if (_ua.indexOf('Android') !== -1) {
uaFields.model = fields.replace("; wv", "").split("; ").pop().split(' Build')[0];
uaFields.model = fields.replace('; wv', '').split('; ').pop().split(' Build')[0];
uaFields.osVersion = fields.split('; ')[1];
} else {
uaFields.model = fields.split('; ')[0];
Expand All @@ -68,8 +68,8 @@ export class DevicePluginWeb extends WebPlugin implements DevicePlugin {
if (_ua.indexOf('Windows') !== -1) {
uaFields.osVersion = fields;
} else {
let lastParts = fields.split('; ').pop().replace(" like Mac OS X", "").split(" ");
uaFields.osVersion = lastParts[lastParts.length-1].replace(/_/g, ".");
let lastParts = fields.split('; ').pop().replace(' like Mac OS X', '').split(' ');
uaFields.osVersion = lastParts[lastParts.length - 1].replace(/_/g, '.');
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/web/local-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class LocalNotificationsPluginWeb extends WebPlugin implements LocalNotif
});

return Promise.resolve({
notifications: notifications.map(_ => { return { id: '' }})
notifications: notifications.map(_ => { return { id: '' }; })
});
}

Expand All @@ -75,13 +75,13 @@ export class LocalNotificationsPluginWeb extends WebPlugin implements LocalNotif
notifications: this.pending.map(localNotification => {
return {
id: '' + localNotification.id
}
};
})
});
}

registerActionTypes(_options: { types: LocalNotificationActionType[]; }): Promise<void> {
throw new Error("Method not implemented.");
throw new Error('Method not implemented.');
}

cancel(pending: LocalNotificationPendingList): Promise<void> {
Expand All @@ -92,14 +92,14 @@ export class LocalNotificationsPluginWeb extends WebPlugin implements LocalNotif
}

areEnabled(): Promise<LocalNotificationEnabledResult> {
throw new Error("Method not implemented.");
throw new Error('Method not implemented.');
}


requestPermissions(): Promise<PermissionsRequestResult> {
return new Promise((resolve, reject) => {
Notification.requestPermission().then((result) => {
if(result === 'denied' || result === 'default') {
if (result === 'denied' || result === 'default') {
reject(result);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/web/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
/*
MotionEventResult,
MotionWatchAccelCallback,
MotionWatchOrientationCallback,
MotionWatchOrientationCallback,
MotionOrientationEventResult
*/
} from '../core-plugin-definitions';
Expand Down
2 changes: 1 addition & 1 deletion core/src/web/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class NetworkPluginWeb extends WebPlugin implements NetworkPlugin {
let onlineBindFunc = listenerFunc.bind(thisRef, { connected: true, connectionType: connectionType });
let offlineBindFunc = listenerFunc.bind(thisRef, { connected: false, connectionType: 'none' });

if(eventName.localeCompare('networkStatusChange') === 0) {
if (eventName.localeCompare('networkStatusChange') === 0) {
window.addEventListener('online', onlineBindFunc);
window.addEventListener('offline', offlineBindFunc);
return {
Expand Down
4 changes: 2 additions & 2 deletions core/src/web/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ShareOptions
} from '../core-plugin-definitions';

declare var navigator:any;
declare var navigator: any;

export class SharePluginWeb extends WebPlugin implements SharePlugin {
constructor() {
Expand All @@ -17,7 +17,7 @@ export class SharePluginWeb extends WebPlugin implements SharePlugin {

share(options?: ShareOptions): Promise<void> {
if (!navigator.share) {
return Promise.reject("Web Share API not available");
return Promise.reject('Web Share API not available');
}

return navigator.share({
Expand Down
6 changes: 3 additions & 3 deletions core/src/web/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {


export class StoragePluginWeb extends WebPlugin implements StoragePlugin {
KEY_PREFIX = "_cap_";
KEY_PREFIX = '_cap_';

constructor() {
super({
Expand All @@ -20,14 +20,14 @@ export class StoragePluginWeb extends WebPlugin implements StoragePlugin {
resolve({
value: window.localStorage.getItem(this.makeKey(options.key))
});
})
});
}

set(options: { key: string, value: string }): Promise<void> {
return new Promise((resolve, _reject) => {
window.localStorage.setItem(this.makeKey(options.key), options.value);
resolve();
})
});
}

remove(options: { key: string }): Promise<void> {
Expand Down

0 comments on commit f08e4a4

Please sign in to comment.