Creating custom eslint rules from the coreeslint guidelines

Looking to make some small modifications to core eslint rules like array-bracket-newline or indent? These rules often rely on utilities within eslint, particularly ast-utils. Up until now, I've been using a plugin to add the modified rules and performing a

require('eslint/lib/rules/utils/ast-utils')
, since eslint is a peer-dependency.

However, due to recent changes in https://github.com/eslint/eslint/commit/24c9f2ac57efcd699ca69695c82e51ce5742df7b, this method is no longer feasible with the addition of an exports directive in the package.json. What is the recommended approach for modifying core eslint rules now?

  • Manually extracting all dependencies could work, but it's laborious and results in unnecessary code duplication (having to identify and remove segments of eslint's code).
  • Forking eslint entirely seems messy, given its interconnectedness with other components like eslint-plugins, vscode extensions, yarn sdks, etc. This would require adjustments across the board or resorting to questionable renaming tactics that could lead to confusion.
  • Using yarn package patching to eliminate the exports appears distasteful.

Is there a cleaner alternative?


As of now, my best solution involves forking eslint, eliminating the exports, and utilizing

require('eslint-fork/lib/rules/utils/ast-utils')
within the fork. While this means having an additional copy of eslint unnecessarily, considering it's for linting purposes, a bit of extra disk space seems inconsequential.

Answer №1

Incorporating unexported files using their full path is a viable option, like so:

const { basename, extname } = require('path');
const utilsPath = extname(basename(require.resolve('example')), 'utilities/files/helper-utils.js');
const helperUtils = require(utilsPath);

Please keep in mind that this approach assumes the primary export can be found within a specific directory within the package ('src' for instance).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Creating a cohesive design: Using CSS to ensure the navigation background complements

I am working on a project with a horizontal navbar that I want to stay fixed while scrolling. The main window has different colored divs as you scroll down, and I would like the navbar to match the image of the main div while scrolling, creating a looping ...

Can you explain the concept of 'each' when using the looping method in jQuery?

I'm grappling with accessing data within a table row. The data could be within a <td> tag, as text in an input field, or as a checkbox in an input field, or even as a button. To illustrate, here's a snippet of a small table: <table bor ...

Toggle all debugger points at once in Chrome's web inspector

Can I quickly toggle all debugger points on or off, or bookmark all debug points at once in Chrome? ...

Physically moving the window to a specified location using window.scrollTo()

Whenever I use the window.scrollTo(); method upon clicking a button, it simply jumps to the destination without displaying the scrolling motion. How can I ensure that the window physically scrolls to the designated position instead of instantly appearing ...

Asynchronous mismatches occur with React.js useState values

There is an unusual problem I'm encountering where the value passed into useState is different than the variable for useState. This issue occurs consistently on one specific UI component, while others do not experience the same problem. I just want to ...

How come an <a> tag is nabbing mouse clicks from a <canvas> element?

I have been experimenting with creating a 3D piano using three.js. Here is a snippet of the code I am currently working on: let renderer, camera, scene, light, keys, selectedKey; init(); render(); function init() { // Code for initializing renderer, ...

one webpage featuring HTML-based charts - visual data representation in HTML

I am looking to create HTML charts using a single file that includes JavaScript and jQuery. Specifically, I need the ability to generate line charts, pie charts, and other types of graphs, all within one file. I do not have much knowledge about JavaScript ...

Ways to tackle the issue of localStorage undefined error

My current struggle involves using next js. Whenever I attempt to utilize localStorage on my page, an error pops up stating that localStorage is not defined. After scouring through numerous articles, the common advice is to switch to window.localStorage, b ...

Tips for positioning input fields and labels in both horizontal and vertical alignment

Below is the HTML code, and I want the tags to look like this: label1: input1 label2: input2 label3: input3 Instead, it currently looks like this: label1: input1 How can I modify the HTML to achieve the desired format? HTML: <div class=" ...

Manipulate JSON data structure with JavaScript

The initial JSON data: { "data": { "count_at_hub": [ { "hub": "A", "date": "", "size": "1", "count": 141 }, { "hub": "A", "date": "", "size": " ...

How to employ Math.random with multiple variables in JavaScript

Within a function, I have the following statement: Math.random() > 0.5 ? 'spikes' : 'slime' I am interested in adding one more variable, let's call it 'stone', and having the program randomly choose between those th ...

Guide to opening all href links in a new window

When loading HTML content parsed from an email to a frame, the issue arises when there is an href link that tries to open in the same frame. I want to modify it so that it opens in a new tab instead. Usually, setting the target to _blank in the href would ...

Having trouble adding state values to an object

I have a specific state set up in my class: this.state = { inputValue: "", todos: [] } My issue lies within an arrow function where I am attempting to use setState to transfer the value of inputValue into todos. this.setState({ inputValue: & ...

The primary directory specified in the package.json file

Question: I have a pre-existing library that I want to turn into an NPM module. Currently, the library is being required through the local file system. How can I specify the main directory path for my module's files? If my structure looks like this: ...

Using JSON to pass checkbox values in Jquery

Recently, I encountered a dilemma with my input form. It consists of three text fields and a checkbox section where users can select multiple values. Additionally, there is an ajax request that sends a POST request to an api. To handle this, I created a fu ...

The website's behavior varies across various web browsers

I am currently working on a website with a full-screen video background and additional JavaScript components. Website : www.omod.biz/omoddemo Unfortunately, the website's performance varies across different browsers. It runs smoothly on Chrome and I ...

JavaScript failing to accurately measure the length

Currently experiencing a Javascript issue where the length of an element is not displayed correctly when using .length, even though it shows up in Chrome console. Here is what it looks like in Chrome console <html xmlns="http://www.w3.o ...

Controlling the Escape Key and Clicking Outside the Material-ui Dialog Box

I am currently utilizing material-ui's dialog feature. In this setup, when a user clicks the "sign out" button, a dialog box opens with options to either confirm the sign out by selecting "yes" or cancel it by choosing "no". The issue arises when the ...

Remove all nested object entries

In my coding project, I have a class structure defined as follows: class Foo{ id:string; name:string; childFooIds: string[]; } Within this structure, each instance of Foo can reference its child Foo objects by ID. These Foo instanc ...

How can we map a promise that resolves to foo to a new promise that resolves to bar?

I am working on a function that uses an XMLHttpRequest to retrieve data and returns a promise with the response. But now I want to modify it so that the promise only contains a specific string from the response. Instead of resolving to response = {status ...