eslint-plugin-constructors 1.0.3 → 1.1.1

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,11 +53,13 @@ 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
+ | ID | Description | Auto-fixable | Recommended |
59
+ | --- | --- | :-: | :-: |
60
+ | [`no-explicit-return`](#no-explicit-return) | Disallows explicit `return` statements in class constructors | ❌ | ✅ |
61
+ | [`require-error-subclass-name`](#require-error-subclass-name) | Requires classes extending `Error` to have names ending in `Error` | ❌ | ✅ |
62
+ | [`require-new`](#require-new-auto-fixable) | Requires `new` when calling error constructors | ✅ | ✅ |
61
63
 
62
64
  ---
63
65
 
@@ -133,9 +135,9 @@ If you don't follow the convention of suffixing custom error classes w/ `Error`.
133
135
 
134
136
  ---
135
137
 
136
- ### `require-new`
138
+ ### `require-new` (auto-fixable)
137
139
 
138
- > Requires `new` when calling error constructors (and optionally other built‑in constructors).
140
+ > Requires `new` when calling error constructors (and optionally other built-in constructors).
139
141
 
140
142
  #### Options
141
143
 
@@ -166,7 +168,7 @@ const arr = new Array(),
166
168
 
167
169
  #### When not to use it
168
170
 
169
- If you prefer the convenience of calling built‑ins without `new` (which is allowed by the spec).
171
+ If you prefer the convenience of calling built-ins without `new` (which is allowed for some of them).
170
172
 
171
173
  <div align="center">
172
174
 
@@ -176,15 +178,49 @@ If you prefer the convenience of calling built‑ins without `new` (which is all
176
178
 
177
179
  ---
178
180
 
181
+ ## Shield
182
+
183
+ <a href="https://codeberg.org/adamlui/eslint-plugin-constructors/#readme">
184
+ <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>
185
+
186
+ #### HTML
187
+
188
+ ```html
189
+ <a href="https://codeberg.org/adamlui/eslint-plugin-constructors/#readme">
190
+ <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>
191
+ ```
192
+
193
+ #### Markdown
194
+
195
+ ```md
196
+ [![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)
197
+ ```
198
+
179
199
  ## License
180
200
 
181
- > Copyright © 2026 [Adam Lui][adamlui-cb] under the [MIT license](./docs/LICENSE.md).
201
+ [<img height=62 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-constructors/af5fe76586/assets/images/logos/mit-license/red-pixelated.png">][epc-license]
202
+
203
+ <details>
204
+
205
+ <summary>
206
+
207
+ Copyright © 2026 [Adam Lui][adamlui-cb] under the [MIT license][epc-license].
208
+
209
+ </summary><br>
210
+
211
+ 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:
212
+
213
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
214
+
215
+ 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
216
+
217
+ </details>
182
218
 
183
219
  ## Related
184
220
 
185
221
  <!-- eslint-plugin-greasemonkey -->
186
222
 
187
- ### [<img width=16 src="https://www.google.com/s2/favicons?domain=eslint.org&sz=16">][epg-readme] [eslint-plugin-greasemonkey][epg-readme]
223
+ ### [<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
224
 
189
225
  <details>
190
226
 
@@ -192,23 +228,31 @@ If you prefer the convenience of calling built‑ins without `new` (which is all
192
228
 
193
229
  > [<img width=555 src="https://cdn.staticdelivr.com/gl/adamlui/eslint-plugin-greasemonkey/c9ac2985bb/assets/images/screenshots/vs-code/squiggles.png">][epg-readme]
194
230
 
195
- > [**Install**][epg-install] / [Readme][epg-readme] / [Report bug][epg-issues]
231
+ > [**Install**][epg-install] / [Readme][epg-readme] / [Supported rules][epg-rules]
196
232
 
197
233
  </details>
198
234
 
199
- ---
235
+ [epg-install]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#installation
236
+ [epg-readme]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#readme
237
+ [epg-rules]: https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#supported-rules
238
+
239
+ <!-- Footer -->
240
+
241
+ <img height=10 width="100%" src="https://cdn.staticdelivr.com/gl/adamlui/ai-web-extensions/d11d2ee/assets/images/separators/gradient-aqua.png">
200
242
 
201
243
  <div align="center">
202
244
 
203
- [**Latest releases**][epc-releases] / [More packages by author][adamlui-npmx] / [Back to top ↑](#top)
245
+ <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>
246
+ [**Latest releases**][epc-releases] / [Report a bug][epc-bugs] / [More packages by author][adamlui-npmx] / [Back to top ↑](#top)
204
247
 
205
248
  </div>
206
249
 
250
+ <!-- Links -->
251
+
207
252
  [adamlui-cb]: https://codeberg.org/adamlui
208
253
  [adamlui-npmx]: https://npmx.dev/org/adamlui
254
+ [epc-bugs]: https://codeberg.org/adamlui/eslint-plugin-constructors/issues/new
255
+ [epc-license]: https://codeberg.org/adamlui/eslint-plugin-constructors/src/branch/main/docs/LICENSE.md
209
256
  [epc-npm]: https://www.npmjs.com/package/eslint-plugin-constructors
210
- [epc-rules]: #rules
257
+ [epc-rules]: #supported-rules
211
258
  [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.1",
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 },