@dxos/eslint-plugin-rules 0.8.4-main.ead640a → 0.8.4-main.effb148878

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
@@ -0,0 +1,94 @@
1
+ # Translation Key Normalization
2
+
3
+ ## Status
4
+
5
+ ESLint rule and migration script ready. Tested on `plugin-chess`.
6
+
7
+ ## Problem
8
+
9
+ 1,326 translation keys across 56 plugins use inconsistent space-separated naming with no enforced suffix convention. 135 keys lack a type suffix entirely. This makes it hard to grep, autocomplete, or validate keys.
10
+
11
+ ## Convention
12
+
13
+ **Format:** `segment.kebab-case.suffix`
14
+
15
+ ```
16
+ settings.debug.label
17
+ add-comment.label
18
+ object-name.placeholder
19
+ add-section.before-dialog.title
20
+ typename.label_other
21
+ ```
22
+
23
+ ### Rules
24
+
25
+ - Every key ends with a **type suffix**: `label | message | placeholder | title | description | heading | alt | button`.
26
+ - Plural suffixes append after the type suffix: `typename.label_zero`, `lobby.participants_other`.
27
+ - Dots separate hierarchical segments; segments use kebab-case.
28
+ - `plugin name` keys become `plugin.label`.
29
+
30
+ ## Tools
31
+
32
+ ### 1. ESLint Rule (ongoing enforcement)
33
+
34
+ `packages/common/eslint-plugin-rules/rules/translation-key-format.js`
35
+
36
+ Registered in `.oxlintrc.json` as `@dxos/eslint-plugin-rules/translation-key-format` (currently `warn`).
37
+
38
+ **Checks:**
39
+
40
+ - `useDotsNotSpaces` — flags space-separated keys, suggests dot.kebab-case, auto-fixable.
41
+ - `missingSuffix` — flags keys missing a valid type suffix (not auto-fixable, needs human decision).
42
+
43
+ **Catches violations in:**
44
+
45
+ - `t('key')` calls in source files.
46
+ - Property keys in `translations.ts` files (string literal keys with string literal values).
47
+
48
+ **Auto-fix:** `moon run plugin-name:lint -- --fix` rewrites both definitions and usages.
49
+
50
+ **Promote to error** once migration is complete to prevent regressions.
51
+
52
+ ### 2. Checker Script (bulk analysis)
53
+
54
+ `scripts/check-translations.mts` — run via `npx tsx scripts/check-translations.mts`.
55
+
56
+ Reports:
57
+
58
+ | Check | Current Count |
59
+ | -------------------------------------- | ------------- |
60
+ | Missing keys (used but undefined) | 68 |
61
+ | Unused keys (defined but unreferenced) | 444 |
62
+ | Incomplete plurals | 8 |
63
+ | Missing suffix | 135 |
64
+ | Non-hierarchical (space-separated) | 1,326 |
65
+
66
+ Use this for bulk analysis, migration planning, and tracking progress.
67
+
68
+ ## Migration Plan
69
+
70
+ ### Step 1: Fix known edge cases in normalizer
71
+
72
+ - `plugin name` → `plugin.label` (special case).
73
+ - Keys ending in nouns (`key`, `name`, `count`, `period`) that aren't valid suffixes need a suffix appended.
74
+
75
+ ### Step 2: Migrate incrementally with `--fix`
76
+
77
+ Per plugin: `moon run plugin-name:lint -- --fix`, then verify with `moon run plugin-name:lint`.
78
+
79
+ Start with small plugins (`plugin-chess`, `plugin-template`), then batch the rest.
80
+
81
+ ### Step 3: Validate
82
+
83
+ - Re-run checker script to confirm counts decrease.
84
+ - Build + test the migrated plugins.
85
+
86
+ ### Step 4: Promote to error
87
+
88
+ Change `.oxlintrc.json` from `"warn"` to `"error"` once all plugins are clean.
89
+
90
+ ## Out of Scope
91
+
92
+ - Moving to JSON files.
93
+ - Cleaning up unused keys (separate effort using checker output).
94
+ - UI packages / `osTranslations` namespace (phase 2).
package/docs/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # @dxos/eslint-plugin-rules
2
2
 
3
-
4
-
5
3
  ## Dependency Graph
6
4
 
7
5
  ```mermaid
@@ -28,4 +26,4 @@ linkStyle default stroke:#333,stroke-width:1px
28
26
  ## Dependencies
29
27
 
30
28
  | Module | Direct |
31
- |---|---|
29
+ | ------ | ------ |
package/index.js CHANGED
@@ -2,11 +2,17 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ import fs from 'node:fs';
6
+
5
7
  import comment from './rules/comment.js';
8
+ import consistentUpdateParam from './rules/consistent-update-param.js';
6
9
  import effectSubpathImports from './rules/effect-subpath-imports.js';
7
10
  import header from './rules/header.js';
11
+ import importAsNamespace from './rules/import-as-namespace.js';
12
+ import noBareDotImports from './rules/no-bare-dot-imports.js';
13
+ import noEffectRunPromise from './rules/no-effect-run-promise.js';
8
14
  import noEmptyPromiseCatch from './rules/no-empty-promise-catch.js';
9
- import fs from 'node:fs';
15
+ import translationKeyFormat from './rules/translation-key-format.js';
10
16
 
11
17
  const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
12
18
 
@@ -18,9 +24,14 @@ const plugin = {
18
24
  },
19
25
  rules: {
20
26
  comment,
27
+ 'consistent-update-param': consistentUpdateParam,
21
28
  'effect-subpath-imports': effectSubpathImports,
22
29
  header,
30
+ 'import-as-namespace': importAsNamespace,
31
+ 'no-bare-dot-imports': noBareDotImports,
32
+ 'no-effect-run-promise': noEffectRunPromise,
23
33
  'no-empty-promise-catch': noEmptyPromiseCatch,
34
+ 'translation-key-format': translationKeyFormat,
24
35
  },
25
36
  configs: {
26
37
  recommended: {
@@ -30,6 +41,9 @@ const plugin = {
30
41
  rules: {
31
42
  'dxos-plugin/effect-subpath-imports': 'error',
32
43
  'dxos-plugin/header': 'error',
44
+ 'dxos-plugin/import-as-namespace': 'error',
45
+ 'dxos-plugin/no-bare-dot-imports': 'error',
46
+ 'dxos-plugin/no-effect-run-promise': 'error',
33
47
  'dxos-plugin/no-empty-promise-catch': 'error',
34
48
  // TODO(dmaretskyi): Turned off due to large number of errors and no auto-fix.
35
49
  // 'dxos-plugin/comment': 'error',
package/moon.yml CHANGED
@@ -1,2 +1,2 @@
1
- type: library
1
+ layer: library
2
2
  language: typescript
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@dxos/eslint-plugin-rules",
3
- "version": "0.8.4-main.ead640a",
3
+ "version": "0.8.4-main.effb148878",
4
4
  "homepage": "https://dxos.org",
5
5
  "bugs": "https://github.com/dxos/dxos/issues",
6
- "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/dxos/dxos"
9
+ },
10
+ "license": "FSL-1.1-Apache-2.0",
7
11
  "author": "info@dxos.org",
8
12
  "sideEffects": true,
9
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
+ };