Skip to content

💅 noShadow false positive, flags conflict inside type definition when it shouldn't #6038

@dyc3

Description

@dyc3

Environment information

playground

Rule name

lint/nursery/noShadow

Playground link

https://next.biomejs.dev/playground/?lintRules=all&analyzerFixMode=safeAndUnsafeFixes&code=dAB5AHAAZQAgAFAAcgBvAHAAcwAgAD0AIAB7AAoAIAAgACAAIABjAG8AbgB0AGEAYwB0ADoAIABDAG8AbgB0AGEAbgB0AEQAYQB0AGEAOwAKACAAIAAgACAAbwBuAEMAaABhAG4AZwBlAD8AOgAgACgAYwBvAG4AdABhAGMAdAA6ACAAQwBvAG4AdABhAG4AdABEAGEAdABhACkAIAA9AD4AIAB2AG8AaQBkADsACgAgACAAIAAgAG8AbgBEAGUAbABlAHQAZQA%2FADoAIAAoAGMAbwBuAHQAYQBjAHQAOgAgAEMAbwBuAHQAYQBuAHQARABhAHQAYQApACAAPQA%2BACAAdgBvAGkAZAA7AAoAfQA7AAoAYwBvAG4AcwB0ACAAewAgAGMAbwBuAHQAYQBjAHQAIAA9ACAAewB9ACwAIABvAG4AQwBoAGEAbgBnAGUAIAA9ACAAKAApACAAPQA%2BACAAewB9ACwAIABvAG4ARABlAGwAZQB0AGUAIAA9ACAAKAApACAAPQA%2BACAAewB9ACAAfQA6ACAAUAByAG8AcABzACAAPQAgAHsAfQA7AAoA&ruleDomains.react=all&ruleDomains.test=all&ruleDomains.solid=all&ruleDomains.next=all

Expected result

In the playground, noShadow flags the function argument in a type definition as shadowing a variable in the upper scope. This shouldn't matter, because the argument names in type definitions don't actually matter for the type definition.

Since the playground is kinda noisy for this, this is the diagnostic in question.

This variable shadows another variable with the same name in the outer scope.
  
    1 │ type Props = {
    2 │     contact: ContantData;
  > 3 │     onChange?: (contact: ContantData) => void;
      │                 ^^^^^^^
    4 │     onDelete?: (contact: ContantData) => void;
    5 │ };
  
  ℹ This is the shadowed variable, which is now inaccessible in the inner scope.
  
    4 │     onDelete?: (contact: ContantData) => void;
    5 │ };
  > 6 │ const { contact = {}, onChange = () => {}, onDelete = () => {} }: Props = {};
      │         ^^^^^^^
    7 │ 
  
  ℹ Consider renaming this variable. It's easy to confuse the origin of variables if they share the same name.

See also, eslint playground does not flag this: https://typescript-eslint.io/play#ts=5.7.2&fileType=.tsx&code=C4TwDgpgBACgTgezAZygXigbwFBSgYwQDtgBDfYALimWDgEsiBzAblymIGEALU5iAPzUAFIRLkqNOoyYBKdAD4oANwT0AJmzzEAIhAA2EYIJFiyFarQbN5aJao1sAvmzG0sBYueDooAIj8AGg4iHj4maAxhWyVMKCdg3QMjSKhoxQ8neOp4JFQMTBdsIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uQAsBDACYcA7uiiJo0DtEjgwAXxDygA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

Labels

A-LinterArea: linterL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions