TSLint: re-enable no-angle-bracket-type-assertion rule

This rule enforces using `x as y` instead of `<y>x` in order to cast
elements. This makes things easier to read and protects against
conflicts with tsx.
This commit is contained in:
glacambre 2019-04-03 06:33:13 +02:00
parent f1ad4a36b1
commit 9119944bd9
No known key found for this signature in database
GPG key ID: B9625DB1767553AC
4 changed files with 10 additions and 14 deletions

View file

@ -134,7 +134,7 @@ export function hintPage(
let different = modeState.hints.find(h => { let different = modeState.hints.find(h => {
return ( return (
!(h.target instanceof HTMLAnchorElement) || !(h.target instanceof HTMLAnchorElement) ||
h.target.href !== (<HTMLAnchorElement>firstTarget).href h.target.href !== (firstTarget as HTMLAnchorElement).href
) )
}) })
@ -364,7 +364,7 @@ function elementFilterableText(el: Element): string {
const nodename = el.nodeName.toLowerCase() const nodename = el.nodeName.toLowerCase()
let text: string let text: string
if (nodename == "input") { if (nodename == "input") {
text = (<HTMLInputElement>el).value text = (el as HTMLInputElement).value
} else if (0 < el.textContent.length) { } else if (0 < el.textContent.length) {
text = el.textContent text = el.textContent
} else if (el.hasAttribute("title")) { } else if (el.hasAttribute("title")) {

View file

@ -1349,7 +1349,7 @@ export function snow_mouse_mode() {
//#content_helper //#content_helper
function findRelLink(pattern: RegExp): HTMLAnchorElement | null { function findRelLink(pattern: RegExp): HTMLAnchorElement | null {
// querySelectorAll returns a "non-live NodeList" which is just a shit array without working reverse() or find() calls, so convert it. // querySelectorAll returns a "non-live NodeList" which is just a shit array without working reverse() or find() calls, so convert it.
const links = Array.from(<NodeListOf<HTMLAnchorElement>>document.querySelectorAll("a[href]")) const links = Array.from(document.querySelectorAll("a[href]") as NodeListOf<HTMLAnchorElement>)
// Find the last link that matches the test // Find the last link that matches the test
return links.reverse().find(link => pattern.test(link.innerText)) return links.reverse().find(link => pattern.test(link.innerText))
@ -1364,7 +1364,7 @@ function findRelLink(pattern: RegExp): HTMLAnchorElement | null {
// Return the last element in the document matching the supplied selector, // Return the last element in the document matching the supplied selector,
// or null if there are no matches. // or null if there are no matches.
function selectLast(selector: string): HTMLElement | null { function selectLast(selector: string): HTMLElement | null {
const nodes = <NodeListOf<HTMLElement>>document.querySelectorAll(selector) const nodes = document.querySelectorAll(selector) as NodeListOf<HTMLElement>
return nodes.length ? nodes[nodes.length - 1] : null return nodes.length ? nodes[nodes.length - 1] : null
} }
@ -1386,14 +1386,14 @@ function selectLast(selector: string): HTMLElement | null {
*/ */
//#content //#content
export function followpage(rel: "next" | "prev" = "next") { export function followpage(rel: "next" | "prev" = "next") {
const link = <HTMLLinkElement>selectLast(`link[rel~=${rel}][href]`) const link = selectLast(`link[rel~=${rel}][href]`) as HTMLLinkElement
if (link) { if (link) {
window.location.href = link.href window.location.href = link.href
return return
} }
const anchor = <HTMLAnchorElement>selectLast(`a[rel~=${rel}][href]`) || findRelLink(new RegExp(config.get("followpagepatterns", rel), "i")) const anchor = (selectLast(`a[rel~=${rel}][href]`) || findRelLink(new RegExp(config.get("followpagepatterns", rel), "i"))) as HTMLAnchorElement
if (anchor) { if (anchor) {
DOM.mouseEvent(anchor, "click") DOM.mouseEvent(anchor, "click")
@ -1746,7 +1746,7 @@ export function focusinput(nth: number | string) {
let inputs = DOM.getElemsBySelector(INPUTPASSWORD_selectors, [DOM.isSubstantial]) let inputs = DOM.getElemsBySelector(INPUTPASSWORD_selectors, [DOM.isSubstantial])
if (inputs.length) { if (inputs.length) {
inputToFocus = <HTMLElement>inputs[0] inputToFocus = inputs[0] as HTMLElement
} }
} else if (nth === "-b") { } else if (nth === "-b") {
let inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[] let inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[]
@ -1757,7 +1757,7 @@ export function focusinput(nth: number | string) {
// either a number (not special) or we failed to find a special input when // either a number (not special) or we failed to find a special input when
// asked and falling back is acceptable // asked and falling back is acceptable
if ((!inputToFocus || !document.contains(inputToFocus)) && fallbackToNumeric) { if ((!inputToFocus || !document.contains(inputToFocus)) && fallbackToNumeric) {
let index = isNaN(<number>nth) ? 0 : <number>nth let index = isNaN(nth as number) ? 0 : nth as number
inputToFocus = DOM.getNthElement(INPUTTAGS_selectors, index, [DOM.isSubstantial]) inputToFocus = DOM.getNthElement(INPUTTAGS_selectors, index, [DOM.isSubstantial])
} }

View file

@ -277,9 +277,7 @@ export function isVisible(element: Element) {
*/ */
export function getAllDocumentFrames(doc = document) { export function getAllDocumentFrames(doc = document) {
if (!(doc instanceof HTMLDocument)) return [] if (!(doc instanceof HTMLDocument)) return []
let frames = (<HTMLIFrameElement[] & HTMLFrameElement[]>( let frames = (Array.from(doc.getElementsByTagName("iframe")) as HTMLIFrameElement[] & HTMLFrameElement[])
Array.from(doc.getElementsByTagName("iframe"))
))
.concat(Array.from(doc.getElementsByTagName("frame"))) .concat(Array.from(doc.getElementsByTagName("frame")))
.filter(frame => !frame.src.startsWith("moz-extension://")) .filter(frame => !frame.src.startsWith("moz-extension://"))
return frames.concat( return frames.concat(
@ -360,7 +358,7 @@ export function getNthElement(
.clamp(-inputs.length, inputs.length - 1) .clamp(-inputs.length, inputs.length - 1)
.mod(inputs.length) .mod(inputs.length)
return <HTMLElement>inputs[index] return inputs[index] as HTMLElement
} }
return null return null

View file

@ -13,8 +13,6 @@
"max-line-length": false, "max-line-length": false,
"max-union-size": false, "max-union-size": false,
"member-access": false, "member-access": false,
"missing-whitespace": false,
"no-angle-bracket-type-assertion": false,
"no-array-delete": false, "no-array-delete": false,
"no-big-function": false, "no-big-function": false,
"no-bitwise": false, "no-bitwise": false,