eslint-plugin-constructors 1.5.0 → 1.6.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 +38 -8
- package/package.json +7 -7
- package/src/index.d.ts +2 -0
- package/src/utils/deprecations.js +1 -1
- package/src/utils/init.js +7 -4
- package/src/utils/pkg.js +21 -0
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<img alt="[License: MIT]" src="https://img.shields.io/badge/License-MIT-f1f20a.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
9
9
|
<a target="_blank" href="https://getnpmstats.com/?package=eslint-plugin-constructors&range=last-year&interval=monthly">
|
|
10
10
|
<img src="https://img.shields.io/npm/dm/eslint-plugin-constructors?style=for-the-badge&logo=npm&color=black"></a>
|
|
11
|
-
<a
|
|
12
|
-
<img alt="[
|
|
11
|
+
<a href="#usage">
|
|
12
|
+
<img alt="[Supports ESLint >=9.0.0 / Oxlint >=1.65.0]" src="https://img.shields.io/badge/Supports-ESLint_%3E%3D9.0.0_%2F_Oxlint_%3E%3D1.65.0-4B32C3?style=for-the-badge&logo=eslint"></a>
|
|
13
13
|
<br><br>
|
|
14
14
|
|
|
15
15
|
ESLint rules to enforce best practices for constructor usage.
|
|
@@ -33,6 +33,8 @@ npm i -D eslint-plugin-constructors
|
|
|
33
33
|
Usage
|
|
34
34
|
</h2>
|
|
35
35
|
|
|
36
|
+
### <img height=15 width=auto src="https://www.google.com/s2/favicons?domain=eslint.org&sz=64"> ESLint
|
|
37
|
+
|
|
36
38
|
Add a bundled config to your `eslint.config.*js`:
|
|
37
39
|
|
|
38
40
|
```js
|
|
@@ -52,12 +54,44 @@ export default [
|
|
|
52
54
|
]
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
Available bundles: `recommended`, `problem` (deterministic bugs only)
|
|
56
|
-
|
|
57
57
|
**Note:** Rule config is either a severity string (`'off'`, `'warn'`, `'error'`) or an array `[severity, options]` when the rule accepts options.
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
61
|
+
### <img height=15 width=auto src="https://www.google.com/s2/favicons?domain=oxc.rs&sz=64"> Oxlint
|
|
62
|
+
|
|
63
|
+
Add a bundled config to your `oxlint.config.ts`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
...
|
|
67
|
+
import constructors from 'eslint-plugin-constructors'
|
|
68
|
+
|
|
69
|
+
export default defineConfig({
|
|
70
|
+
overrides: [
|
|
71
|
+
// other overrides
|
|
72
|
+
{
|
|
73
|
+
files: ['**/*.js'],
|
|
74
|
+
jsPlugins: ['eslint-plugin-constructors'],
|
|
75
|
+
rules: {
|
|
76
|
+
...constructors.configs.recommended.rules,
|
|
77
|
+
'constructors/no-explicit-return': 'allow', // selectively disable rule
|
|
78
|
+
'constructors/require-new': ['deny', { mode: 'throwing' }] // selectively tweak rule
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Note:** Rule config is either a severity string (`'allow'`, `'warn'`, `'deny'`) or an array `[severity, options]` when the rule accepts options.
|
|
86
|
+
|
|
87
|
+
**Note:** Oxlint is typically **6-20× faster than ESLint** w/ this plugin (due to its Rust core and parallel file processing).
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
*Available bundles:* `recommended`, `problem` (deterministic bugs only), `stylistic`
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
61
95
|
<h2 id="supported-rules">
|
|
62
96
|
<img height=30 width=27 align="top" src="https://api.iconify.design/mdi/format-list-checks.svg?color=%232b2b2a">
|
|
63
97
|
Supported rules
|
|
@@ -65,8 +99,6 @@ Available bundles: `recommended`, `problem` (deterministic bugs only)
|
|
|
65
99
|
|
|
66
100
|
<h3 id="no-constructor-bind">
|
|
67
101
|
<code>no-constructor-bind</code>
|
|
68
|
-
<a title="Introduced in recent release" target="_blank" href="https://codeberg.org/adamlui/eslint-plugin-constructors/releases/tag/v1.5.0">
|
|
69
|
-
<img height=16 align="middle" src="https://api.iconify.design/mdi/sprout.svg?color=%234a4a4a"></a>
|
|
70
102
|
<a title="Included in recommended config" href="#usage">
|
|
71
103
|
<img height=18 alt="[Recommended]" src="https://img.shields.io/badge/Recommended-f1f20a?style=flat-square" align="middle"></a>
|
|
72
104
|
<a title="Accepts eslint --fix" target="_blank" href="https://eslint.org/docs/latest/use/command-line-interface#--fix">
|
|
@@ -129,8 +161,6 @@ If you target environments that do not support class fields.
|
|
|
129
161
|
|
|
130
162
|
<h3 id="no-constructor-state">
|
|
131
163
|
<code>no-constructor-state</code>
|
|
132
|
-
<a title="Introduced in recent release" target="_blank" href="https://codeberg.org/adamlui/eslint-plugin-constructors/releases/tag/v1.5.0">
|
|
133
|
-
<img height=16 align="middle" src="https://api.iconify.design/mdi/sprout.svg?color=%234a4a4a"></a>
|
|
134
164
|
<a title="Included in recommended config" href="#usage">
|
|
135
165
|
<img height=18 alt="[Recommended]" src="https://img.shields.io/badge/Recommended-f1f20a?style=flat-square" align="middle"></a>
|
|
136
166
|
<a title="Accepts eslint --fix" target="_blank" href="https://eslint.org/docs/latest/use/command-line-interface#--fix">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-constructors",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "ESLint rules for constructor usage",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-quality",
|
|
@@ -57,29 +57,29 @@
|
|
|
57
57
|
"demo": "eslint demo",
|
|
58
58
|
"lint": "pre-commit run",
|
|
59
59
|
"lint:all": "pre-commit run --all-files",
|
|
60
|
-
"test": "node tests/run
|
|
60
|
+
"test": "node tests/run"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"globals": "^17.13.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@e18e/eslint-plugin": "^0.8.1",
|
|
67
|
-
"@eslint/js": "^10.0.1",
|
|
68
67
|
"@eslint/json": "^2.1.1",
|
|
69
68
|
"@eslint/markdown": "^7.5.1",
|
|
70
69
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
71
|
-
"eslint": "^10.
|
|
70
|
+
"eslint": "^10.13.0",
|
|
72
71
|
"eslint-plugin-eslint-plugin": "^7.6.2",
|
|
73
72
|
"eslint-plugin-import-x": "^4.17.1",
|
|
74
|
-
"eslint-plugin-n": "^18.
|
|
73
|
+
"eslint-plugin-n": "^18.5.0",
|
|
75
74
|
"eslint-plugin-no-secrets": "^2.3.3",
|
|
76
75
|
"eslint-plugin-no-unsanitized": "^4.1.5",
|
|
77
|
-
"eslint-plugin-package-json": "^1.
|
|
76
|
+
"eslint-plugin-package-json": "^1.11.0",
|
|
78
77
|
"eslint-plugin-promise": "^7.3.0",
|
|
79
78
|
"eslint-plugin-regexp": "^3.3.1",
|
|
80
79
|
"eslint-plugin-security": "^4.2.0",
|
|
81
80
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
82
|
-
"eslint-plugin-woodpecker": "^1.
|
|
81
|
+
"eslint-plugin-woodpecker": "^1.1.1",
|
|
82
|
+
"oxlint": "^1.89.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"eslint": ">=9.0.0"
|
package/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type RuleSetting = RuleSeverity | [RuleSeverity, ...unknown[]]
|
|
|
4
4
|
type ConfigName =
|
|
5
5
|
| 'recommended'
|
|
6
6
|
| 'problem'
|
|
7
|
+
| 'stylistic'
|
|
7
8
|
|
|
8
9
|
interface PluginConfig {
|
|
9
10
|
plugins: Record<string, unknown>
|
|
@@ -23,6 +24,7 @@ interface PluginRule {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare const plugin: {
|
|
27
|
+
meta: { name: string }
|
|
26
28
|
rules: Record<string, PluginRule>
|
|
27
29
|
configs: Record<ConfigName, PluginConfig>
|
|
28
30
|
}
|
package/src/utils/init.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import deprecationsUtils from './deprecations.js'
|
|
2
|
+
import pkg from './pkg.js'
|
|
2
3
|
import rulesUtils from './rules.js'
|
|
3
4
|
|
|
4
5
|
import noConstructorBind from '../rules/no-constructor-bind.js'
|
|
@@ -9,7 +10,8 @@ import requireNew from '../rules/require-new.js'
|
|
|
9
10
|
|
|
10
11
|
import deprecations from '../data/deprecations.js'
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
+
const pkgName = pkg.getName(),
|
|
14
|
+
namespace = pkgName.replace(/^@[^/]+\//, '').replace(/^eslint-plugin-/, '')
|
|
13
15
|
|
|
14
16
|
export default {
|
|
15
17
|
configs(plugin) {
|
|
@@ -22,7 +24,8 @@ export default {
|
|
|
22
24
|
})
|
|
23
25
|
plugin.configs = {
|
|
24
26
|
recommended: createConfig(rule => rule.meta.docs.recommended),
|
|
25
|
-
problem: createConfig(rule => rule.meta.type == 'problem')
|
|
27
|
+
problem: createConfig(rule => rule.meta.type == 'problem'),
|
|
28
|
+
stylistic: createConfig(rule => rule.meta.docs.category == 'Stylistic Issues')
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
|
|
@@ -31,7 +34,7 @@ export default {
|
|
|
31
34
|
deprecationsUtils.initAlias(plugin, entry)
|
|
32
35
|
},
|
|
33
36
|
|
|
34
|
-
plugin() { return { rules: {}, configs: {} }},
|
|
37
|
+
plugin() { return { meta: { name: pkgName }, rules: {}, configs: {} }},
|
|
35
38
|
|
|
36
39
|
rules(plugin) {
|
|
37
40
|
plugin.rules = {
|
|
@@ -42,6 +45,6 @@ export default {
|
|
|
42
45
|
'require-new': requireNew
|
|
43
46
|
}
|
|
44
47
|
for (const [ruleId, rule] of Object.entries(plugin.rules))
|
|
45
|
-
rule.meta.docs.url = `https://codeberg.org/adamlui
|
|
48
|
+
rule.meta.docs.url = `https://codeberg.org/adamlui/${pkgName}/#${ruleId}`
|
|
46
49
|
}
|
|
47
50
|
}
|
package/src/utils/pkg.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
getName() { // oxlint-disable security/detect-non-literal-fs-filename
|
|
7
|
+
let current = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
while (current) {
|
|
9
|
+
const pkgPath = path.join(current, 'package.json')
|
|
10
|
+
if (fs.existsSync(pkgPath))
|
|
11
|
+
try {
|
|
12
|
+
const { name } = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
13
|
+
if (name) return name
|
|
14
|
+
} catch { /* malformed, keep walking */ }
|
|
15
|
+
const parent = path.dirname(current)
|
|
16
|
+
if (parent === current) return null
|
|
17
|
+
current = parent
|
|
18
|
+
}
|
|
19
|
+
return null
|
|
20
|
+
} // oxlint-enable security/detect-non-literal-fs-filename
|
|
21
|
+
}
|