n"] ` to make the package easy to find. You can add any other keywords that might be relevant to your plugin as well. 

A complete annotated example of what a plugin’s ` package.json ` file should
look like:

    
    
    // package.json
    {
      // Name npm package.
      // Add your own package name. eslint-plugin-example is taken!
      "name": "eslint-plugin-example",
      "version": "1.0.0",
      "description": "ESLint plugin for enforce-foo-bar rule.",
      "main": "eslint-plugin-example.js", // plugin entry point
      "scripts": {
        "test": "node enforce-foo-bar.test.js"
      },
      // Add eslint>=8.0.0 as a peer dependency.
      "peerDependencies": {
        "eslint": ">=8.0.0"
      },
      // Add these standard keywords to make plugin easy to find!
      "keywords": [
        "eslint",
        "eslintplugin",
        "eslint-plugin"
      ],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "eslint": "^8.36.0"
      }
    }
    
    
    1  
    2  
    3  
    4  
    5  
    6  
    7  
    8  
    9  
    10  
    11  
    12  
    13  
    14  
    15  
    16  
    17  
    18  
    19  
    20  
    21  
    22  
    23  
    24  
    25  
    26  
    27  
    

To publish the package, run ` npm publish ` and follow the CLI prompts.

You should see the package live on npm!

##  Step 10: Use the Published Custom Rule

Next, you can use the published plugin.

Run the following command in your project to download the package:

    
    
    npm install --save-dev eslint-plugin-example # Add your package name here
    
    
    1  
    

Update the ` eslint.config.js ` to use the packaged version of the plugin:

    
    
    // eslint.config.js
    "use strict";
    
    // Import the plugin downloaded from npm
    const eslintPluginExample = require("eslint-plugin-example");
    
    // ... rest of configuration
    
    
    1  
    2  
    3  
    4  
    5  
    6  
    7  
    

Now you’re ready to test the custom rule.

Run ESLint on the ` example.js ` file you created in step 8, now with the
downloaded plugin:

    
    
    npx eslint example.js
    
    
    1  
    

This produces the following output in the terminal:

    
    
    /<path-to-directory>/eslint-custom-rule-example/example.js
      8:11  error  Value other than "bar" assigned to `const foo`. Unexpected value: baz  example/enforce-foo-bar
    
    ✖ 1 problem (1 error, 0 warnings)
      1 error and 0 warnings potentially fixable with the `--fix` option.
    
    
    1  
    2  
    3  
    4  
    5  
    

As you can see in the above message, you can actually fix the issue with the `
--fix ` flag, correcting the variable assignment to be ` "bar" ` .

Run ESLint again with the ` --fix ` flag:

    
    
    npx eslint example.js --fix
    
    
    1  
    

There is no error output in the terminal when you run this, but you can see
the fix applied in ` example.js ` . You should see the following:

    
    
    // example.js
    
    // ... rest of file
    
    function incorrectFoo(){
      const foo = "bar"; // Fixed!
    }
    
    
    1  
    2  
    3  
    4  
    5  
    6  
    7  
    

##  Summary

In this tutorial, you’ve made a custom rule that requires all ` const `
variables named ` foo ` to be assigned the string ` "bar" ` and suggests
replacing any other value assigned to ` const foo ` with ` "bar" ` . You’ve
also added the rule to a plugin, and published the plugin on npm.

Through doing this, you’ve learned the following practices which you can apply
to create other custom rules and plugins:

  1. Creating a custom ESLint rule 
  2. Testing the custom rule 
  3. Bundling the rule in a plugin 
  4. Publishing the plugin 
  5. Using the rule from the plugin 

##  View the Tutorial Code

You can view the annotated source code for the tutorial [ here
](https://github.com/eslint/eslint/tree/main/docs/_examples/custom-rule-
tutorial-code) .

[ Edit this page ](