Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@types/eslint-scope
Advanced tools
TypeScript definitions for eslint-scope
@types/eslint-scope provides TypeScript type definitions for the eslint-scope package, which is used to analyze the scope of variables in JavaScript code. This package is particularly useful for developers who are building tools that need to understand variable scoping, such as linters, code analyzers, and compilers.
Scope Analysis
This feature allows you to analyze the scope of variables in a given piece of JavaScript code. The code sample demonstrates how to parse JavaScript code into an Abstract Syntax Tree (AST) using espree and then analyze the scope using eslint-scope.
const eslintScope = require('eslint-scope');
const espree = require('espree');
const code = 'function foo() { var bar = 1; }';
const ast = espree.parse(code, { ecmaVersion: 6 });
const scopeManager = eslintScope.analyze(ast);
scopeManager.scopes.forEach(scope => {
console.log(scope.variables);
});
Variable Tracking
This feature allows you to track variables within different scopes. The code sample shows how to parse JavaScript code and then log the names of all variables found in each scope.
const eslintScope = require('eslint-scope');
const espree = require('espree');
const code = 'let x = 10; function test() { let y = 20; }';
const ast = espree.parse(code, { ecmaVersion: 6 });
const scopeManager = eslintScope.analyze(ast);
scopeManager.scopes.forEach(scope => {
scope.variables.forEach(variable => {
console.log(variable.name);
});
});
Reference Tracking
This feature allows you to track references to variables within different scopes. The code sample demonstrates how to parse JavaScript code and then log the names of all references found in each scope.
const eslintScope = require('eslint-scope');
const espree = require('espree');
const code = 'let a = 1; function foo() { console.log(a); }';
const ast = espree.parse(code, { ecmaVersion: 6 });
const scopeManager = eslintScope.analyze(ast);
scopeManager.scopes.forEach(scope => {
scope.references.forEach(reference => {
console.log(reference.identifier.name);
});
});
ESLint is a popular linting tool for JavaScript and TypeScript. It includes scope analysis as part of its linting process, but it is a more comprehensive tool that also includes rule enforcement, code style checking, and more.
Acorn is a fast, small, JavaScript parser that can be used to generate an AST from JavaScript code. While it does not provide scope analysis out of the box, it can be used in conjunction with other tools to achieve similar functionality.
babel-eslint is a parser that allows ESLint to lint all valid Babel code. It extends the capabilities of ESLint to support experimental syntax not yet supported by ESLint itself. It can be used to analyze the scope of variables in modern JavaScript code.
npm install --save @types/eslint-scope
This package contains type definitions for eslint-scope (https://github.com/eslint/eslint-scope).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/eslint-scope.
import * as eslint from "eslint";
import * as estree from "estree";
export const version: string;
export class ScopeManager implements eslint.Scope.ScopeManager {
scopes: Scope[];
globalScope: Scope;
acquire(node: {}, inner?: boolean): Scope | null;
getDeclaredVariables(node: {}): Variable[];
}
export class Scope implements eslint.Scope.Scope {
type:
| "block"
| "catch"
| "class"
| "for"
| "function"
| "function-expression-name"
| "global"
| "module"
| "switch"
| "with"
| "TDZ";
isStrict: boolean;
upper: Scope | null;
childScopes: Scope[];
variableScope: Scope;
block: estree.Node;
variables: Variable[];
set: Map<string, Variable>;
references: Reference[];
through: Reference[];
functionExpressionScope: boolean;
}
export class Variable implements eslint.Scope.Variable {
name: string;
scope: Scope;
identifiers: estree.Identifier[];
references: Reference[];
defs: eslint.Scope.Definition[];
}
export class Reference implements eslint.Scope.Reference {
identifier: estree.Identifier;
from: Scope;
resolved: Variable | null;
writeExpr: estree.Node | null;
init: boolean;
isWrite(): boolean;
isRead(): boolean;
isWriteOnly(): boolean;
isReadOnly(): boolean;
isReadWrite(): boolean;
}
export interface AnalysisOptions {
optimistic?: boolean;
directive?: boolean;
ignoreEval?: boolean;
nodejsScope?: boolean;
impliedStrict?: boolean;
fallback?: string | ((node: {}) => string[]);
sourceType?: "script" | "module";
ecmaVersion?: number;
}
export function analyze(ast: {}, options?: AnalysisOptions): ScopeManager;
These definitions were written by Toru Nagashima.
FAQs
TypeScript definitions for eslint-scope
The npm package @types/eslint-scope receives a total of 8,946,629 weekly downloads. As such, @types/eslint-scope popularity was classified as popular.
We found that @types/eslint-scope demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.