/eslint-utils

Utilities for ESLint plugins and custom rules.

Primary LanguageJavaScriptMIT LicenseMIT

eslint-utils2

npm version Downloads/month Build Status Coverage Status Dependency Status

eslint-utils 基础上优化 ReferenceTracker ,以支持通配符,例如:

import { ReferenceTracker } from "eslint-utils";

export default {
  meta: {},
  create(context) {
    return {
      "Program:exit"() {
        const tracker = new ReferenceTracker(context.getScope());
        const traceMap = {
          // Find `console.*` .
          console: {
            [ReferenceTracker.SingleLevelWildcard]: {
              [ReferenceTracker.READ]: true,
            },
          },
          // Find `Object.prototype.**.bind()` .
          Object: {
            prototype: {
              [ReferenceTracker.MultiLevelWildcard]: {
                bind: {
                  [ReferenceTracker.CALL]: true,
                },
              },
            },
          },
        };

        for (const { node, path } of tracker.iterateGlobalReferences(
          traceMap
        )) {
          context.report({
            node,
            message: "disallow {{name}}.",
            data: { name: path.join(".") },
          });
        }
      },
    };
  },
};

以下是 eslint-utils README 原文。

🏁 Goal

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

For examples:

📖 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.