JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19974926
  • Score
    100M100P100Q212437F
  • License MIT

Utilities for ESLint plugins.

Package Exports

  • eslint-utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.