Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Commit

Permalink
chore: integrate prettier with lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
adieuadieu committed Aug 2, 2017
1 parent 091e613 commit e01c57a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 59 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"clean": "rimraf dist",
"precommit": "lint-staged",
"prepublishOnly": "npm test && npm run build",
"prettier": "prettier --single-quote --trailing-comma all --write \"src/**/*.ts\"",
"prettier": "prettier --no-semi --single-quote --trailing-comma all --write \"src/**/*.ts\"",
"release": "np",
"test": "npm run tslint",
"tslint": "tslint -c tslint.json -p tsconfig.json --exclude node_modules/**"
Expand All @@ -52,8 +52,9 @@
"typescript": "^2.4.2"
},
"lint-staged": {
"*.ts": [
"prettier --single-quote --trailing-comma all --write",
"*.{ts,js}": [
"prettier --no-semi --single-quote --trailing-comma all --write",
"npm run lint",
"git add"
]
}
Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class Chromeless<T extends any> implements Promise<T> {

then<U>(
onFulfill: (value: T) => U | PromiseLike<U>,
onReject?: (error: any) => U | PromiseLike<U>
onReject?: (error: any) => U | PromiseLike<U>,
): Promise<U> {
return this.lastReturnPromise.then(onFulfill, onReject) as Promise<U>
}
Expand Down Expand Up @@ -233,7 +233,7 @@ export default class Chromeless<T extends any> implements Promise<T> {
*/
cookiesGet(query: CookieQuery): Chromeless<Cookie[] | null>
cookiesGet(
nameOrQuery?: string | CookieQuery
nameOrQuery?: string | CookieQuery,
): Chromeless<Cookie | Cookie[] | null> {
if (typeof nameOrQuery !== 'undefined') {
throw new Error('Querying cookies is not implemented yet')
Expand Down
14 changes: 7 additions & 7 deletions src/chrome/local-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class LocalRuntime {
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout
this.chromelessOptions.waitTimeout,
)
}

Expand Down Expand Up @@ -159,14 +159,14 @@ export default class LocalRuntime {
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout
this.chromelessOptions.waitTimeout,
)
}

const exists = await nodeExists(this.client, selector)
if (!exists) {
throw new Error(
`mousedown(): node for selector ${selector} doesn't exist`
`mousedown(): node for selector ${selector} doesn't exist`,
)
}

Expand All @@ -181,7 +181,7 @@ export default class LocalRuntime {
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout
this.chromelessOptions.waitTimeout,
)
}

Expand All @@ -205,7 +205,7 @@ export default class LocalRuntime {
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout
this.chromelessOptions.waitTimeout,
)
}

Expand All @@ -225,7 +225,7 @@ export default class LocalRuntime {
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout
this.chromelessOptions.waitTimeout,
)
}

Expand All @@ -248,7 +248,7 @@ export default class LocalRuntime {

async cookiesSet(
nameOrCookies: string | Cookie | Cookie[],
value?: string
value?: string,
): Promise<void> {
if (typeof nameOrCookies !== 'string' && !value) {
const cookies = Array.isArray(nameOrCookies)
Expand Down
4 changes: 2 additions & 2 deletions src/chrome/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export default class LocalChrome implements Chrome {
} else {
config.height = await evaluate(
client,
(() => window.innerHeight).toString()
(() => window.innerHeight).toString(),
)
config.width = await evaluate(
client,
(() => window.innerWidth).toString()
(() => window.innerWidth).toString(),
)
}

Expand Down
18 changes: 9 additions & 9 deletions src/chrome/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getEndpoint(remoteOptions: RemoteOptions | boolean): RemoteOptions {
}

throw new Error(
'No Chromeless remote endpoint & API key provided. Either set as "remote" option in constructor or set as "CHROMELESS_ENDPOINT_URL" and "CHROMELESS_ENDPOINT_API_KEY" env variables.'
'No Chromeless remote endpoint & API key provided. Either set as "remote" option in constructor or set as "CHROMELESS_ENDPOINT_URL" and "CHROMELESS_ENDPOINT_API_KEY" env variables.',
)
}

Expand Down Expand Up @@ -53,8 +53,8 @@ export default class RemoteChrome implements Chrome {

reject(
new Error(
"Timed out after 30sec. Connection couldn't be established."
)
"Timed out after 30sec. Connection couldn't be established.",
),
)
}, 30000)

Expand Down Expand Up @@ -109,7 +109,7 @@ export default class RemoteChrome implements Chrome {
channel.publish(
this.TOPIC_NEW_SESSION,
JSON.stringify({ channelId, options: this.options }),
{ qos: 1 }
{ qos: 1 },
)
})

