eslint-plugin-constructors 1.5.0 → 1.5.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
@@ -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 target="_blank" href="https://eslint.org/">
12
- <img alt="[Requires ESLint >=9.0.0]" src="https://img.shields.io/badge/Requires-ESLint_%3E%3D9.0.0-4B32C3?style=for-the-badge&logo=eslint"></a>
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)
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,7 +99,7 @@ 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">
102
+ <a title="Introduced in latest minor release" target="_blank" href="https://codeberg.org/adamlui/eslint-plugin-constructors/releases/tag/v1.5.0">
69
103
  <img height=16 align="middle" src="https://api.iconify.design/mdi/sprout.svg?color=%234a4a4a"></a>
70
104
  <a title="Included in recommended config" href="#usage">
71
105
  <img height=18 alt="[Recommended]" src="https://img.shields.io/badge/Recommended-f1f20a?style=flat-square" align="middle"></a>
@@ -129,7 +163,7 @@ If you target environments that do not support class fields.
129
163
 
130
164
  <h3 id="no-constructor-state">
131
165
  <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">
166
+ <a title="Introduced in latest minor release" target="_blank" href="https://codeberg.org/adamlui/eslint-plugin-constructors/releases/tag/v1.5.0">
133
167
  <img height=16 align="middle" src="https://api.iconify.design/mdi/sprout.svg?color=%234a4a4a"></a>
134
168
  <a title="Included in recommended config" href="#usage">
135
169
  <img height=18 alt="[Recommended]" src="https://img.shields.io/badge/Recommended-f1f20a?style=flat-square" align="middle"></a>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-constructors",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "ESLint rules for constructor usage",
5
5
  "keywords": [
6
6
  "code-quality",
@@ -57,21 +57,20 @@
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.js"
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.12.0",
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.4.1",
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
76
  "eslint-plugin-package-json": "^1.10.1",
@@ -79,7 +78,8 @@
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.0.1"
81
+ "eslint-plugin-woodpecker": "^1.1.0",
82
+ "oxlint": "^1.89.0"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "eslint": ">=9.0.0"
package/src/index.d.ts CHANGED
@@ -23,6 +23,7 @@ interface PluginRule {
23
23
  }
24
24
 
25
25
  declare const plugin: {
26
+ meta: { name: string }
26
27
  rules: Record<string, PluginRule>
27
28
  configs: Record<ConfigName, PluginConfig>
28
29
  }
@@ -1,4 +1,4 @@
1
- /* eslint-disable security/detect-object-injection */
1
+ // oxlint-disable security/detect-object-injection
2
2
 
3
3
  export default {
4
4
  initAlias(plugin, [ruleId, { default: defaultOpts, wrapKey, renames = {} }]) {
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 namespace = 'constructors'
13
+ const pkgName = pkg.getName(),
14
+ namespace = pkgName.replace(/^@[^/]+\//, '').replace(/^eslint-plugin-/, '')
13
15
 
14
16
  export default {
15
17
  configs(plugin) {
@@ -31,7 +33,7 @@ export default {
31
33
  deprecationsUtils.initAlias(plugin, entry)
32
34
  },
33
35
 
34
- plugin() { return { rules: {}, configs: {} }},
36
+ plugin() { return { meta: { name: pkgName }, rules: {}, configs: {} }},
35
37
 
36
38
  rules(plugin) {
37
39
  plugin.rules = {
@@ -42,6 +44,6 @@ export default {
42
44
  'require-new': requireNew
43
45
  }
44
46
  for (const [ruleId, rule] of Object.entries(plugin.rules))
45
- rule.meta.docs.url = `https://codeberg.org/adamlui/eslint-plugin-${namespace}/#${ruleId}`
47
+ rule.meta.docs.url = `https://codeberg.org/adamlui/${pkgName}/#${ruleId}`
46
48
  }
47
49
  }
@@ -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
+ }