eslint-plugin-constructors 1.0.3 → 1.1.0

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.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  <a id="top"></a>
2
2
 
3
- # eslint-plugin-constructors
3
+ # <img height=24 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-constructors/9b14b5d0f2/assets/images/icons/eslint/purple/icon32.png"> eslint-plugin-constructors
4
4
 
5
5
  [![](https://img.shields.io/npm/v/eslint-plugin-constructors?logo=icinga&style=for-the-badge&label=Latest%20Build&color=32fcee)][epc-npm]
6
- [![](https://img.shields.io/badge/License-MIT-f1f20a.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge)](./#license)
6
+ [![](https://img.shields.io/badge/License-MIT-f1f20a.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge)](#license)
7
7
  [![](https://img.shields.io/badge/Requires-ESLint_%3E%3D9.0.0-4B32C3?style=for-the-badge&logo=eslint)](https://eslint.org/)
8
8
 
9
9
  ESLint rules to enforce best practices for constructor usage.
@@ -53,15 +53,19 @@ export default [
53
53
  ]
54
54
  ```
55
55
 
56
- ## Rules
56
+ ## Supported rules
57
57
 
58
- - [`no-explicit-return`](#no-explicit-return)
59
- - [`require-error-subclass-name`](#require-error-subclass-name)
60
- - [`require-new`](#require-new)
58
+ <!-- eslint-disable markdown/no-missing-link-fragments -->
59
+ | ID | Description | Auto-fixable | Recommended |
60
+ | --- | --- | :-: | :-: |
61
+ | [`no-explicit-return`](#no-explicit-return) | Disallows explicit `return` statements in class constructors | ❌ | ✅ |
62
+ | [`require-error-subclass-name`](#require-error-subclass-name) | Requires classes extending `Error` to have names ending in `Error` | ❌ | ✅ |
63
+ | [`require-new`](#require-new-auto-fixable) | Requires `new` when calling error constructors | ✅ | ✅ |
64
+ <!-- eslint-enable markdown/no-missing-link-fragments -->
61
65
 
62
66
  ---
63
67
 
64
- ### `no-explicit-return`
68
+ ### 𝄃𝄃𝄂𝄂𝄀𝄁𝄃𝄂𝄂𝄃 `no-explicit-return`
65
69
 
66
70
  > Disallows explicit `return` statements inside class constructors.
67
71
 
@@ -103,7 +107,7 @@ If you need to return a different object from a constructor.
103
107
 
104
108
  ---
105
109
 
106
- ### `require-error-subclass-name`
110
+ ### 𝄃𝄃𝄂𝄂𝄀𝄁𝄃𝄂𝄂𝄃 `require-error-subclass-name`
107
111
 
108
112
  > Requires classes extending `Error` have a name ending in `Error`.
109
113
 
@@ -133,9 +137,9 @@ If you don't follow the convention of suffixing custom error classes w/ `Error`.
133
137
 
134
138
  ---
135
139
 
136
- ### `require-new`
140
+ ### 𝄃𝄃𝄂𝄂𝄀𝄁𝄃𝄂𝄂𝄃 `require-new` (auto-fixable)
137
141
 
138
- > Requires `new` when calling error constructors (and optionally other built‑in constructors).
142
+ > Requires `new` when calling error constructors (and optionally other built-in constructors).
139
143
 
140
144
  #### Options
141
145
 
@@ -166,7 +170,7 @@ const arr = new Array(),
166
170
 
167
171
  #### When not to use it
168
172
 
169
- If you prefer the convenience of calling built‑ins without `new` (which is allowed by the spec).
173
+ If you prefer the convenience of calling built-ins without `new` (which is allowed for some of them).
170
174
 
171
175
  <div align="center">
172
176
 
@@ -176,15 +180,49 @@ If you prefer the convenience of calling built‑ins without `new` (which is all
176
180
 
177
181
  ---
178
182
 
183
+ ## Shield
184
+
185
+ <a href="https://codeberg.org/adamlui/eslint-plugin-constructors/#readme">
186
+ <img height=32 alt="[Linted by eslint-plugin-constructors]" src="https://img.shields.io/badge/Linted_by-eslint--plugin--constructors-4b32c3?logo=eslint&logoColor=white&labelColor=464646&style=for-the-badge"></a>
187
+
188
+ #### HTML
189
+
190
+ ```html
191
+ <a href="https://codeberg.org/adamlui/eslint-plugin-constructors/#readme">
192
+ <img height=32 alt="[Linted by eslint-plugin-constructors]" src="https://img.shields.io/badge/Linted_by-eslint--plugin--constructors-4b32c3?logo=eslint&logoColor=white&labelColor=464646&style=for-the-badge"></a>
193
+ ```
194
+
195
+ #### Markdown
196
+
197
+ ```md
198
+ [![Linted by eslint-plugin-constructors](https://img.shields.io/badge/Linted_by-eslint--plugin--constructors-4b32c3?logo=eslint&logoColor=white&labelColor=464646&style=for-the-badge)](https://codeberg.org/adamlui/eslint-plugin-constructors/#readme)
199
+ ```
200
+
179
201
  ## License
180
202
 
181
- > Copyright © 2026 [Adam Lui][adamlui-cb] under the [MIT license](./docs/LICENSE.md).
203
+ [<img height=62 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-constructors/af5fe76586/assets/images/logos/mit-license/red-pixelated.png">][epc-license]
204
+
205
+ <details>
206
+
207
+ <summary>
208
+
209
+ Copyright © 2026 [Adam Lui][adamlui-cb] under the [MIT license][epc-license].
210
+
211
+ </summary><br>
212
+
213
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
214
+
215
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
216
+
217
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
218
+
219
+ </details>
182
220
 
183
221
  ## Related
184
222
 
185
223
  <!-- eslint-plugin-greasemonkey -->
186
224
 
187
- ### [<img width=16 src="https://www.google.com/s2/favicons?domain=eslint.org&sz=16">][epg-readme] [eslint-plugin-greasemonkey][epg-readme]
225
+ ### [<img height=15 width=auto src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-constructors/9b14b5d0f2/assets/images/icons/eslint/purple/icon16.png">][epg-readme] [eslint-plugin-greasemonkey][epg-readme]
188
226
 
189
227
  <details>
190
228
 
@@ -192,23 +230,31 @@ If you prefer the convenience of calling built‑ins without `new` (which is all
192
230
 
193
231
  > [<img width=555 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-greasemonkey/c9ac2985bb/assets/images/screenshots/vs-code/squiggles.png">][epg-readme]
194
232
 
195
- > [**Install**][epg-install] / [Readme][epg-readme] / [Report bug][epg-issues]
233
+ > [**Install**][epg-install] / [Readme][epg-readme] / [Supported rules][epg-rules]
196
234
 
197
235
  </details>
198
236
 
199
- ---
237
+ [epg-install]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#installation
238
+ [epg-readme]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#readme
239
+ [epg-rules]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#supported-rules
240
+
241
+ <!-- Footer -->
242
+
243
+ <img height=10 width="100%" src="https://cdn.staticdelivr.com/gl/adamlui/ai-web-extensions/d11d2ee/assets/images/separators/gradient-aqua.png">
200
244
 
201
245
  <div align="center">
202
246
 
203
- [**Latest releases**][epc-releases] / [More packages by author][adamlui-npmx] / [Back to top ↑](#top)
247
+ <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.staticdelivr.com/gl/adamlui/js-utils/6b0d399/assets/images/icons/tag/white/icon16.svg"><img height=14 src="https://cdn.staticdelivr.com/gl/adamlui/js-utils/6b0d399/assets/images/icons/tag/dark-gray/icon16.svg"></picture>
248
+ [**Latest releases**][epc-releases] / [Report a bug][epc-bugs] / [More packages by author][adamlui-npmx] / [Back to top ↑](#top)
204
249
 
205
250
  </div>
206
251
 
252
+ <!-- Links -->
253
+
207
254
  [adamlui-cb]: https://codeberg.org/adamlui
208
255
  [adamlui-npmx]: https://npmx.dev/org/adamlui
256
+ [epc-bugs]: https://codeberg.org/adamlui/eslint-plugin-constructors/issues/new
257
+ [epc-license]: https://codeberg.org/adamlui/eslint-plugin-constructors/src/branch/main/docs/LICENSE.md
209
258
  [epc-npm]: https://www.npmjs.com/package/eslint-plugin-constructors
210
- [epc-rules]: #rules
259
+ [epc-rules]: #supported-rules
211
260
  [epc-releases]: https://codeberg.org/adamlui/eslint-plugin-constructors/releases
212
- [epg-install]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#installation
213
- [epg-readme]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#readme
214
- [epg-issues]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/issues/new
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-constructors",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "ESLint rules for constructor usage",
5
5
  "type": "module",
6
6
  "engines": {
@@ -76,6 +76,7 @@
76
76
  "eslint-plugin-no-unsanitized": "^4.1.5",
77
77
  "eslint-plugin-promise": "^7.3.0",
78
78
  "eslint-plugin-regexp": "^3.3.0",
79
+ "eslint-plugin-security": "^4.0.1",
79
80
  "globals": "^17.12.0",
80
81
  "husky": "^9.1.7",
81
82
  "yamllint-js": "^0.2.4"
package/src/index.js CHANGED
@@ -21,4 +21,4 @@ plugin.configs = {
21
21
  }
22
22
  }
23
23
 
24
- export default plugin
24
+ export { plugin as default, plugin as constructors }
@@ -1,12 +1,12 @@
1
- const ERR_CONSTRUCTORS = new Set([
1
+ const errors = new Set([
2
2
  'AggregateError', 'Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError'])
3
3
 
4
- const BUILTIN_CONSTRUCTORS = new Set([
4
+ const builtins = new Set([
5
5
  'Array', 'BigInt', 'Boolean', 'Date', 'Function', 'Map', 'Number', 'Object', 'RegExp', 'Set', 'String', 'Symbol',
6
6
  'WeakMap', 'WeakSet'
7
7
  ])
8
8
 
9
- function isErrConstructor(name) { return ERR_CONSTRUCTORS.has(name) }
9
+ function isErrConstructor(name) { return errors.has(name) }
10
10
 
11
11
  export default {
12
12
  meta: {
@@ -33,7 +33,7 @@ export default {
33
33
  if (node.new) return
34
34
  const calleeName = node.callee.name ; if (!calleeName) return
35
35
  const shouldReport = mode == 'error-only' ? isErrConstructor(calleeName)
36
- : isErrConstructor(calleeName) || BUILTIN_CONSTRUCTORS.has(calleeName)
36
+ : isErrConstructor(calleeName) || builtins.has(calleeName)
37
37
  if (shouldReport)
38
38
  context.report({
39
39
  node, messageId: 'requireNew', data: { name: calleeName },