A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/eslint-scope below:

eslint-scope - npm

ESLint Scope is the ECMAScript scope analyzer used in ESLint. It is a fork of escope.

npm i eslint-scope --save

To use in an ESM file:

import * as eslintScope from 'eslint-scope';

To use in a CommonJS file:

const eslintScope = require('eslint-scope');

In order to analyze scope, you'll need to have an ESTree compliant AST structure to run it on. The primary method is eslintScope.analyze(), which takes two arguments:

  1. ast - the ESTree-compliant AST structure to analyze.
  2. options (optional) - Options to adjust how the scope is analyzed, including:

Example:

import * as eslintScope from 'eslint-scope';
import * as espree from 'espree';
import estraverse from 'estraverse';

const options = {
    ecmaVersion: 2022,
    sourceType: "module"
};

const ast = espree.parse(code, { range: true, ...options });
const scopeManager = eslintScope.analyze(ast, options);

const currentScope = scopeManager.acquire(ast);   // global scope

estraverse.traverse(ast, {
    enter (node, parent) {
        // do stuff

        if (/Function/.test(node.type)) {
            currentScope = scopeManager.acquire(node);  // get current function scope
        }
    },
    leave(node, parent) {
        if (/Function/.test(node.type)) {
            currentScope = currentScope.upper;  // set to parent scope
        }

        // do stuff
    }
});

The following section describes the API for this package. You can also read the docs.

The ScopeManager class is at the core of eslint-scope and is returned when you call eslintScope.analyze(). It manages all scopes in a given AST.

Scopes returned by the ScopeManager methods have the following properties:

The GlobalScope class is a specialized scope representing the global execution context. It extends the base Scope class with additional functionality for handling implicitly defined global variables.

Each variable object has the following properties:

Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the ESLint Contributor Guidelines, so please be sure to read them before contributing. If you're not sure where to dig in, check out the issues.

We work hard to ensure that ESLint Scope is safe for everyone and that security issues are addressed quickly and responsibly. Read the full security policy.

ESLint Scope is licensed under a permissive BSD 2-clause license.

The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. Become a Sponsor to get your logo on our READMEs and website.

Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4