@almadar/eslint-plugin 2.1.1 → 2.2.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/index.js CHANGED
@@ -9,6 +9,7 @@ const templateSerializableProps = require("./rules/template-serializable-props")
9
9
  const noTypeProp = require("./rules/no-type-prop");
10
10
  const noAsAny = require("./rules/no-as-any");
11
11
  const noImportGenerated = require("./rules/no-import-generated");
12
+ const noUseNavigate = require("./rules/no-use-navigate");
12
13
  const requireEventBus = require("./rules/require-event-bus");
13
14
  const requireDisplayName = require("./rules/require-display-name");
14
15
  const requireClosedCircuitProps = require("./rules/require-closed-circuit-props");
@@ -47,6 +48,7 @@ const plugin = {
47
48
  "no-type-prop": noTypeProp,
48
49
  "no-as-any": noAsAny,
49
50
  "no-import-generated": noImportGenerated,
51
+ "no-use-navigate": noUseNavigate,
50
52
  "require-event-bus": requireEventBus,
51
53
  "require-display-name": requireDisplayName,
52
54
  "require-closed-circuit-props": requireClosedCircuitProps,
@@ -89,6 +91,7 @@ plugin.configs.recommended = {
89
91
  "almadar/no-type-prop": "error",
90
92
  "almadar/no-as-any": "error",
91
93
  "almadar/no-import-generated": "error",
94
+ "almadar/no-use-navigate": "error",
92
95
 
93
96
  // Warn-level — conventions that should be followed
94
97
  "almadar/require-event-bus": "warn",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/eslint-plugin",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "private": false,
5
5
  "description": "Custom ESLint rules for Almadar component architecture",
6
6
  "main": "index.js",
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ meta: {
5
+ type: "problem",
6
+ docs: {
7
+ description:
8
+ "Disallow useNavigate from react-router-dom. Use useEventBus and emit UI:NAVIGATE instead.",
9
+ category: "Almadar Architecture",
10
+ },
11
+ messages: {
12
+ noUseNavigate:
13
+ "Do not use useNavigate() from react-router-dom. Emit 'UI:NAVIGATE' via useEventBus instead for closed circuit compliance.",
14
+ noReactRouterNavigate:
15
+ "Do not import useNavigate from react-router-dom. Use useEventBus().emit('UI:NAVIGATE', { url }) instead.",
16
+ },
17
+ schema: [],
18
+ },
19
+
20
+ create(context) {
21
+ return {
22
+ // Catch: import { useNavigate } from 'react-router-dom'
23
+ ImportDeclaration(node) {
24
+ if (
25
+ node.source &&
26
+ node.source.value === "react-router-dom" &&
27
+ node.specifiers
28
+ ) {
29
+ for (const specifier of node.specifiers) {
30
+ if (
31
+ specifier.type === "ImportSpecifier" &&
32
+ specifier.imported &&
33
+ specifier.imported.name === "useNavigate"
34
+ ) {
35
+ context.report({
36
+ node: specifier,
37
+ messageId: "noReactRouterNavigate",
38
+ });
39
+ }
40
+ }
41
+ }
42
+ },
43
+ // Catch: useNavigate() call expressions
44
+ CallExpression(node) {
45
+ if (
46
+ node.callee.type === "Identifier" &&
47
+ node.callee.name === "useNavigate"
48
+ ) {
49
+ context.report({
50
+ node,
51
+ messageId: "noUseNavigate",
52
+ });
53
+ }
54
+ },
55
+ };
56
+ },
57
+ };