mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Merge pull request #1456 from tridactyl/tslint_rules_reactivation
TSLint: re-enable no-identical-functions rule
This commit is contained in:
commit
62bedd669a
6 changed files with 41 additions and 59 deletions
|
@ -135,22 +135,18 @@ browser.tabs.onActivated.addListener(ev => {
|
||||||
|
|
||||||
const aucon = new AutoContain()
|
const aucon = new AutoContain()
|
||||||
|
|
||||||
|
function cancelReq(details) {
|
||||||
|
if (aucon.getCancelledRequest(details.tabId)) {
|
||||||
|
aucon.clearCancelledRequests(details.tabId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle cancelled requests as a result of autocontain.
|
// Handle cancelled requests as a result of autocontain.
|
||||||
browser.webRequest.onCompleted.addListener(
|
browser.webRequest.onCompleted.addListener(cancelReq,
|
||||||
details => {
|
|
||||||
if (aucon.getCancelledRequest(details.tabId)) {
|
|
||||||
aucon.clearCancelledRequests(details.tabId)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ urls: ["<all_urls"], types: ["main_frame"] },
|
{ urls: ["<all_urls"], types: ["main_frame"] },
|
||||||
)
|
)
|
||||||
|
|
||||||
browser.webRequest.onErrorOccurred.addListener(
|
browser.webRequest.onErrorOccurred.addListener(cancelReq,
|
||||||
details => {
|
|
||||||
if (aucon.getCancelledRequest(details.tabId)) {
|
|
||||||
aucon.clearCancelledRequests(details.tabId)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ urls: ["<all_urls>"], types: ["main_frame"] },
|
{ urls: ["<all_urls>"], types: ["main_frame"] },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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 => {
|
config.getAsync("leavegithubalone").then(v => {
|
||||||
if (v === "true") return
|
if (v === "true") return
|
||||||
try {
|
try {
|
||||||
// On quick loading pages, the document is already loaded
|
// On quick loading pages, the document is already loaded
|
||||||
// if (document.location.host === "github.com") {
|
document.body.addEventListener("keydown", protectSlash)
|
||||||
document.body.addEventListener("keydown", function(e) {
|
|
||||||
if ("/".indexOf(e.key) !== -1 && contentState.mode === "normal") {
|
|
||||||
e.cancelBubble = true
|
|
||||||
e.stopImmediatePropagation()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// }
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// But on slower pages we wait for the document to load
|
// But on slower pages we wait for the document to load
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
// if (document.location.host === "github.com") {
|
document.body.addEventListener("keydown", protectSlash)
|
||||||
document.body.addEventListener("keydown", function(e) {
|
|
||||||
if ("/".indexOf(e.key) !== -1 && contentState.mode === "normal") {
|
|
||||||
e.cancelBubble = true
|
|
||||||
e.stopImmediatePropagation()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -4053,6 +4053,7 @@ export async function echo(...str: string[]) {
|
||||||
*
|
*
|
||||||
* `composite get_current_url | js -p alert(JS_ARG)`
|
* `composite get_current_url | js -p alert(JS_ARG)`
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-identical-functions */
|
||||||
//#content
|
//#content
|
||||||
export async function js(...str: string[]) {
|
export async function js(...str: string[]) {
|
||||||
if (str[0].startsWith("-p")) {
|
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.
|
* 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
|
//#background
|
||||||
export async function jsb(...str: string[]) {
|
export async function jsb(...str: string[]) {
|
||||||
if (str[0].startsWith("-p")) {
|
if (str[0].startsWith("-p")) {
|
||||||
|
|
|
@ -1280,6 +1280,15 @@ export function removeChangeListener<P extends keyof default_config>(
|
||||||
browser.storage.onChanged.addListener(async (changes, areaname) => {
|
browser.storage.onChanged.addListener(async (changes, areaname) => {
|
||||||
if (CONFIGNAME in changes) {
|
if (CONFIGNAME in changes) {
|
||||||
const defaultConf = new default_config()
|
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()
|
// newValue is undefined when calling browser.storage.AREANAME.clear()
|
||||||
if (changes[CONFIGNAME].newValue !== undefined) {
|
if (changes[CONFIGNAME].newValue !== undefined) {
|
||||||
|
@ -1301,7 +1310,6 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
|
||||||
) !== JSON.stringify(changes[CONFIGNAME].newValue[k]),
|
) !== JSON.stringify(changes[CONFIGNAME].newValue[k]),
|
||||||
)
|
)
|
||||||
|
|
||||||
const old = USERCONFIG
|
|
||||||
USERCONFIG = changes[CONFIGNAME].newValue
|
USERCONFIG = changes[CONFIGNAME].newValue
|
||||||
|
|
||||||
// Trigger listeners
|
// Trigger listeners
|
||||||
|
@ -1312,26 +1320,14 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
changedKeys.forEach(key => {
|
changedKeys.forEach(key => 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]))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if (areaname === (await get("storageloc"))) {
|
} 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
|
// If newValue is undefined and AREANAME is the same value as STORAGELOC, the user wants to clean their config
|
||||||
const old = USERCONFIG
|
|
||||||
USERCONFIG = o({})
|
USERCONFIG = o({})
|
||||||
|
|
||||||
Object.keys(old)
|
Object.keys(old)
|
||||||
.filter(key => old[key] !== defaultConf[key])
|
.filter(key => old[key] !== defaultConf[key])
|
||||||
.forEach(key => {
|
.forEach(key => triggerChangeListeners(key))
|
||||||
const arr = changeListeners.get(key)
|
|
||||||
if (arr) {
|
|
||||||
arr.forEach(f => f(old[key], defaultConf[key]))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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.
|
/** Test each case in testcases.
|
||||||
|
|
||||||
Warning: if your function really accepts an array, that array must be
|
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)
|
testcases = testcases.map(wrapPrimitives)
|
||||||
for (const [args, ans] of testcases) {
|
for (const [args, ans] of testcases) {
|
||||||
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
||||||
expect(
|
expect(arrayify(toTest, args)).toEqual(expect.arrayContaining(ans)))
|
||||||
(() => {
|
|
||||||
const result = toTest(...args)
|
|
||||||
if (result instanceof Array) return result
|
|
||||||
else return [result]
|
|
||||||
})(),
|
|
||||||
).toEqual(expect.arrayContaining(ans)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,13 +37,7 @@ export function testAllCustom(toTest, testcases, expectAttr, expectArg) {
|
||||||
testcases = testcases.map(wrapPrimitives)
|
testcases = testcases.map(wrapPrimitives)
|
||||||
for (const [args, ans] of testcases) {
|
for (const [args, ans] of testcases) {
|
||||||
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
||||||
expect(
|
expect(arrayify(toTest, args))[expectAttr](eval(expectArg)))
|
||||||
(() => {
|
|
||||||
const result = toTest(...args)
|
|
||||||
if (result instanceof Array) return result
|
|
||||||
else return [result]
|
|
||||||
})(),
|
|
||||||
)[expectAttr](eval(expectArg)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
"no-empty": [true, "allow-empty-catch", "allow-empty-functions"],
|
"no-empty": [true, "allow-empty-catch", "allow-empty-functions"],
|
||||||
"no-eval": false,
|
"no-eval": false,
|
||||||
"no-extra-semicolon": false,
|
"no-extra-semicolon": false,
|
||||||
"no-identical-functions": false,
|
|
||||||
"no-shadowed-variable": false,
|
"no-shadowed-variable": false,
|
||||||
"no-string-throw": false,
|
"no-string-throw": false,
|
||||||
"no-unsafe-finally": false,
|
"no-unsafe-finally": false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue