@dxos/eslint-plugin-rules 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- 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:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- 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.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -16,4 +16,4 @@ pnpm i @dxos/eslint-plugin-rules
16
16
 
17
17
  Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
18
18
 
19
- License: [MIT](./LICENSE) Copyright 2022 © DXOS
19
+ License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
package/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import fs from 'node:fs';
6
6
 
7
7
  import comment from './rules/comment.js';
8
+ import consistentUpdateParam from './rules/consistent-update-param.js';
8
9
  import effectSubpathImports from './rules/effect-subpath-imports.js';
9
10
  import header from './rules/header.js';
10
11
  import importAsNamespace from './rules/import-as-namespace.js';
@@ -23,6 +24,7 @@ const plugin = {
23
24
  },
24
25
  rules: {
25
26
  comment,
27
+ 'consistent-update-param': consistentUpdateParam,
26
28
  'effect-subpath-imports': effectSubpathImports,
27
29
  header,
28
30
  'import-as-namespace': importAsNamespace,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dxos/eslint-plugin-rules",
3
- "version": "0.8.4-main.74a063c4e0",
3
+ "version": "0.8.4-main.765dc60934",
4
4
  "homepage": "https://dxos.org",
5
5
  "bugs": "https://github.com/dxos/dxos/issues",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/dxos/dxos"
9
9
  },
10
- "license": "MIT",
10
+ "license": "FSL-1.1-Apache-2.0",
11
11
  "author": "info@dxos.org",
12
12
  "sideEffects": true,
13
13
  "type": "module",
