Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically pick up all files in ./eslint-local-rules #25

Open
fregante opened this issue Nov 25, 2023 · 0 comments
Open

Automatically pick up all files in ./eslint-local-rules #25

fregante opened this issue Nov 25, 2023 · 0 comments

Comments

@fregante
Copy link
Contributor

fregante commented Nov 25, 2023

Once the rules start to pile up, it's easier to keep them in separate files. Currently I have this in index.js:

const fs = require("node:fs");
const path = require("node:path");

const ruleFiles = fs
  .readdirSync(__dirname)
  .filter((file) => !file.endsWith("test.js") && !file.endsWith("index.js"));

const rules = Object.fromEntries(
  ruleFiles.map((file) => [
    path.basename(file, ".js"),
    require("./" + file),
  ])
);

module.exports = rules;

It would be good to add something like it on the condition that:

  • eslint-local-rules.js isn't found
  • eslint-local-rules/index.js isn't found
  • eslint-local-rules/*.js files exist

This follows #22 in that it reduces the amount of boilerplate code that one needs to copy-paste. For people who want custom loading logic, they can keep using the index file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant