From 93002a543d9bd6ca2a2b47b5d1b0bff131a7cc52 Mon Sep 17 00:00:00 2001 From: "J. Degand" <70610011+jdegand@users.noreply.github.com> Date: Sat, 11 May 2024 01:44:23 -0400 Subject: [PATCH] docs: rework forbid-enum-md (#886) --- .../docs/challenges/nx/27-forbid-enum-rule.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/src/content/docs/challenges/nx/27-forbid-enum-rule.md b/docs/src/content/docs/challenges/nx/27-forbid-enum-rule.md index 113c605..9aa51e3 100644 --- a/docs/src/content/docs/challenges/nx/27-forbid-enum-rule.md +++ b/docs/src/content/docs/challenges/nx/27-forbid-enum-rule.md @@ -1,9 +1,10 @@ --- title: 🟢 Custom Eslint Rule -description: Challenge 27 is about creating a custom Eslint Rule to forbid enums +description: Challenge 27 is about creating a custom ESLint Rule to forbid enums author: thomas-laforge contributors: - tomalaforge + - jdegand challengeNumber: 27 sidebar: order: 12 @@ -11,14 +12,16 @@ sidebar: ## Information -Eslint is an amazing tool that helps developers avoid simple mistakes and adhere to company style guides. +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. +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 an enum is present in this repo's code. This 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. 😇 +The `tools/eslint-rules` folder contains the starter code for this challenge. -To assist you with AST (Abstract Syntax Tree) definitions, you can visit the [AST explorer](https://astexplorer.net/) 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. +To test the rule inside your project, add `"@nrwl/nx/workspace/forbidden-enum": "error"` to the `eslintrc.json`. You can navigate to Challenge 47, `Enums vs. Union Types', and you should immediately see an error. -You can also check this [repo](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules) for eslint rule examples. +To assist you with AST (Abstract Syntax Tree) definitions, you can visit the [AST Explorer](https://astexplorer.net/) and use `JavaScript`, `@typescript-eslint/parser`, and `ESLint-v8` as the transformation methods. 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](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules) for ESLint rule examples.