@cratis/eslint-plugin-arc 20.44.2 → 20.45.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 CHANGED
@@ -7,6 +7,7 @@ base config, [`@cratis/eslint-config`](https://www.npmjs.com/package/@cratis/esl
7
7
  |---|---|
8
8
  | `skip-generated-proxies` (processor) | Skips Arc-generated proxy files wholesale. They carry a `// @generated by Cratis` header (and a `**DO NOT EDIT**` banner), cannot be edited, and are regenerated by the build — so any finding on them is un-actionable. Keyed on the header because proxies sit intermixed with hand-written `.ts`. |
9
9
  | `no-hooks-in-view-model` | Disallows React hook calls inside MVVM view models (classes named `*ViewModel`). A view model must be a plain, React-free class; inject Cratis abstractions instead of calling hooks. |
10
+ | `no-direct-mobx-react-import` | Disallows direct imports from `mobx-react` or `mobx-react-lite`. The MobX binding is an internal detail of `@cratis/arc.react.mvvm`, which re-exports `observer` (the sanctioned leaf observer boundary) — import it from there so the binding can evolve without breaking consumers. |
10
11
 
11
12
  ## Install
12
13
 
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { noHooksInViewModel } from './lib/noHooksInViewModel.js';
3
+ import { noDirectMobxReactImport } from './lib/noDirectMobxReactImport.js';
3
4
  import { isGeneratedProxy, skipGeneratedProxies } from './lib/skipGeneratedProxies.js';
4
5
 
5
6
  const { version } = createRequire(import.meta.url)('./package.json');
@@ -10,7 +11,10 @@ const { version } = createRequire(import.meta.url)('./package.json');
10
11
  // directly. Composes on top of @cratis/eslint-config.
11
12
  const plugin = {
12
13
  meta: { name: '@cratis/eslint-plugin-arc', version },
13
- rules: { 'no-hooks-in-view-model': noHooksInViewModel },
14
+ rules: {
15
+ 'no-hooks-in-view-model': noHooksInViewModel,
16
+ 'no-direct-mobx-react-import': noDirectMobxReactImport,
17
+ },
14
18
  processors: { 'skip-generated-proxies': skipGeneratedProxies },
15
19
  configs: {},
16
20
  };
@@ -33,6 +37,7 @@ Object.assign(plugin.configs, {
33
37
  plugins: { '@cratis/arc': plugin },
34
38
  rules: {
35
39
  '@cratis/arc/no-hooks-in-view-model': 'error',
40
+ '@cratis/arc/no-direct-mobx-react-import': 'error',
36
41
  },
37
42
  },
38
43
  ],
@@ -40,4 +45,4 @@ Object.assign(plugin.configs, {
40
45
 
41
46
  export default plugin;
42
47
  export const { configs, rules, processors, meta } = plugin;
43
- export { noHooksInViewModel, skipGeneratedProxies, isGeneratedProxy };
48
+ export { noHooksInViewModel, noDirectMobxReactImport, skipGeneratedProxies, isGeneratedProxy };
@@ -0,0 +1,33 @@
1
+ const FORBIDDEN_MODULES = new Set(['mobx-react', 'mobx-react-lite']);
2
+
3
+ // Flags direct imports from 'mobx-react' or 'mobx-react-lite'. In a Cratis Arc application the
4
+ // MobX binding is an internal detail of @cratis/arc.react.mvvm: 'observer' (the sanctioned leaf
5
+ // observer boundary) is re-exported from there, so consumers should never reach for the underlying
6
+ // MobX React packages directly. Importing 'observer' through @cratis/arc.react.mvvm lets the binding
7
+ // evolve without breaking consumers and keeps the sanctioned boundary discoverable.
8
+ export const noDirectMobxReactImport = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: "Disallow direct imports from 'mobx-react' or 'mobx-react-lite'; import 'observer' from '@cratis/arc.react.mvvm' instead.",
13
+ recommended: true,
14
+ url: 'https://github.com/Cratis/Arc/blob/main/Source/JavaScript/Arc.ESLint/README.md',
15
+ },
16
+ schema: [],
17
+ messages: {
18
+ noDirectImport: "Do not import from '{{module}}'. Import 'observer' from '@cratis/arc.react.mvvm' instead — the MobX binding is an internal detail of Cratis Arc MVVM.",
19
+ },
20
+ },
21
+ create(context) {
22
+ return {
23
+ ImportDeclaration(node) {
24
+ const module = node.source.value;
25
+ if (FORBIDDEN_MODULES.has(module)) {
26
+ context.report({ node: node.source, messageId: 'noDirectImport', data: { module } });
27
+ }
28
+ },
29
+ };
30
+ },
31
+ };
32
+
33
+ export default noDirectMobxReactImport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/eslint-plugin-arc",
3
- "version": "20.44.2",
3
+ "version": "20.45.0",
4
4
  "description": "Cratis Arc ESLint rules: skip generated proxies and keep MVVM view models React-free. Compose on top of @cratis/eslint-config.",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",