@onrails/eslint-plugin 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +14 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onrails/eslint-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "ESLint rules for @onrails/result boundaries — flags Promise<Result<…>> in public APIs and _unsafeUnwrap*. Replaces unmaintained eslint-plugin-neverthrow.",
5
5
  "license": "MIT",
6
6
  "author": "Alan R. Soares",
package/src/index.js CHANGED
@@ -94,11 +94,13 @@ const noUnsafeUnwrap = {
94
94
  meta: {
95
95
  type: "suggestion",
96
96
  docs: {
97
- description: "Discourage _unsafeUnwrap / _unsafeUnwrapErr outside tests.",
97
+ description:
98
+ "Discourage _unsafeUnwrap / _unsafeUnwrapErr and unwrapOk / unwrapErr / unwrap outside tests. Matching is name-based; same-named functions from other libraries are flagged too.",
98
99
  },
99
100
  schema: [],
100
101
  messages: {
101
- unsafe: "Avoid _unsafeUnwrap* — use match(), resolve(), or yieldResult() in tryGen.",
102
+ unsafe:
103
+ "Avoid _unsafeUnwrap* and unwrap* outside tests — use match(), resolve(), or yieldResult() in tryGen.",
102
104
  },
103
105
  },
104
106
  create(context) {
@@ -115,6 +117,16 @@ const noUnsafeUnwrap = {
115
117
  context.report({ node, messageId: "unsafe" });
116
118
  }
117
119
  },
120
+ CallExpression(node) {
121
+ if (
122
+ node.callee.type === "Identifier" &&
123
+ (node.callee.name === "unwrapOk" ||
124
+ node.callee.name === "unwrapErr" ||
125
+ node.callee.name === "unwrap")
126
+ ) {
127
+ context.report({ node, messageId: "unsafe" });
128
+ }
129
+ },
118
130
  };
119
131
  },
120
132
  };