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

Commit ab42dd7

Browse files
committed
chore: update prettier config
- update prettier - remove conflicting tslint rules - prettify json files - add editorconfig - move prettier config to config files for editors to pick up - run prettier check in CI
1 parent d6e9bfa commit ab42dd7

File tree

10 files changed

+96
-127
lines changed

10 files changed

+96
-127
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
[*]
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
end_of_line = lf

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.nyc_output/
2+
*.md
3+
dist/
4+
package.json
5+
package-lock.json
6+
serverless/

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"coverage": "npm run ava",
2727
"precommit": "lint-staged",
2828
"prepublishOnly": "npm test && npm run build",
29-
"prettier": "prettier --no-semi --single-quote --trailing-comma all --write \"src/**/*.ts\"",
29+
"prettier": "prettier --list-different --write \"**/*.{ts,json}\"",
3030
"release": "np",
31-
"test": "npm run tslint && npm run ava",
32-
"lint": "npm run tslint",
31+
"test": "npm run lint && npm run ava",
32+
"lint": "npm run prettier && npm run tslint",
3333
"tslint": "tslint -c tslint.json -p tsconfig.json --exclude node_modules/**",
3434
"watch": "tsc -w",
3535
"watch:test": "tsc -d -w & ava --watch"
@@ -52,7 +52,7 @@
5252
"lint-staged": "^4.0.2",
5353
"np": "^2.16.0",
5454
"nyc": "^11.1.0",
55-
"prettier": "^1.5.3",
55+
"prettier": "1.9.2",
5656
"rimraf": "^2.6.1",
5757
"tslint": "^5.5.0",
5858
"typescript": "^2.4.2"

