Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add no-unsafe-any #1374

Closed
wants to merge 2 commits into from
Closed

Conversation

bradzacher
Copy link
Member

@bradzacher bradzacher commented Dec 23, 2019

Fixes #791

WIP

  • still need to cover more cases
    • member and call expressions on an any
    • (maybe) assigning any generics to stricter ones (const x: Set<string> = new Set<any>([false]);)
    • better error messages (put in var names)
    • options for each of the check
  • option for checking if variable is an exception arg (as they are always any)???
  • performance
    • this rule is super slow currently (17s on our codebase).
    • need to figure out how to make it less chatty, or how to cache things. Unsure.
    • I'll need to do some profiling to see where the bottlenecks are exactly.

New rule which uses type information to validate that you're not doing anything with an any.

It's easy to keep your own code (mostly) safe via the no-explicit-any rule, but there are a number of places where things can get unsafe due to library types (from DefinitelyTyped, or from the default TS libraries).

This rule will help catch of those cases.

const a = Object.defineProperty({}, 'a', {}); // typeof === any

const b = new Map();
b.get('a'); // typeof === any

const c = JSON.parse('{}'); // typeof === any

const d1 = [], d2 = Array(3); // typeof === any[]

let e1 = null, e2 = undefined, e3; // typeof === any

// etc..

@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Dec 23, 2019
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@bradzacher bradzacher added the DO NOT MERGE PRs which should not be merged yet label Jan 21, 2020
@bradzacher
Copy link
Member Author

closing in favour of the no-unsafe-* rules that I've implemented

@bradzacher bradzacher closed this Mar 5, 2020
@bradzacher bradzacher deleted the no-unsafe-any branch March 5, 2020 02:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DO NOT MERGE PRs which should not be merged yet enhancement: new plugin rule New rule request for eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New set of rules: no-unsafe-*
1 participant