Socket
Socket
Sign inDemoInstall

eslint-utils

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-utils

Utilities for ESLint plugins.


Version published
Maintainers
1
Install size
218 kB
Created

Package description

What is eslint-utils?

The eslint-utils package provides utility functions for developers working with ESLint, a static code analysis tool for identifying problematic patterns in JavaScript code. It offers a set of APIs that can be used to manipulate and query the abstract syntax tree (AST) generated by ESLint, making it easier to create custom rules and analyze code.

What are eslint-utils's main functionalities?

AST Utilities

Provides functions to interact with the AST, such as finding variables, their references, and their definitions within the code.

{"findVariable": "function (initializer) { return getVariableByName(initializer, 'myVariable'); }"}

Reference Utilities

Offers methods to determine if a variable is being used in the code, which can help in identifying unused variables and potential bugs.

{"isUsedVariable": "function (variable) { return isUsedVariable(variable); }"}

Scope Analysis

Allows for analysis of variable scope, which can be used to ensure that variables are declared and used within the correct scope.

{"getInnermostScope": "function (scope, node) { return getInnermostScope(scope, node); }"}

Other packages similar to eslint-utils

Readme

Source

eslint-utils

npm version Downloads/month Build Status Coverage Status Dependency Status

🏁 Goal

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

For example, there is the class which tracks variable references.

const { ReferenceTracker } = require("eslint-utils")

module.exports = {
    meta: {},
    create(context) {
        return {
            "Program:exit"() {
                const tracker = new ReferenceTracker(context.getScope())

                // Track the references of global variables.
                for (const { node, path } of tracker.iterateGlobalReferences({
                    // Iterate the call expressions of `console.log`, `console.info`
                    console: {
                        log: { [ReferenceTracker.CALL]: true },
                        info: { [ReferenceTracker.CALL]: true },
                    },
                })) {
                    context.report({
                        node,
                        message: "Don't use {{name}}.",
                        data: { name: path.join(".") },
                    })
                }

                // Track the references of CommonJS modules.
                for (const { node, path } of tracker.iterateCjsReferences({
                    // Iterate the access of `fs.exists`.
                    fs: {
                        exists: { [ReferenceTracker.READ]: true },
                    },
                })) {
                    context.report({
                        node,
                        message: "Don't use {{name}}.",
                        data: { name: path.join(".") },
                    })
                }
            }
        }
    },
}

💿 Installation

Use npm or yarn.

npm install eslint-utils

Requirements

  • Node.js 6.5.0 or newer.

📖 Usage

See API reference.

📰 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 08 May 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc