Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed May 2, 2019
1 parent 7f090b4 commit 29c8e71
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 287 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm install --save ad-block

```javascript

const {AdBlockClient, FilterOptions} = require('ad-block')
const { AdBlockClient, FilterOptions } = require('ad-block')
const client = new AdBlockClient()
client.parse('/public/ad/*$domain=slashdot.org')
client.parse('/public/ad3/*$script')
Expand Down
24 changes: 9 additions & 15 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const request = require('request')
const {sanitizeABPInput} = require('./filtering')
const { sanitizeABPInput } = require('./filtering')
const fs = require('fs')
const {AdBlockClient, adBlockLists} = require('..')
const { AdBlockClient, adBlockLists } = require('..')

/**
* Builds an adblock client, given one or more strings containing filter rules.
Expand Down Expand Up @@ -62,13 +62,11 @@ const getSingleListDataFromSingleURL = (listURL, filter, options) => {
return new Promise((resolve, reject) => {
request.get(listURL, function (error, response, body) {
if (error) {
console.error(`Request error: ${error}`)
reject()
reject(new Error(`Request error: ${error}`))
return
}
if (response.statusCode !== 200) {
console.error(`Error status code ${response.statusCode} returned for URL: ${listURL}`)
reject()
reject(new Error(`Error status code ${response.statusCode} returned for URL: ${listURL}`))
return
}
if (filter) {
Expand Down Expand Up @@ -103,17 +101,15 @@ const makeAdBlockClientFromListURL = (listURL, filter, options) => {
body = sanitizeABPInput(body)
resolve(makeAdBlockClientFromString(body, options))
}).catch((error) => {
console.error(`getSingleListDataFromSingleURL error: ${error}`)
reject()
reject(new Error(`getSingleListDataFromSingleURL error: ${error}`))
})
} else {
console.log(`${listURL}...`)
getSingleListDataFromSingleURL(listURL, filter).then((listData) => {
const body = sanitizeABPInput(listData)
resolve(makeAdBlockClientFromString(body, options))
}).catch((error) => {
console.error(`getSingleListDataFromSingleURL error: ${error}`)
reject()
reject(new Error(`getSingleListDataFromSingleURL error: ${error}`))
})
}
})
Expand Down Expand Up @@ -148,7 +144,7 @@ const makeAdBlockClientFromListUUID = (uuid, options) => {
list = adBlockLists.malware.find((l) => l.uuid === uuid)
}
if (!list) {
return Promise.reject()
return Promise.reject(new Error(`No list found for UUID ${uuid}`))
}

const filterFn = getListFilterFunction(uuid)
Expand Down Expand Up @@ -181,13 +177,11 @@ const getListBufferFromURL = (listURL, filter) => {
return new Promise((resolve, reject) => {
request.get(listURL, function (error, response, body) {
if (error) {
console.error(`Request error: ${error}`)
reject()
reject(new Error(`Request error: ${error}`))
return
}
if (response.statusCode !== 200) {
console.error(`Error status code ${response.statusCode} returned for URL: ${listURL}`)
reject()
reject(new Error(`Error status code ${response.statusCode} returned for URL: ${listURL}`))
return
}
if (filter) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* node scripts/check.js --uuid 67F880F5-7602-4042-8A3D-01481FD7437A --stats
*/
const commander = require('commander')
const {makeAdBlockClientFromListUUID, makeAdBlockClientFromDATFile, makeAdBlockClientFromListURL, makeAdBlockClientFromString, makeAdBlockClientFromFilePath, readSiteList} = require('../lib/util')
const {FilterOptions} = require('..')
const { makeAdBlockClientFromListUUID, makeAdBlockClientFromDATFile, makeAdBlockClientFromListURL, makeAdBlockClientFromString, makeAdBlockClientFromFilePath, readSiteList } = require('../lib/util')
const { FilterOptions } = require('..')

const filterStringToFilterOption = (val) => FilterOptions[val]

Expand Down
12 changes: 5 additions & 7 deletions scripts/generateDataFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {AdBlockClient, FilterOptions} = require('..')
const { AdBlockClient, FilterOptions } = require('..')
const path = require('path')
const fs = require('fs')
const request = require('request')
const braveUnbreakPath = './test/data/brave-unbreak.txt'
const {getListBufferFromURL, getListFilterFunction} = require('../lib/util')
const {adBlockLists} = require('..')
const { getListBufferFromURL, getListFilterFunction } = require('../lib/util')
const { adBlockLists } = require('..')

let totalExceptionFalsePositives = 0
let totalNumFalsePositives = 0
Expand Down Expand Up @@ -38,13 +38,11 @@ const generateDataFileFromURL = (listURL, outputDATFilename, filter) => {
console.log(`${listURL}...`)
request.get(listURL, function (error, response, body) {
if (error) {
console.error(`Request error: ${error}`)
reject()
reject(new Error(`Request error: ${error}`))
return
}
if (response.statusCode !== 200) {
console.error(`Error status code ${response.statusCode} returned for URL: ${listURL}`)
reject()
reject(new Error(`Error status code ${response.statusCode} returned for URL: ${listURL}`))
return
}
const braveUnbreakBody = fs.readFileSync(braveUnbreakPath, 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateManifestFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {AdBlockClient} = require('..')
const { AdBlockClient } = require('..')
const fs = require('fs')

const client = new AdBlockClient()
Expand Down
3 changes: 1 addition & 2 deletions scripts/uploadDataFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const uploadFile = (key, filePath, filename) => {
var uploader = client.uploadFile(params)
process.stdout.write(`Started uploading to: ${params.s3Params.Key}... `)
uploader.on('error', function (err) {
console.error('Unable to upload:', err.stack, 'Do you have ~/.aws/credentials filled out?')
reject()
reject(new Error(`Unable to upload, do you have ~/.aws/credentials filled out? ${err}`))
})
uploader.on('end', function (params) {
console.log('completed')
Expand Down
4 changes: 2 additions & 2 deletions test/js/filterListTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
/* global describe, it */

const assert = require('assert')
const {adBlockLists} = require('../..')
const { adBlockLists } = require('../..')

describe('adBlockLists', function () {
describe('default', function () {
it('contains 4 default lists', function () {
assert.equal(adBlockLists.default.length, 5)
assert.strictEqual(adBlockLists.default.length, 5)
})
it('has uuid property', function () {
adBlockLists.default.forEach((list) => {
Expand Down
4 changes: 2 additions & 2 deletions test/js/filteringTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
/* global describe, it */

const assert = require('assert')
const {sanitizeABPInput, extraConcatRules} = require('../../lib/filtering')
const { sanitizeABPInput, extraConcatRules } = require('../../lib/filtering')
const filteredOutRule = '*/test'
const predicate = (rule) => !rule.startsWith('*')

sanitizeABPInputFiltered = (input, filterPredicate) =>
const sanitizeABPInputFiltered = (input, filterPredicate) =>
sanitizeABPInput(input, filterPredicate).split('\n').slice(0, extraConcatRules.length * -1).join('\n')

describe('filtering', function () {
Expand Down
14 changes: 7 additions & 7 deletions test/js/fingerprintTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
/* global describe, it, before */

const assert = require('assert')
const {AdBlockClient} = require('../..')
const { AdBlockClient } = require('../..')

describe('getFingerprint', function () {
before(function () {
this.adBlockClient = new AdBlockClient()
})
it('Extracts simple fingerprint', function () {
assert.equal(this.adBlockClient.getFingerprint('fdasfdsafdas'), 'fdasfd')
assert.strictEqual(this.adBlockClient.getFingerprint('fdasfdsafdas'), 'fdasfd')
})
it('Does not use special characters for fingerprints', function () {
assert.equal(this.adBlockClient.getFingerprint('*fdasfdsafdas'), 'fdasfd')
assert.strictEqual(this.adBlockClient.getFingerprint('*fdasfdsafdas'), 'fdasfd')
})
it('Extracts host anchored filter fingerprint', function () {
assert.equal(this.adBlockClient.getFingerprint('||brave.com'), 'brave.')
assert.strictEqual(this.adBlockClient.getFingerprint('||brave.com'), 'brave.')
})
it('Does not extract a fingerprint for strings that are too short', function () {
assert.equal(this.adBlockClient.getFingerprint('prime'), undefined)
assert.strictEqual(this.adBlockClient.getFingerprint('prime'), undefined)
})
it('Does not extract a fingerprint for blacklisted strings', function () {
assert.equal(this.adBlockClient.getFingerprint('https://'), undefined)
assert.strictEqual(this.adBlockClient.getFingerprint('https://'), undefined)
})
it('Extract a fingerprint for short host anchored filters', function () {
assert.equal(this.adBlockClient.getFingerprint('||a.ca/brianbondy'), 'a.ca/b')
assert.strictEqual(this.adBlockClient.getFingerprint('||a.ca/brianbondy'), 'a.ca/b')
})
})
Loading

1 comment on commit 29c8e71

@SergeyZhukovsky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.