0.0.1 • Published 8 months ago

@winches/eslint-plugin-local-rules v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

eslint-plugin-local-rules

fork: https://github.com/cletusw/eslint-plugin-local-rules/blob/master/README.md

add builder build output

A plugin for ESLint that allows you to use project-specific rules, similar to the --rulesdir command line option (more).

Workaround for https://github.com/eslint/eslint/issues/8769 (previously https://github.com/eslint/eslint/issues/2715).

Other solutions

Dependencies

  • Requires ESLint version 0.8.0 or higher

Install

npm install eslint-plugin-local-rules

./eslint-local-rules.js (or ./eslint-local-rules/index.js)

'use strict';

module.exports = {
  'disallow-identifiers': {
    meta: {
      docs: {
        description: 'disallow identifiers',
        category: 'Possible Errors',
        recommended: false,
      },
      schema: [],
    },
    create: function (context) {
      return {
        Identifier: function (node) {
          context.report({
            node: node,
            message: 'Identifiers not allowed for Super Important reasons.',
          });
        },
      };
    },
  },
};

./.eslintrc

{
  "plugins": ["eslint-plugin-local-rules"],

  "rules": {
    "local-rules/disallow-identifiers": 2
  }
}

Usage (TypeScript)

npm install ts-node @types/eslint

./eslint-local-rules/index.js

require("ts-node").register({
  transpileOnly: true,
  compilerOptions: {
    module: "commonjs",
  },
});

module.exports = require("./rules").default;

./eslint-local-rules/rules.ts

import type { Rule } from "eslint";

export default {
  "disallow-identifiers": {
    meta: {
      docs: {
        description: 'disallow identifiers',
        category: 'Possible Errors',
        recommended: false,
      },
      schema: [],
    },
    create: function (context) {
      return {
        Identifier: function (node) {
          context.report({
            node: node,
            message: 'Identifiers not allowed for Super Important reasons.',
          });
        },
      };
    },
  },
} satisfies Record<string, Rule.RuleModule>;

npm/yarn/pnpm workspaces support

This plugin supports npm/yarn/pnpm workspaces, although note that if the eslint-local-rules.js file is in the workspace subdirectory, running from the project root is unsupported.

For example, if there's an eslint-local-rules.js and index.js in ./src/app:

Wrong: npx eslint src/app/index.js

Right: (cd src/app; npx eslint index.js)

Also note that if there is an eslint-local-rules.js file in both the workspace subdirectory and project root, the workspace one takes precedence (assuming you're running eslint from the workspace directory, as above).

License

MIT

0.0.1

8 months ago