@@ -0,0 +1,143 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ /**
6
+ * ESLint rule to enforce that the callback parameter name in Obj.update(),
7
+ * Relation.update(), and Entity.update() matches the first argument name.
8
+ *
9
+ * @example
10
+ * // ❌ Bad
11
+ * Obj.update(trigger, (t) => { t.enabled = true; });
12
+ * Obj.update(trigger, (mutableTrigger) => { mutableTrigger.enabled = true; });
13
+ *
14
+ * // ✅ Good
15
+ * Obj.update(trigger, (trigger) => { trigger.enabled = true; });
16
+ */
17
+ export default {
18
+ meta: {
19
+ type: 'suggestion',
20
+ docs: {
21
+ description:
22
+ 'Enforce callback parameter name matches the first argument in Obj.update, Relation.update, and Entity.update.',
23
+ category: 'Best Practices',
24
+ recommended: true,
25
+ },
26
+ fixable: 'code',
27
+ schema: [],
28
+ messages: {
29
+ mismatchedName:
30
+ 'Callback parameter "{{callbackParam}}" should be "{{firstArg}}" to match the first argument of {{caller}}.update().',
31
+ },
32
+ },
33
+ create(context) {
34
+ /** Yield all Identifier reference nodes for `name` inside `node`, respecting scope shadowing. */
35
+ function* collectReferences(node, name) {
36
+ if (!node || typeof node !== 'object' || !node.type) {
37
+ return;
38
+ }
39
+
40
+ if (
41
+ node.type === 'ArrowFunctionExpression' ||
42
+ node.type === 'FunctionExpression' ||
43
+ node.type === 'FunctionDeclaration'
44
+ ) {
45
+ if (node.params?.some((p) => p.type === 'Identifier' && p.name === name)) {
46
+ return;
47
+ }
48
+ yield* collectReferences(node.body, name);
49
+ return;
50
+ }
51
+
52
+ if (node.type === 'Identifier' && node.name === name) {
53
+ yield node;
54
+ return;
55
+ }
56
+
57
+ for (const key of Object.keys(node)) {
58
+ if (key === 'parent') {
59
+ continue;
60
+ }
61
+ if (node.type === 'MemberExpression' && key === 'property' && !node.computed) {
62
+ continue;
63
+ }
64
+ if (node.type === 'Property' && key === 'key' && !node.computed && !node.shorthand) {
65
+ continue;
66
+ }
67
+
68
+ const child = node[key];
69
+ if (Array.isArray(child)) {
70
+ for (const item of child) {
71
+ if (item && typeof item === 'object' && item.type) {
72
+ yield* collectReferences(item, name);
73
+ }
74
+ }
75
+ } else if (child && typeof child === 'object' && child.type) {
76
+ yield* collectReferences(child, name);
77
+ }
78
+ }
79
+ }
80
+
81
+ return {
82
+ CallExpression(node) {
83
+ const { callee } = node;
84
+
85
+ if (
86
+ callee.type !== 'MemberExpression' ||
87
+ callee.object.type !== 'Identifier' ||
88
+ !['Obj', 'Relation', 'Entity'].includes(callee.object.name) ||
89
+ callee.property.type !== 'Identifier' ||
90
+ callee.property.name !== 'update'
91
+ ) {
92
+ return;
93
+ }
94
+
95
+ const args = node.arguments;
96
+ if (args.length < 2) {
97
+ return;
98
+ }
99
+
100
+ const firstArg = args[0];
101
+ const callback = args[1];
102
+
103
+ if (firstArg.type !== 'Identifier') {
104
+ return;
105
+ }
106
+ if (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression') {
107
+ return;
108
+ }
109
+ if (callback.params.length !== 1) {
110
+ return;
111
+ }
112
+
113
+ const param = callback.params[0];
114
+ if (param.type !== 'Identifier') {
115
+ return;
116
+ }
117
+ if (param.name === firstArg.name) {
118
+ return;
119
+ }
120
+
121
+ context.report({
122
+ node: param,
123
+ messageId: 'mismatchedName',
124
+ data: {
125
+ callbackParam: param.name,
126
+ firstArg: firstArg.name,
127
+ caller: callee.object.name,
128
+ },
129
+ fix(fixer) {
130
+ const oldName = param.name;
131
+ const newName = firstArg.name;
132
+
133
+ const fixes = [fixer.replaceTextRange([param.range[0], param.range[0] + oldName.length], newName)];
134
+ for (const ref of collectReferences(callback.body, oldName)) {
135
+ fixes.push(fixer.replaceTextRange([ref.range[0], ref.range[0] + oldName.length], newName));
136
+ }
137
+ return fixes;
138
+ },
139
+ });
140
+ },
141
+ };
142
+ },
143
+ };
@@ -47,7 +47,9 @@ export default {
47
47
  const exportsCache = new Map(); // packageName -> Set<segment>
48
48
 
49
49
  const loadExportsForPackage = (pkgName) => {
50
- if (exportsCache.has(pkgName)) return exportsCache.get(pkgName);
50
+ if (exportsCache.has(pkgName)) {
51
+ return exportsCache.get(pkgName);
52
+ }
51
53
  try {
52
54
  const pkgJson = requireForFile(`${pkgName}/package.json`);
53
55
  const ex = pkgJson && pkgJson.exports;
@@ -55,8 +57,12 @@ export default {
55
57
  if (ex && typeof ex === 'object') {
56
58
  for (const key of Object.keys(ex)) {
57
59
  // Keys like './Schema', './SchemaAST', './Function' (skip '.' and './package.json').
58
- if (key === '.' || key === './package.json') continue;
59
- if (key.startsWith('./')) segments.add(key.slice(2));
60
+ if (key === '.' || key === './package.json') {
61
+ continue;
62
+ }
63
+ if (key.startsWith('./')) {
64
+ segments.add(key.slice(2));
65
+ }
60
66
  }
61
67
  }
62
68
  exportsCache.set(pkgName, segments);
@@ -74,7 +80,9 @@ export default {
74
80
  };
75
81
 
76
82
  const resolveExportToSegment = (pkgName, exportName) => {
77
- if (isValidSubpath(pkgName, exportName)) return exportName;
83
+ if (isValidSubpath(pkgName, exportName)) {
84
+ return exportName;
85
+ }
78
86
  if (pkgName === 'effect' && EFFECT_EXPORT_TO_SUBPATH[exportName]) {
79
87
  const segment = EFFECT_EXPORT_TO_SUBPATH[exportName];
80
88
  return isValidSubpath(pkgName, segment) ? segment : null;
@@ -110,9 +118,13 @@ export default {
110
118
  return {
111
119
  ImportDeclaration: (node) => {
112
120
  const source = String(node.source.value);
113
- if (!isEffectPackage(source)) return;
121
+ if (!isEffectPackage(source)) {
122
+ return;
123
+ }
114
124
  const basePackage = getBasePackage(source);
115
- if (shouldSkipEffectPackage(basePackage)) return;
125
+ if (shouldSkipEffectPackage(basePackage)) {
126
+ return;
127
+ }
116
128
 
117
129
  // If it's a subpath import (e.g., 'effect/Schema'), enforce namespace import except for allowed subpaths.
118
130
  if (source.startsWith(basePackage + '/')) {
@@ -148,10 +160,15 @@ export default {
148
160
  const typeImports = [];
149
161
  const regularImports = [];
150
162
  for (const specifier of node.specifiers) {
151
- if (specifier.type !== 'ImportSpecifier') continue;
163
+ if (specifier.type !== 'ImportSpecifier') {
164
+ continue;
165
+ }
152
166
  const entry = { imported: specifier.imported.name, local: specifier.local.name };
153
- if (specifier.importKind === 'type') typeImports.push(entry);
154
- else regularImports.push(entry);
167
+ if (specifier.importKind === 'type') {
168
+ typeImports.push(entry);
169
+ } else {
170
+ regularImports.push(entry);
171
+ }
155
172
  }
156
173
 
157
174
  // Partition into resolvable vs unresolved specifiers (resolved entries include segment for fix).
@@ -162,13 +179,19 @@ export default {
162
179
 
163
180
  typeImports.forEach((spec) => {
164
181
  const segment = resolveExportToSegment(packageName, spec.imported);
165
- if (segment) resolvedType.push({ ...spec, segment });
166
- else unresolvedType.push(spec);
182
+ if (segment) {
183
+ resolvedType.push({ ...spec, segment });
184
+ } else {
185
+ unresolvedType.push(spec);
186
+ }
167
187
  });
168
188
  regularImports.forEach((spec) => {
169
189
  const segment = resolveExportToSegment(packageName, spec.imported);
170
- if (segment) resolvedRegular.push({ ...spec, segment });
171
- else unresolvedRegular.push(spec);
190
+ if (segment) {
191
+ resolvedRegular.push({ ...spec, segment });
192
+ } else {
193
+ unresolvedRegular.push(spec);
194
+ }
172
195
  });
173
196
 
174
197
  const unresolved = [...unresolvedType, ...unresolvedRegular].map(({ imported }) => imported);
@@ -214,7 +237,9 @@ export default {
214
237
  const useNamed = NAMED_IMPORT_ALLOWED_SUBPATHS.has(segment);
215
238
  const merged = [...group.regular];
216
239
  for (const t of group.type) {
217
- if (!group.regular.some((r) => r.local === t.local)) merged.push(t);
240
+ if (!group.regular.some((r) => r.local === t.local)) {
241
+ merged.push(t);
242
+ }
218
243
  }
219
244
  if (useNamed && merged.length > 0) {
220
245
  const specParts = merged.map(({ imported, local }) =>
@@ -225,7 +250,9 @@ export default {
225
250
  const seen = new Set();
226
251
  for (const { imported, local } of merged) {
227
252
  const alias = imported !== local ? local : imported;
228
- if (seen.has(alias)) continue;
253
+ if (seen.has(alias)) {
254
+ continue;
255
+ }
229
256
  seen.add(alias);
230
257
  const isTypeOnly =
231
258
  group.type.some((t) => t.imported === imported) &&
@@ -249,7 +276,9 @@ export default {
249
276
  });
250
277
  unresolvedType.forEach((s) => {
251
278
  const entry = byLocal.get(s.local) ?? {};
252
- if (!entry.value) entry.type = s; // only keep type if no value for same local
279
+ if (!entry.value) {
280
+ entry.type = s;
281
+ } // only keep type if no value for same local
253
282
  byLocal.set(s.local, entry);
254
283
  });
255
284
 
@@ -265,14 +294,18 @@ export default {
265
294
  specParts.push(part);
266
295
  }
267
296
  }
268
- if (specParts.length) imports.push(`import { ${specParts.join(', ')} } from '${packageName}';`);
297
+ if (specParts.length) {
298
+ imports.push(`import { ${specParts.join(', ')} } from '${packageName}';`);
299
+ }
269
300
  }
270
301
 
271
302
  // Get the original import's indentation.
272
303
  const importIndent = sourceCode.text.slice(node.range[0] - node.loc.start.column, node.range[0]);
273
304
 
274
305
  // Join imports with newline and proper indentation.
275
- if (imports.length === 0) return null; // nothing to change
306
+ if (imports.length === 0) {
307
+ return null;
308
+ } // nothing to change
276
309
  const newImports = imports.join('\n' + importIndent);
277
310
 
278
311
  return fixer.replaceText(node, newImports);