Expand All @@ -121,16 +121,16 @@ export default class RemoteChrome implements Chrome {

if (data.outOfTime) {
console.warn(
`Chromeless Proxy disconnected because it reached it's execution time limit (5 minutes).`
`Chromeless Proxy disconnected because it reached it's execution time limit (5 minutes).`,
)
} else if (data.inactivity) {
console.warn(
'Chromeless Proxy disconnected due to inactivity (no commands sent for 30 seconds).'
'Chromeless Proxy disconnected due to inactivity (no commands sent for 30 seconds).',
)
} else {
console.warn(
`Chromeless Proxy disconnected (we don't know why).`,
data
data,
)
}

Expand All @@ -143,7 +143,7 @@ export default class RemoteChrome implements Chrome {
console.error(error)

reject(
new Error('Unable to get presigned websocket URL and connect to it.')
new Error('Unable to get presigned websocket URL and connect to it.'),
)
}
})
Expand Down Expand Up @@ -183,7 +183,7 @@ export default class RemoteChrome implements Chrome {
async close(): Promise<void> {
this.channel.publish(
this.TOPIC_END,
JSON.stringify({ channelId: this.channelId, client: true })
JSON.stringify({ channelId: this.channelId, client: true }),
)

this.channel.end()
Expand Down
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import LocalChrome from './chrome/local'
import { version } from './util'
import { Cookie, ChromelessOptions } from './types'

export {
Queue,
LocalChrome,
Chromeless,
Cookie,
ChromelessOptions,
version,
}
export { Queue, LocalChrome, Chromeless, Cookie, ChromelessOptions, version }

export default Chromeless
32 changes: 16 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export type Command =
type: 'returnHtml'
}
| {
type: 'returnPdf',
type: 'returnPdf'
options?: PdfOptions
}
| {
Expand All @@ -95,7 +95,7 @@ export type Command =
y: number
}
| {
type: 'setHtml',
type: 'setHtml'
html: string
}
| {
Expand Down Expand Up @@ -125,15 +125,15 @@ export type Command =
nameOrQuery?: string | CookieQuery
}
| {
type: 'mousedown',
type: 'mousedown'
selector: string
}
| {
type: 'mouseup',
type: 'mouseup'
selector: string
}
| {
type: 'focus',
type: 'focus'
selector: string
}

Expand Down Expand Up @@ -162,16 +162,16 @@ export interface CookieQuery {

// https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF
export interface PdfOptions {
landscape?: boolean,
displayHeaderFooter?: boolean,
printBackground?: boolean,
scale?: number,
paperWidth?: number,
paperHeight?: number,
marginTop?: number,
marginBottom?: number,
marginLeft?: number,
marginRight?: number,
pageRanges?: string,
landscape?: boolean
displayHeaderFooter?: boolean
printBackground?: boolean
scale?: number
paperWidth?: number
paperHeight?: number
marginTop?: number
marginBottom?: number
marginLeft?: number
marginRight?: number
pageRanges?: string
ignoreInvalidPageRanges?: boolean
}
24 changes: 12 additions & 12 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const version: string = ((): string => {
export async function waitForNode(
client: Client,
selector: string,
waitTimeout: number
waitTimeout: number,
): Promise<void> {
const { Runtime } = client
const getNode = selector => {
Expand All @@ -33,7 +33,7 @@ export async function waitForNode(
if (new Date().getTime() - start > waitTimeout) {
clearInterval(interval)
reject(
new Error(`wait("${selector}") timed out after ${waitTimeout}ms`)
new Error(`wait("${selector}") timed out after ${waitTimeout}ms`),
)
}

Expand All @@ -58,7 +58,7 @@ export async function wait(timeout: number): Promise<void> {

export async function nodeExists(
client: Client,
selector: string
selector: string,
): Promise<boolean> {
const { Runtime } = client
const exists = selector => {
Expand Down Expand Up @@ -164,7 +164,7 @@ export async function evaluate<T>(
if (result && result.exceptionDetails) {
throw new Error(
result.exceptionDetails.exception.value ||
result.exceptionDetails.exception.description
result.exceptionDetails.exception.description,
)
}

Expand All @@ -178,7 +178,7 @@ export async function evaluate<T>(
export async function type(
client: Client,
text: string,
selector?: string
selector?: string,
): Promise<void> {
if (selector) {
await focus(client, selector)
Expand All @@ -202,7 +202,7 @@ export async function press(
client: Client,
keyCode: number,
count?: number,
modifiers?: any
modifiers?: any,
): Promise<void> {
const { Input } = client

Expand Down Expand Up @@ -233,7 +233,7 @@ export async function press(

export async function getValue(
client: Client,
selector: string
selector: string,
): Promise<string> {
const { Runtime } = client
const browserCode = selector => {
Expand All @@ -250,7 +250,7 @@ export async function getValue(
export async function scrollTo(
client: Client,
x: number,
y: number
y: number,
): Promise<void> {
const { Runtime } = client
const browserCode = (x, y) => {
Expand All @@ -271,7 +271,7 @@ export async function setHtml(client: Client, html: string): Promise<void> {

export async function getCookies(
client: Client,
nameOrQuery?: string | Cookie
nameOrQuery?: string | Cookie,
): Promise<any> {
if (nameOrQuery) {
throw new Error('Not yet implemented')
Expand All @@ -296,7 +296,7 @@ export async function getAllCookies(client: Client): Promise<any> {

export async function setCookies(
client: Client,
cookies: Cookie[]
cookies: Cookie[],
): Promise<void> {
const { Network } = client

Expand All @@ -311,7 +311,7 @@ export async function setCookies(
export async function mousedown(
client: Client,
selector: string,
scale: number
scale: number,
) {
const clientRect = await getClientRect(client, selector)
const { Input } = client
Expand Down Expand Up @@ -375,7 +375,7 @@ export async function html(client: Client): Promise<string> {

export async function pdf(
client: Client,
options?: PdfOptions
options?: PdfOptions,
): Promise<string> {
const { Page } = client

Expand Down

0 comments on commit e01c57a

Please sign in to comment.