Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eslint-community/eslint-utils

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint-community/eslint-utils

Utilities for ESLint plugins.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28M
decreased by-0.92%
Maintainers
2
Weekly downloads
 
Created

What is @eslint-community/eslint-utils?

@eslint-community/eslint-utils is a utility library for working with ESLint. It provides a set of tools to help with creating, testing, and debugging ESLint rules and plugins.

What are @eslint-community/eslint-utils's main functionalities?

getStaticValue

The `getStaticValue` function evaluates the static value of a given AST node. This is useful for determining the value of constants and literals in the code.

const { getStaticValue } = require('@eslint-community/eslint-utils');
const espree = require('espree');

const ast = espree.parse('const foo = 42;', { ecmaVersion: 2020 });
const node = ast.body[0].declarations[0].init;
const value = getStaticValue(node);
console.log(value); // { value: 42 }

ReferenceTracker

The `ReferenceTracker` class helps track references to global variables and properties. This is useful for identifying where and how certain variables or properties are used in the code.

const { ReferenceTracker } = require('@eslint-community/eslint-utils');
const espree = require('espree');
const eslintScope = require('eslint-scope');

const ast = espree.parse('const foo = { bar: 42 }; foo.bar;', { ecmaVersion: 2020 });
const scopeManager = eslintScope.analyze(ast);
const tracker = new ReferenceTracker(scopeManager);

for (const { node } of tracker.iterateGlobalReferences({ foo: { bar: true } })) {
  console.log(node); // Node representing `foo.bar`
}

getFunctionHeadLocation

The `getFunctionHeadLocation` function returns the location of the function head, which includes the function keyword, name, and parameters. This is useful for reporting issues related to function definitions.

const { getFunctionHeadLocation } = require('@eslint-community/eslint-utils');
const espree = require('espree');

const ast = espree.parse('function foo() {}', { ecmaVersion: 2020 });
const node = ast.body[0];
const location = getFunctionHeadLocation(node, { sourceCode: { text: 'function foo() {}' } });
console.log(location); // { start: { line: 1, column: 0 }, end: { line: 1, column: 13 } }

Other packages similar to @eslint-community/eslint-utils

Keywords

FAQs

Package last updated on 20 Nov 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc