Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Ban property #2791

Closed
ghost opened this issue May 19, 2017 · 4 comments
Closed

Ban property #2791

ghost opened this issue May 19, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented May 19, 2017

Bug Report

  • TSLint version: 5.2.0
  • TypeScript version: 2.4.0-dev.20170519
  • Running TSLint via: CLI

TypeScript code being linted

[-1, 2, -3].map(Math.abs);

with tslint.json configuration:

{
    "rules": {
        "ban": [
            true,
            ["Math", "abs"]
        ]
    }
}

Actual behavior

No error.

Expected behavior

A lint failure.

This would be a breaking change, but it makes sense to me. Maybe put it under an option until 6.0?

@vsiao
Copy link

vsiao commented Sep 12, 2017

How come ban is restricted to call expressions? Can we just remove this line?
https://github.com/palantir/tslint/blob/master/src/rules/banRule.ts#L149

@ryanatkn
Copy link

ryanatkn commented Mar 7, 2018

Another use case - I want to ban usage of length and name on the DOM window global. It's a rare gotcha but it's gotten me multiple times after refactoring.

console.log('surprise, these are defined in lib.dom.d.ts', length, name);

The following TypeScript-based solutions don't work: (because Subsequent variable declarations must have the same type.)

declare var length: never;
// nor
interface Window {
  length: never;
}

Reference in TypeScript issues - microsoft/TypeScript#14306

@jdom
Copy link

jdom commented Jan 3, 2019

@ryanatkn I believe your case would be covered by #3824.

I'm looking for banning those global variables, but also usages of Function.length. Could this rule be expanded to cover property accesses too?

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Oct 2, 2019

Removing Ignoring the Type: Breaking Change label per #4811. Now accepting PRs!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants