Skip to content

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

@fregante

Description

@fregante

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions