eslint-compat-utils
Provides an API for ESLint custom rules that is compatible with the latest ESLint even when using older ESLint.
Last updated 5 months ago by ota-meshi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install eslint-compat-utils 
SYNC missed versions from official npm registry.

eslint-compat-utils

This package is still in the experimental stage.

Provides an API for ESLint custom rules that is compatible with the latest ESLint even when using older ESLint.

Installation

npm install eslint-compat-utils

Usage

const { getSourceCode } = require("eslint-compat-utils");
module.exports = {
  meta: { /* ... */ },
  create(context) {
    const sourceCode = getSourceCode(context)
    return {
      "Program"(node) {
        const scope = sourceCode.getScope(node);
      },
    };
  },
}

API

getSourceCode(context)

Returns an extended instance of context.sourceCode or the result of context.getSourceCode(). Extended instances can use new APIs such as getScope(node) even with old ESLint.

getCwd(context)

Gets the value of context.cwd, but for older ESLint it returns the result of context.getCwd(). Versions older than v6.6.0 return a value from the result of process.cwd().

getFilename(context)

Gets the value of context.filename, but for older ESLint it returns the result of context.getFilename().

getPhysicalFilename(context)

Gets the value of context.physicalFilename, but for older ESLint it returns the result of context.getPhysicalFilename(). Versions older than v7.28.0 return a value guessed from the result of context.getFilename(), but it may be incorrect.

Current Tags

  • 0.5.1                                ...           latest (5 months ago)

14 Versions

  • 0.5.1                                ...           5 months ago
  • 0.5.0                                ...           8 months ago
  • 0.4.1                                ...           10 months ago
  • 0.4.0                                ...           10 months ago
  • 0.3.3                                ...           10 months ago
  • 0.3.2                                ...           10 months ago
  • 0.3.1                                ...           10 months ago
  • 0.3.0                                ...           10 months ago
  • 0.2.1                                ...           10 months ago
  • 0.2.0                                ...           10 months ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
  • 0.0.2                                ...           a year ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE