Socket
Socket
Sign inDemoInstall

@eslint-community/eslint-utils

Package Overview
Dependencies
2
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint-community/eslint-utils

Utilities for ESLint plugins.


Version published
Weekly downloads
19M
decreased by-13.4%
Maintainers
2
Install size
398 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

@eslint-community/eslint-utils

npm version Downloads/month Build Status Coverage Status

🏁 Goal

This package provides utility functions and classes for make ESLint custom rules.

For examples:

  • getStaticValue evaluates static value on AST.
  • ReferenceTracker checks the members of modules/globals as handling assignments and destructuring.

📖 Usage

See documentation.

📰 Changelog

See releases.

❤️ Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run clean removes the coverage result of npm test command.
  • npm run coverage shows the coverage result of the last npm test command.
  • npm run lint runs ESLint.
  • npm run watch runs tests on each file change.

Keywords

FAQs

Last updated on 17 Mar 2023

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc