Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

new rule: no-unsupported-browser-code #171

Closed
AdamTReineke opened this issue Jul 6, 2016 · 2 comments
Closed

new rule: no-unsupported-browser-code #171

AdamTReineke opened this issue Jul 6, 2016 · 2 comments
Labels
Microsoft Internal Issues related to closed source Microsoft code.
Milestone

Comments

@AdamTReineke
Copy link

It's easy to accumulate lots of browser specific code when adding workarounds for browser bugs. This new rule would use the tslint.json to specify which browser versions you care about supporting, then specifically formatted comments to annotate all browser hacks. As you drop support for older browsers and change the tslint.json configuration, tslint would flag the comments so you can remove the code.

Some examples from our code base, annotated with new "Browser Specific" comments:

// Called when we get a pointer down event for IE11
// Browser Specific: IE 11
document.body.addEventListener("pointerdown", function (event: MSPointerEvent) {
    if (event.pointerType !== "mouse") { ... }
}, false);

// Called when we get a pointer down event for IE10
// Browser Specific: IE 10
document.body.addEventListener("MSPointerDown", function (event: MSPointerEvent) {
    if (event.pointerType === event.MSPOINTER_TYPE_PEN) { ... }
    else if (event.pointerType === event.MSPOINTER_TYPE_TOUCH) { ... }
}, false);
// Work around bug where this doesn't render on iOS by forcing the hardware to do it
// Browser Specific: Mobile Safari
if (Utilities.browser.isSafari && !Utilities.browser.isChrome && Utilities.browser.isMobile) {
    style["transform"] = "translate3d(0,0,0)";
}

If we dropped support for IE 10, the event listener would be flagged and we could remove that code from our code base.

Some additional thinking is needed to come up with a decent grammar for designating the browser versions. @browserspecific <string> (for JSdoc usages) or Browser Specific: <string> seem like good tags around the string itself.

A grammar something like [Mobile] (Safari|Chrome|Firefox|FF|Internet Explorer|IE|Edge) [[>|<]<number>] would lead to comments like Mobile Safari < 8 or Chrome > 45 or IE, which seems ok.

@HamletDRC
Copy link
Member

Great. idea. It seems pretty easy to implement.

to configure the rule you could list your supported browers and have something like:

no-unsupported-browser-code: [ true, [
    "IE 10",
    "IE 11",
    "Chrome [4-9][0-9]",   // regex for 40 to 99
]]

@HamletDRC HamletDRC added feature-request Microsoft Internal Issues related to closed source Microsoft code. labels Jul 9, 2016
@HamletDRC
Copy link
Member

Tagging feature request and microsoft-internal so we can make this a high priority. PRs welcome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Microsoft Internal Issues related to closed source Microsoft code.
Projects
None yet
Development

No branches or pull requests

2 participants