• This repository has been archived on 15/Aug/2024
  • Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 2-Clause "Sim...
  • Created almost 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

eslint-scope: ECMAScript scope analyzer

npm version Downloads Build Status

ESLint Scope

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

Install

npm i eslint-scope --save

📖 Usage

To use in an ESM file:

import * as eslintScope from 'eslint-scope';

To use in a CommonJS file:

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

Example:

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

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

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
    }
});

Contributing

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.

Build Commands

  • npm test - run all linting and tests
  • npm run lint - run all linting

License

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

More Repositories

1

eslint

Find and fix problems in your JavaScript code.
JavaScript
25,026
star
2

js

Monorepo for the JS language tools.
JavaScript
2,283
star
3

typescript-eslint-parser

An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
JavaScript
916
star
4

config-inspector

A visual tool for inspecting and understanding your ESLint flat configs.
Vue
697
star
5

doctrine

JSDoc parser
JavaScript
456
star
6

markdown

Lint JavaScript code blocks in Markdown documents
JavaScript
405
star
7

generator-eslint

A Yeoman generator to help with ESLint development
JavaScript
230
star
8

rewrite

Monorepo for the new version of ESLint
JavaScript
156
star
9

rfcs

Repo for managing Requests For Comments (RFCs) for the ESLint project
129
star
10

eslintrc

The legacy ESLintRC config file format for ESLint
JavaScript
118
star
11

archive-website

The ESLint website
JavaScript
96
star
12

create-config

Utility to create ESLint config files
JavaScript
76
star
13

eslint.org

ESLint website
JavaScript
75
star
14

eslint-github-bot

Plugin-based GitHub bot for ESLint
JavaScript
65
star
15

eslint-cli

The local eslint executor.
JavaScript
57
star
16

eslint-jp

Repository for creating and triaging issues in Japanese
47
star
17

eslint-visitor-keys

Constants and utilities about visitor keys to traverse AST.
JavaScript
42
star
18

json

JSON language plugin for ESLint
JavaScript
38
star
19

cn.eslint.org

Chinese ESLint documentation
JavaScript
27
star
20

eslint-transforms

Codemods for the ESLint ecosystem
JavaScript
25
star
21

eslint-release

The ESLint release tool
JavaScript
24
star
22

tsc-meetings

Technical Steering Committee meeting notes, proposals, and related information
JavaScript
20
star
23

zh-hans.docs.eslint.org

Simplified Chinese website
JavaScript
15
star
24

playground

ESLint online playground
JavaScript
11
star
25

eslint-canary

ESLint regression build
JavaScript
10
star
26

css

CSS language plugin for ESLint
10
star
27

code-explorer

TypeScript
9
star
28

eslint-tester

(Deprecated) A testing utility for ESLint
JavaScript
9
star
29

github-action

A GitHub action to run ESLint on pull requests
JavaScript
5
star
30

.github

Community health files for ESLint
1
star