1.0.0-rc.0 • Published 2 years ago

eslint-plugin-mycujoo v1.0.0-rc.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@mycujoo/eslint-plugin

This ESLint plugin enforces MyCujoo custom eslint rules.

Usage

Assuming you already have ESLint installed, run:

# npm
npm install @mycujoo/eslint-plugin --save-dev

# yarn
yarn add @mycujoo/eslint-plugin --dev

Then extend the recommended eslint config:

{
  "extends": [
    // ...
    "plugin:@mycujoo/eslint-plugin/recommended"
  ]
}

Custom Configuration

If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:

{
  "plugins": [
    // ...
    "@mycujoo/eslint-plugin"
  ],
  "rules": {
    // ...
    "@mycujoo/eslint-plugin/json-safety": "error",
  }
}

Adding new rules

To add a new rule: 1. create a new rule file inside the rules folder. The name should be suggestive of the rule. 2. Basic rule content:

"use strict";

module.exports = {
  meta: {
    type: "suggestion",
    docs: {
      description: "Rule docs description",
      url: "https://documentation.com",
    },

    messages: {
      CUSTOM_RULE_MESSAGE_ID:
        "Rule description",
    },
  },
  create(context) {
    return {
      Identifier(node) {
        // rule logic

        context.report({
          node,
          message: "CUSTOM_RULE_MESSAGE_ID",
          fix: (fixer) => {
            // fixer logic
          },
        });
      },
    };
  },
};

}
  1. Name and export the new rule in /rules/index.js

Further reading

  1. ESLint documentation about rules Working with Rules
  2. Blog: Creating Custom Eslint Rules
  3. YouTube: Create custom rule in the ESLint or Youtube: Writing custom Babel and ESLint plugins with ASTs