src/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ export default class Chromeless<T extends any> implements Promise<T> {
101101
break
102102
}
103103
case 'string': {
104-
this.queue.enqueue({ type: 'wait', selector: firstArg, timeout: args[0] })
104+
this.queue.enqueue({
105+
type: 'wait',
106+
selector: firstArg,
107+
timeout: args[0],
108+
})
105109
break
106110
}
107111
case 'function': {

src/chrome/local-runtime.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default class LocalRuntime {
154154

155155
private async waitSelector(
156156
selector: string,
157-
waitTimeout: number = this.chromelessOptions.waitTimeout
157+
waitTimeout: number = this.chromelessOptions.waitTimeout,
158158
): Promise<void> {
159159
this.log(`Waiting for ${selector} ${waitTimeout}`)
160160
await waitForNode(this.client, selector, waitTimeout)
@@ -403,10 +403,7 @@ export default class LocalRuntime {
403403

404404
// Returns the S3 url or local file path
405405
async returnPdf(options?: PdfOptions): Promise<string> {
406-
const {
407-
filePath,
408-
...cdpOptions
409-
} = options || { filePath: undefined }
406+
const { filePath, ...cdpOptions } = options || { filePath: undefined }
410407
const data = await pdf(this.client, cdpOptions)
411408

412409
if (isS3Configured()) {

src/util.test.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ const testUrl = `data:text/html,${testHtml}`
99

1010
const getPngMetaData = async (filePath): Promise<any> => {
1111
const fd = fs.openSync(filePath, 'r')
12-
return await new Promise((resolve) => {
13-
fs.read(fd, Buffer.alloc(24), 0, 24, 0,
14-
(err, bytesRead, buffer) => resolve({
15-
width: buffer.readUInt32BE(16),
16-
height: buffer.readUInt32BE(20)
17-
}))
12+
return await new Promise(resolve => {
13+
fs.read(fd, Buffer.alloc(24), 0, 24, 0, (err, bytesRead, buffer) =>
14+
resolve({
15+
width: buffer.readUInt32BE(16),
16+
height: buffer.readUInt32BE(20),
17+
}),
18+
)
1819
})
1920
}
2021

2122
// POC
2223
test('evaluate (document.title)', async t => {
2324
const chromeless = new Chromeless({ launchChrome: false })
24-
const title = await chromeless
25-
.goto(testUrl)
26-
.evaluate(() => document.title)
25+
const title = await chromeless.goto(testUrl).evaluate(() => document.title)
2726

2827
await chromeless.end()
2928

@@ -32,12 +31,8 @@ test('evaluate (document.title)', async t => {
3231

3332
test('screenshot and pdf path', async t => {
3433
const chromeless = new Chromeless({ launchChrome: false })
35-
const screenshot = await chromeless
36-
.goto(testUrl)
37-
.screenshot()
38-
const pdf = await chromeless
39-
.goto(testUrl)
40-
.pdf()
34+
const screenshot = await chromeless.goto(testUrl).screenshot()
35+
const pdf = await chromeless.goto(testUrl).pdf()
4136

4237
await chromeless.end()
4338

@@ -48,18 +43,16 @@ test('screenshot and pdf path', async t => {
4843
})
4944

5045
test('screenshot by selector', async t => {
51-
const version = await CDP.Version()
52-
const versionMajor = parseInt(/Chrome\/(\d+)/.exec(version['User-Agent'])[1])
53-
// clipping will only work on chrome 61+
46+
const version = await CDP.Version()
47+
const versionMajor = parseInt(/Chrome\/(\d+)/.exec(version['User-Agent'])[1])
48+
// clipping will only work on chrome 61+
5449

55-
const chromeless = new Chromeless({ launchChrome: false })
56-
const screenshot = await chromeless
57-
.goto(testUrl)
58-
.screenshot('img')
50+
const chromeless = new Chromeless({ launchChrome: false })
51+
const screenshot = await chromeless.goto(testUrl).screenshot('img')
5952

60-
await chromeless.end()
53+
await chromeless.end()
6154

62-
const png = await getPngMetaData(screenshot)
63-
t.is(png.width, versionMajor > 60 ? 512 : 1440)
64-
t.is(png.height, versionMajor > 60 ? 512 : 900)
55+
const png = await getPngMetaData(screenshot)
56+
t.is(png.width, versionMajor > 60 ? 512 : 1440)
57+
t.is(png.height, versionMajor > 60 ? 512 : 900)
6558
})

src/util.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import * as fs from 'fs'
22
import * as os from 'os'
33
import * as path from 'path'
44
import * as cuid from 'cuid'
5-
import { Client, Cookie, DeviceMetrics, PdfOptions, BoxModel, Viewport, Headers } from './types'
5+
import {
6+
Client,
7+
Cookie,
8+
DeviceMetrics,
9+
PdfOptions,
10+
BoxModel,
11+
Viewport,
12+
Headers,
13+
} from './types'
614
import * as CDP from 'chrome-remote-interface'
715
import * as AWS from 'aws-sdk'
816

@@ -564,8 +572,13 @@ export function getDebugOption(): boolean {
564572
return false
565573
}
566574

567-
export function writeToFile(data: string, extension: string, filePathOverride: string): string {
568-
const filePath = filePathOverride || path.join(os.tmpdir(), `${cuid()}.${extension}`)
575+
export function writeToFile(
576+
data: string,
577+
extension: string,
578+
filePathOverride: string,
579+
): string {
580+
const filePath =
581+
filePathOverride || path.join(os.tmpdir(), `${cuid()}.${extension}`)
569582
fs.writeFileSync(filePath, Buffer.from(data, 'base64'))
570583
return filePath
571584
}
@@ -588,29 +601,32 @@ export function isS3Configured() {
588601

589602
const s3ContentTypes = {
590603
'image/png': {
591-
extension: 'png'
604+
extension: 'png',
592605
},
593606
'application/pdf': {
594-
extension: 'pdf'
607+
extension: 'pdf',
595608
},
596609
}
597610

598-
export async function uploadToS3(data: string, contentType: string): Promise<string> {
611+
export async function uploadToS3(
612+
data: string,
613+
contentType: string,
614+
): Promise<string> {
599615
const s3ContentType = s3ContentTypes[contentType]
600616
if (!s3ContentType) {
601617
throw new Error(`Unknown S3 Content type ${contentType}`)
602618
}
603619
const s3Path = `${getS3ObjectKeyPrefix()}${cuid()}.${s3ContentType.extension}`
604620
const s3 = new AWS.S3()
605621
await s3
606-
.putObject({
607-
Bucket: getS3BucketName(),
608-
Key: s3Path,
609-
ContentType: contentType,
610-
ACL: 'public-read',
611-
Body: Buffer.from(data, 'base64'),
612-
})
613-
.promise()
622+
.putObject({
623+
Bucket: getS3BucketName(),
624+
Key: s3Path,
625+
ContentType: contentType,
626+
ACL: 'public-read',
627+
Body: Buffer.from(data, 'base64'),
628+
})
629+
.promise()
614630

615631
return `https://${getS3BucketUrl()}/${s3Path}`
616-
}
632+
}

tsconfig.json

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs",
4-
"target": "es5",
5-
"moduleResolution": "node",
6-
"sourceMap": true,
7-
"outDir": "dist",
8-
"lib": [
9-
"es6",
10-
"dom"
11-
],
12-
"strictNullChecks": false,
13-
"pretty": true,
14-
"rootDir": ".",
15-
"forceConsistentCasingInFileNames": true
16-
},
17-
"exclude": [
18-
"node_modules",
19-
"node_modules/**",
20-
"dist"
21-
],
22-
"include": [
23-
"./src/**/*.ts",
24-
"./examples/**/*.ts"
25-
]
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"outDir": "dist",
8+
"lib": ["es6", "dom"],
9+
"strictNullChecks": false,
10+
"pretty": true,
11+
"rootDir": ".",
12+
"forceConsistentCasingInFileNames": true
13+
},
14+
"exclude": ["node_modules", "node_modules/**", "dist"],
15+
"include": ["./src/**/*.ts", "./examples/**/*.ts"]
2616
}

tslint.json

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,11 @@
1-
21
{
32
"rules": {
43
"class-name": true,
5-
"comment-format": [
6-
true,
7-
"check-space"
8-
],
9-
"indent": [
10-
true,
11-
"spaces"
12-
],
13-
"one-line": [
14-
true,
15-
"check-open-brace",
16-
"check-whitespace"
17-
],
4+
"comment-format": [true, "check-space"],
185
"no-var-keyword": true,
19-
"quotemark": [
20-
true,
21-
"single",
22-
"avoid-escape"
23-
],
24-
"semicolon": [
25-
true,
26-
"never",
27-
"ignore-bound-class-methods"
28-
],
29-
"whitespace": [
30-
true,
31-
"check-branch",
32-
"check-decl",
33-
"check-operator",
34-
"check-module",
35-
"check-separator",
36-
"check-type"
37-
],
38-
"typedef-whitespace": [
39-
true,
40-
{
41-
"call-signature": "nospace",
42-
"index-signature": "nospace",
43-
"parameter": "nospace",
44-
"property-declaration": "nospace",
45-
"variable-declaration": "nospace"
46-
},
47-
{
48-
"call-signature": "onespace",
49-
"index-signature": "onespace",
50-
"parameter": "onespace",
51-
"property-declaration": "onespace",
52-
"variable-declaration": "onespace"
53-
}
54-
],
556
"no-internal-module": true,
56-
"no-trailing-whitespace": true,
577
"no-null-keyword": false,
588
"prefer-const": true,
599
"jsdoc-format": true
6010
}
61-
}
11+
}

0 commit comments

Comments
 (0)