1. eslint-compat-utils
Provides an API for ESLint custom rules that is compatible with the latest ESLint even when using older ESLint.
eslint-compat-utils
Package: eslint-compat-utils
Created by: ota-meshi
Last modified: Mon, 18 Mar 2024 13:13:19 GMT
Version: 0.5.0
License: MIT
Downloads: 6,825,918
Repository: https://github.com/ota-meshi/eslint-compat-utils

Install

npm install eslint-compat-utils
yarn add eslint-compat-utils

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.

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin