Skip to content

Commit

Permalink
add linter rule typescript/member-ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
andykais committed Jan 19, 2019
1 parent 6a180ed commit 35abcbf
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 93 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"no-console": "warn",
"typescript/no-unused-vars": "error",
"typescript/explicit-member-accessibility": "error",
"typescript/member-ordering": "error",
"no-only-tests/no-only-tests": "error"
}
}
52 changes: 26 additions & 26 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions src/scraper/scrape-step/downloader/implementations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ type FetchFunction = (
export class Downloader extends AbstractDownloader<DownloadData> {
private urlTemplate: ReturnType<typeof compileTemplate>
private headerTemplates: Map<string, ReturnType<typeof compileTemplate>>
private verifyResponseOk = (response: Fetch.Response, url: string) => {
if (!response.ok) {
throw new Error(`status ${response.status} for ${url}`)
}
}
private fetcher: FetchFunction

public constructor(config: ScrapeConfig, options: Options, tools: Tools) {
Expand Down Expand Up @@ -80,6 +75,11 @@ export class Downloader extends AbstractDownloader<DownloadData> {
return this.fetcher(downloadId, downloadData)
}

private verifyResponseOk = (response: Fetch.Response, url: string) => {
if (!response.ok) {
throw new Error(`status ${response.status} for ${url}`)
}
}
private downloadToFileAndMemory: FetchFunction = async (
downloadId,
[url, fetchOptions]
Expand Down
31 changes: 16 additions & 15 deletions src/scraper/scrape-step/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Rx from 'rxjs'
import * as ops from 'rxjs/operators'
import VError from 'verror'
import { downloaderClassFactory } from './downloader'
import { parserClassFactory } from './parser'
import { incrementer } from './incrementer'
Expand Down Expand Up @@ -69,6 +68,22 @@ class ScrapeStep extends AbstractScrapeStep {
scrapeNextChild
)
}

public run: typeof AbstractScrapeStep.prototype.run = (
parentValues: ParsedValue[]
): Rx.Observable<ParsedValue[]> =>
Rx.from(parentValues).pipe(
ops.flatMap(this.incrementObservableFunction),
ops.catchError(wrapError(`scraper '${this.scraperName}'`)),
ops.flatMap(
parsedValues =>
this.children.length
? this.children.map(child => child.run(parsedValues))
: [Rx.of(parsedValues)]
),
ops.mergeAll()
)

private downloadParseFunction: DownloadParseFunction = async (
{ parsedValue: value, id: parentId },
incrementIndex
Expand Down Expand Up @@ -115,20 +130,6 @@ class ScrapeStep extends AbstractScrapeStep {
return parsedValuesWithId
}
}
public run: typeof AbstractScrapeStep.prototype.run = (
parentValues: ParsedValue[]
): Rx.Observable<ParsedValue[]> =>
Rx.from(parentValues).pipe(
ops.flatMap(this.incrementObservableFunction),
ops.catchError(wrapError(`scraper '${this.scraperName}'`)),
ops.flatMap(
parsedValues =>
this.children.length
? this.children.map(child => child.run(parsedValues))
: [Rx.of(parsedValues)]
),
ops.mergeAll()
)
}

export { ScrapeStep, IdentityScrapeStep }
12 changes: 6 additions & 6 deletions src/scraper/scrape-step/parser/implementations/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { Tools } from '../../../../tools'
export class Parser extends AbstractParser {
private parser: (value: string) => string[]

public constructor(config: ScrapeConfig, options: Options, tools: Tools) {
super(config, options, tools)
this.parser = this.attribute ? this.selectAttrVals : this.selectTextVals
}
protected parse = (value: string) => this.parser(value)

private selectTextVals = (value: string) => {
const $ = cheerio.load(value)
const values: string[] = []
Expand All @@ -26,10 +32,4 @@ export class Parser extends AbstractParser {
})
return values
}
protected parse = (value: string) => this.parser(value)

public constructor(config: ScrapeConfig, options: Options, tools: Tools) {
super(config, options, tools)
this.parser = this.attribute ? this.selectAttrVals : this.selectTextVals
}
}
Loading

0 comments on commit 35abcbf

Please sign in to comment.