Socket
Socket
Sign inDemoInstall

@typescript-eslint/scope-manager

Package Overview
Dependencies
3
Maintainers
1
Versions
2649
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @typescript-eslint/scope-manager

TypeScript scope analyser for ESLint


Version published
Weekly downloads
43M
increased by2.31%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @typescript-eslint/scope-manager?

The @typescript-eslint/scope-manager package is part of the TypeScript ESLint project. It is used to generate TypeScript-aware scope information for ESLint. This scope information is essential for linting TypeScript codebases, as it understands TypeScript-specific features like types and interfaces, which are not present in regular JavaScript.

What are @typescript-eslint/scope-manager's main functionalities?

Scope Analysis

The package analyzes the scope of variables and types within TypeScript code. It helps in identifying where variables are defined and how they are being used, which is crucial for linting and avoiding errors like variable shadowing or undeclared variables.

N/A

TypeScript-specific Scope Handling

It extends ESLint's scope analysis capabilities to understand TypeScript-specific constructs such as interfaces, types, and enums, which are not part of the standard JavaScript language.

N/A

Integration with ESLint

The scope manager is designed to work seamlessly with ESLint, allowing developers to use ESLint's rule set for TypeScript code. It provides the necessary scope information to ESLint rules so they can operate on TypeScript code as they would on JavaScript code.

N/A

Other packages similar to @typescript-eslint/scope-manager

Changelog

Source

5.45.0 (2022-11-28)

Bug Fixes

  • eslint-plugin: [array-type] --fix flag removes parentheses from type (#5997) (42b33af)
  • eslint-plugin: [keyword-spacing] prevent crash on no options (#6073) (1f19998)
  • eslint-plugin: [member-ordering] support private fields (#5859) (f02761a)
  • eslint-plugin: [prefer-readonly] report if a member's property is reassigned (#6043) (6e079eb)
  • scope-manager: add support for TS4.9 satisfies expression (#6059) (44027db)
  • typescript-estree: stub out ts.SatisfiesExpression on old TS versions (#6076) (1302b30)

Features

  • eslint-plugin: [member-ordering] add a required option for required vs. optional member ordering (#5965) (2abadc6)
  • support Auto Accessor syntax (#5926) (becd1f8)

Readme

Source

TypeScript Scope Manager

CI NPM Version NPM Downloads

This is a fork of eslint-scope, enhanced to support TypeScript functionality. You can view the original license for the code here.

This package is consumed automatically by @typescript-eslint/parser. You probably don't want to use it directly.

Getting Started

You can find our Getting Started docs here

Installation

$ yarn add -D typescript @typescript-eslint/scope-manager
$ npm i --save-dev typescript @typescript-eslint/scope-manager

API

analyze(tree, options)

Analyses a given AST and returns the resulting ScopeManager.

interface AnalyzeOptions {
  /**
   * Known visitor keys.
   */
  childVisitorKeys?: Record<string, string[]> | null;

  /**
   * Which ECMAScript version is considered.
   * Defaults to `2018`.
   * `'latest'` is converted to 1e8 at parser.
   */
  ecmaVersion?: EcmaVersion | 1e8;

  /**
   * Whether the whole script is executed under node.js environment.
   * When enabled, the scope manager adds a function scope immediately following the global scope.
   * Defaults to `false`.
   */
  globalReturn?: boolean;

  /**
   * Implied strict mode (if ecmaVersion >= 5).
   * Defaults to `false`.
   */
  impliedStrict?: boolean;

  /**
   * The identifier that's used for JSX Element creation (after transpilation).
   * This should not be a member expression - just the root identifier (i.e. use "React" instead of "React.createElement").
   * Defaults to `"React"`.
   */
  jsxPragma?: string;

  /**
   * The identifier that's used for JSX fragment elements (after transpilation).
   * If `null`, assumes transpilation will always use a member on `jsxFactory` (i.e. React.Fragment).
   * This should not be a member expression - just the root identifier (i.e. use "h" instead of "h.Fragment").
   * Defaults to `null`.
   */
  jsxFragmentName?: string | null;

  /**
   * The lib used by the project.
   * This automatically defines a type variable for any types provided by the configured TS libs.
   * For more information, see https://www.typescriptlang.org/tsconfig#lib
   *
   * Defaults to the lib for the provided `ecmaVersion`.
   */
  lib?: Lib[];

  /**
   * The source type of the script.
   */
  sourceType?: 'script' | 'module';

  /**
   * Emit design-type metadata for decorated declarations in source.
   * Defaults to `false`.
   */
  emitDecoratorMetadata?: boolean;
}

Example usage:

import { analyze } from '@typescript-eslint/scope-manager';
import { parse } from '@typescript-eslint/typescript-estree';

const code = `const hello: string = 'world';`;
const ast = parse(code, {
  // note that scope-manager requires ranges on the AST
  range: true,
});
const scope = analyze(ast, {
  ecmaVersion: 2020,
  sourceType: 'module',
});

References

Contributing

See the contributing guide here

Keywords

FAQs

Last updated on 28 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc