Skip to content

linter: no-inner-declarations option to ignore nesting in typescript namespaces #21143

Description

@jamiebuilds

Within the eslint/no-inner-declarations rule it would be really nice if you could configure it to ignore TypeScript namespaces.

"eslint/no-inner-declarations": ["error", { "namespaces": "allow" }]

The primary purpose of a namespace is to organize code.

When you have a namespace with a bunch of different distinct things inside of it, having this rule force you to yank code all the way out of the namespace, far away from the code that actually uses it, makes it less readable:

+ // After: Code is further away from where it is relevant
+ function generateTooltipArrowPath(): string {
+     // ...
+ }
 
  export namespace Tooltip {
    export type RootProps = { /* ... */ };
    export function Root(props: RootProps) { /* ... */ }
  
    export type TriggerProps = { /* ... */ };
    export function Trigger(props: TriggerProps) { /* ... */ }
  
    export type PortalProps = { /* ... */ };
    export function Portal(props: PortalProps) { /* ... */ }
  
    export type ContentProps = { /* ... */ };
    export function Content(props: ContentProps) { /* ... */ }

-   // Before: Code is right next to where we need it
-   function generateTooltipArrowPath(): string {
-     // ...
-   }
  
    export type ArrowProps = { /* ... */ };
    export function Arrow(props: ArrowProps) { /* ... */ }
  
    export type LabelProps = { /* ... */ };
    export function Label(props: LabelProps) { /* ... */ }
  
    export type AvatarProps = { /* ... */ };
    export function Avatar(props: AvatarProps) { /* ... */ }
  
    export type TimestampProps = { /* ... */ };
    export function Timestamp(props: TimestampProps) { /* ... */ }
  
    export type KeybindingProps = { /* ... */ };
    export function Keybinding(props: KeybindingProps) { /* ... */ }
  }

We don't need to be concerned with block scoping here, and there's no performance benefit to hoisting it because the namespace is evaluated on init.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions