Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New set of rules:no-unsafe-* #791

Closed
Closed
Assignees
bradzacher
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@bradzacher

Description

@bradzacher

These rules are all implemented - one final case remains to be implemented:no-unsafe-argument to catch when you're passingany into an argument. (See#791 (comment))


Create a rule which uses type information to determine when you're inadvertently breaking type safety by using an any, potentially without knowing.

Often libraries (or even the typescript defs themselves) can have weak(/lazy) types which returnany. If you're not careful, you can inadvertently introduceanys within your codebase, leading to bugs that aren't caught by the compiler.

Examples:

constfoo=Object.create(null);//    ^^^ error: variable declaration implicitly typed as anyconstbar=x.prop;//    ^^^ error: variable declaration implicitly typed as anyconstbaz=(1asany);//    ^^^ error: variable declaration implicitly typed as anyconstbuzz=[];//    ^^^^ error: variable declaration implicitly typed as any[]letbam:any=1;// no error, as it's **explicitly** anyfunctionfoo(arg:string){// ^^^^^^^^^^^^^^^^^^^^^^^^^ error: function return type is implicitly anyif(someCondition){return'str';}returnbam;//   ^^^^^^^^^^^  error: return statement implicitly returns any}foo(x.prop);//  ^^^^^^ error: passed function argument implicitly typed as anyfor(constfizzofbar){}//   ^^^^^^^^^^ error: variable declaration implicitly typed as anyfor(leti=foo;i<10;i+=1){}//       ^ error: variable declaration implicitly typed as any// variable decls, returns, arguments, assignment expressions, ifs...

Should also check assignments:

bam=foo;//  ^^^^^^^^^^ error: assignment expression implicitly uses as anyconstclazz=newClazz();clazz.foo=foo;//    ^^^^^^^^^^^^^^^^ error: assignment expression implicitly uses as anyfoo+=foo;//  ^^^^^^^^^^^ error: assignment expression implicitly uses anyfoo++;//  ^^^^^^ error: update expression implicitly uses any

Maybe also check things boolean things like if/while/etc?

if(foo){}//  ^^^ error: if condition implicitly typed as anywhile(foo){}//     ^^^ error: while condition implicitly typed as anydo{}while(foo)//            ^^^ error: do...while condition implicitly typed as anyswitch(foo){//      ^^^ error: switch discriminate implicitly typed as anycasebar://       ^^^ error: case test implicitly typed as anybreak;}

Should also provide an option to go strict with property access to help with finding the source of an any via property access):

typeObj={foo:{[k:string]:any;bar:{baz:string;};};};declareconstx:Obj;consty=x.foo.bam.baz;//        ^^^^^^^^^ error: property access implicitly returns any//    ^ error: variable declaration implicitly typed as anyconstz:string=x.foo.bam.baz;//                ^^^^^^^^^ error: property access implicitly returns anyconst{ baz}=x.foo.bam;//              ^^^^^^^^^ error: property access implicitly returns any//      ^^^ error: destructured variable implicitly typed as any

Metadata

Metadata

Assignees

Labels

enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp