jsynowiec/node-typescript-boilerplate

Misleading ESLint error suppression comment

luke-m opened this issue · 2 comments

Hi there,

In main.ts, starting on L26, there is the following comment:

// Below are examples of using ESLint errors suppression
// Here it is suppressing a missing return type definition for the greeter function.

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types

I was really confused because after removing the comment, VSCode didn't raise an error in the line containing the function signature. I looked into .eslintrc.json and found the corresponding ESLint plugin defined and also 2 extensions from that plugin, leading me to assume that the rule (explicit-module-boundary-types) was already activated, especially considering the fact that you use it as an example in your boilerplate code. After explicitly activating the rule via the rules field, it started working as intended.

I think it would more sense to use a different, i.e. activated-out-of-the-box, rule as an example for ESLint error suppression examples.

Will the following changes make it less confusing?

diff --git a/.eslintrc.json b/.eslintrc.json
index 3930357..a7a3f42 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -13,10 +13,15 @@
   "plugins": ["@typescript-eslint", "jest"],
   "extends": [
     "eslint:recommended",
-    "plugin:@typescript-eslint/eslint-recommended",
     "plugin:@typescript-eslint/recommended",
     "plugin:jest/recommended",
     "prettier"
   ],
-  "rules": {}
+  "rules": {
+    // The following rule is enabled only to supplement the inline suppression
+    // examples, and because it is not a recommended rule, you should either
+    // disable it, or understand what it enforces.
+    // https://typescript-eslint.io/rules/explicit-function-return-type/
+    "@typescript-eslint/explicit-function-return-type": "warn"
+  }
 }
diff --git a/src/main.ts b/src/main.ts
index de40407..e91ae3e 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -23,10 +23,12 @@ function delayedHello(
   );
 }
 
-// Below are examples of using ESLint errors suppression
-// Here it is suppressing a missing return type definition for the greeter function.
+// Please see the comment in the .eslintrc.json file about the suppressed rule!
+// Below is an example of how to use ESLint errors suppression. You can read more
+// at https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules
 
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export async function greeter(name: string) {
+// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
+export async function greeter(name: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
+  // The name parameter should be of type string. Any is used to trigger the rule.
   return await delayedHello(name, Delays.Long);
 }

Yes! I think that's a great solution.