Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 2.19 KB

forbidden-enum.README.md

File metadata and controls

34 lines (21 loc) · 2.19 KB

Create a eslint rule to forbid enums

Author: Thomas Laforge

Information

Eslint is an amazing tool that helps developers avoid simple mistakes and adhere to company style guides.

In this first example, we will create a rule that forbids the use of enums. The rule will suggest using string unions instead of enums whenever you add an enum to your code. It is a straightforward rule for learning how to create rules.

You will also need to write tests to verify the rule's functionality.

To test the rule inside your project, add "@nrwl/nx/workspace/forbidden-enum": "error" to the eslintrc.json file and attempt to insert an enum into any project to witness the magic. 😇

To assist you with AST (Abstract Syntax Tree) definitions, you can visit the AST explorer and use JavaScript, @typescript-eslint/parser, and Eslint-v8 as the transformation method. However, please note that you will only get the type information there. The transformation function may not work for TypeScript types since the editor is in JavaScript.

You can also check this repo for eslint rule examples.

Submitting your work

  1. Fork the project
  2. clone it
  3. npm ci
  4. ...work on it
  5. npx nx test eslint-rules
  6. Commit your work
  7. Submit a PR with a title beginning with Answer:27 that I will review and other dev can review.

forbidden-enum forbidden-enum solution author

You can ask any question on twitter