Merge pull request #1456 from tridactyl/tslint_rules_reactivation

TSLint: re-enable no-identical-functions rule
This commit is contained in:
Oliver Blanthorn 2019-04-15 18:59:19 +01:00 committed by GitHub
commit 62bedd669a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 59 deletions

View file

@ -135,22 +135,18 @@ browser.tabs.onActivated.addListener(ev => {
const aucon = new AutoContain()
function cancelReq(details) {
if (aucon.getCancelledRequest(details.tabId)) {
aucon.clearCancelledRequests(details.tabId)
}
}
// Handle cancelled requests as a result of autocontain.
browser.webRequest.onCompleted.addListener(
details => {
if (aucon.getCancelledRequest(details.tabId)) {
aucon.clearCancelledRequests(details.tabId)
}
},
browser.webRequest.onCompleted.addListener(cancelReq,
{ urls: ["<all_urls"], types: ["main_frame"] },
)
browser.webRequest.onErrorOccurred.addListener(
details => {
if (aucon.getCancelledRequest(details.tabId)) {
aucon.clearCancelledRequests(details.tabId)
}
},
browser.webRequest.onErrorOccurred.addListener(cancelReq,
{ urls: ["<all_urls>"], types: ["main_frame"] },
)

View file

@ -262,30 +262,25 @@ config.getAsync("modeindicator").then(mode => {
})
})
// Site specific fix for / on GitHub.com
function protectSlash(e) {
if ("/".indexOf(e.key) !== -1 && contentState.mode === "normal") {
e.cancelBubble = true
e.stopImmediatePropagation()
}
}
// Some sites like to prevent firefox's `/` from working so we need to protect
// ourselves against that
// This was originally a github-specific fix
config.getAsync("leavegithubalone").then(v => {
if (v === "true") return
try {
// On quick loading pages, the document is already loaded
// if (document.location.host === "github.com") {
document.body.addEventListener("keydown", function(e) {
if ("/".indexOf(e.key) !== -1 && contentState.mode === "normal") {
e.cancelBubble = true
e.stopImmediatePropagation()
}
})
// }
document.body.addEventListener("keydown", protectSlash)
} catch (e) {
// But on slower pages we wait for the document to load
window.addEventListener("DOMContentLoaded", () => {
// if (document.location.host === "github.com") {
document.body.addEventListener("keydown", function(e) {
if ("/".indexOf(e.key) !== -1 && contentState.mode === "normal") {
e.cancelBubble = true
e.stopImmediatePropagation()
}
})
// }
document.body.addEventListener("keydown", protectSlash)
})
}
})

View file

@ -4053,6 +4053,7 @@ export async function echo(...str: string[]) {
*
* `composite get_current_url | js -p alert(JS_ARG)`
*/
/* tslint:disable:no-identical-functions */
//#content
export async function js(...str: string[]) {
if (str[0].startsWith("-p")) {
@ -4067,6 +4068,7 @@ export async function js(...str: string[]) {
/**
* Lets you execute JavaScript in the background context. All the help from [[js]] applies. Gives you a different `tri` object.
*/
/* tslint:disable:no-identical-functions */
//#background
export async function jsb(...str: string[]) {
if (str[0].startsWith("-p")) {

View file

@ -1280,6 +1280,15 @@ export function removeChangeListener<P extends keyof default_config>(
browser.storage.onChanged.addListener(async (changes, areaname) => {
if (CONFIGNAME in changes) {
const defaultConf = new default_config()
const old = USERCONFIG
function triggerChangeListeners(key) {
const arr = changeListeners.get(key)
if (arr) {
const v = old[key] === undefined ? defaultConf[key] : old[key]
arr.forEach(f => f(v, USERCONFIG[key]))
}
}
// newValue is undefined when calling browser.storage.AREANAME.clear()
if (changes[CONFIGNAME].newValue !== undefined) {
@ -1301,7 +1310,6 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
) !== JSON.stringify(changes[CONFIGNAME].newValue[k]),
)
const old = USERCONFIG
USERCONFIG = changes[CONFIGNAME].newValue
// Trigger listeners
@ -1312,26 +1320,14 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
}
})
changedKeys.forEach(key => {
const arr = changeListeners.get(key)
if (arr) {
const v = old[key] === undefined ? defaultConf[key] : old[key]
arr.forEach(f => f(v, USERCONFIG[key]))
}
})
changedKeys.forEach(key => triggerChangeListeners(key))
} else if (areaname === (await get("storageloc"))) {
// If newValue is undefined and AREANAME is the same value as STORAGELOC, the user wants to clean their config
const old = USERCONFIG
USERCONFIG = o({})
Object.keys(old)
.filter(key => old[key] !== defaultConf[key])
.forEach(key => {
const arr = changeListeners.get(key)
if (arr) {
arr.forEach(f => f(old[key], defaultConf[key]))
}
})
.forEach(key => triggerChangeListeners(key))
}
}
})

View file

@ -7,6 +7,12 @@ function wrapPrimitives(testcases) {
})
}
function arrayify(toTest, args) {
const result = toTest(...args)
if (result instanceof Array) return result
else return [result]
}
/** Test each case in testcases.
Warning: if your function really accepts an array, that array must be
@ -16,13 +22,7 @@ export function testAll(toTest, testcases) {
testcases = testcases.map(wrapPrimitives)
for (const [args, ans] of testcases) {
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
expect(
(() => {
const result = toTest(...args)
if (result instanceof Array) return result
else return [result]
})(),
).toEqual(expect.arrayContaining(ans)))
expect(arrayify(toTest, args)).toEqual(expect.arrayContaining(ans)))
}
}
@ -37,13 +37,7 @@ export function testAllCustom(toTest, testcases, expectAttr, expectArg) {
testcases = testcases.map(wrapPrimitives)
for (const [args, ans] of testcases) {
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
expect(
(() => {
const result = toTest(...args)
if (result instanceof Array) return result
else return [result]
})(),
)[expectAttr](eval(expectArg)))
expect(arrayify(toTest, args))[expectAttr](eval(expectArg)))
}
}

View file

@ -23,7 +23,6 @@
"no-empty": [true, "allow-empty-catch", "allow-empty-functions"],
"no-eval": false,
"no-extra-semicolon": false,
"no-identical-functions": false,
"no-shadowed-variable": false,
"no-string-throw": false,
"no-unsafe-finally": false,