Skip to content

⬅️ Back to Table of Contents

πŸ“„ no-namespace

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 2
πŸ“¦ Imports 4
πŸ“‘ Type Aliases 2

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/eslint-plugin/src/rules/no-namespace.ts

πŸ“€ Default Export

export default createRule<Options, MessageIds>({ ... })
Property Value
name 'no-namespace'
meta.type 'suggestion'
meta.docs.description 'Disallow TypeScript namespaces'
meta.docs.recommended 'recommended'
meta.messages.moduleSyntaxIsPreferred 'ES2015 module syntax is preferred over namespaces.'
meta.schema [ { type: 'object', additionalProperties: false, properties: { allowDeclarations: { type: 'boolean', description: 'Wh...
defaultOptions [ { allowDeclarations: false, allowDefinitionFiles: true, }, ]

Entry point: create β€” documented under Functions.


πŸ“¦ Imports

Name Source
TSESTree @typescript-eslint/utils
AST_NODE_TYPES @typescript-eslint/utils
createRule ../util
isDefinitionFile ../util

Functions

create(context: any, [{ allowDeclarations, allowDefi…: any): { "TSModuleDeclaration[global!=true][id.type!='Literal']"(n…

Parameters:

  • context any
  • [{ allowDeclarations, allowDefinitionFiles }] any

Returns: { "TSModuleDeclaration[global!=true][id.type!='Literal']"(node: TSESTree.TSModuleDeclaration): void; }

Calls:

  • isDeclaration
  • isDefinitionFile (from ../util)
  • context.report
Code
create(context, [{ allowDeclarations, allowDefinitionFiles }]) {
    function isDeclaration(node: TSESTree.Node): boolean {
      if (node.type === AST_NODE_TYPES.TSModuleDeclaration && node.declare) {
        return true;
      }

      return node.parent != null && isDeclaration(node.parent);
    }

    return {
      "TSModuleDeclaration[global!=true][id.type!='Literal']"(
        node: TSESTree.TSModuleDeclaration,
      ): void {
        if (
          node.parent.type === AST_NODE_TYPES.TSModuleDeclaration ||
          (allowDefinitionFiles && isDefinitionFile(context.filename)) ||
          (allowDeclarations && isDeclaration(node))
        ) {
          return;
        }

        context.report({
          node,
          messageId: 'moduleSyntaxIsPreferred',
        });
      },
    };
  }

Internal helpers

Declared inside another function in this file.

isDeclaration(node: TSESTree.Node): boolean

Parameters:

  • node TSESTree.Node

Returns: boolean

Calls:

  • isDeclaration
Code
function isDeclaration(node: TSESTree.Node): boolean {
      if (node.type === AST_NODE_TYPES.TSModuleDeclaration && node.declare) {
        return true;
      }

      return node.parent != null && isDeclaration(node.parent);
    }

Type Aliases

Options

type Options = [
  {
    allowDeclarations?: boolean;
    allowDefinitionFiles?: boolean;
  },
];

MessageIds

type MessageIds = 'moduleSyntaxIsPreferred';

Generated by Syntax Scribe