@maltjoy/eslint-rules 0.2.1 → 0.3.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
@@ -14,6 +14,12 @@ Message:
14
14
 
15
15
  - `no-vjoyinput-type-password`: disallow `VJoyInput` with `type="password"` (or a literal `:type` bound to `password`). Use `VJoyInputPassword` instead.
16
16
 
17
+ - `no-vjoyinput-unit`: disallow `unit` prop usage on `VJoyInput`. Use `VJoyInputNumber` instead.
18
+
19
+ Message:
20
+
21
+ `Do not use VJoyInput with unit, use VJoyInputNumber instead.`
22
+
17
23
  ## Usage (flat config)
18
24
 
19
25
  **Preset (recommended)** — active toutes les règles du design system d’un coup :
package/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import noVJoyButtonCircle from './rules/no-vjoybutton-circle.js';
2
2
  import noVJoyInputTypePassword from './rules/no-vjoyinput-type-password.js';
3
+ import noVJoyInputUnit from './rules/no-vjoyinput-unit.js';
3
4
 
4
5
  const rules = {
5
6
  'no-vjoybutton-circle': noVJoyButtonCircle,
6
7
  'no-vjoyinput-type-password': noVJoyInputTypePassword,
8
+ 'no-vjoyinput-unit': noVJoyInputUnit,
7
9
  };
8
10
 
9
11
  const plugin = {
@@ -20,6 +22,7 @@ plugin.configs.recommended = [
20
22
  rules: {
21
23
  '@maltjoy/eslint-rules/no-vjoybutton-circle': 'error',
22
24
  '@maltjoy/eslint-rules/no-vjoyinput-type-password': 'error',
25
+ '@maltjoy/eslint-rules/no-vjoyinput-unit': 'error',
23
26
  },
24
27
  },
25
28
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maltjoy/eslint-rules",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Custom ESLint rules for the @maltjoy/core-vue design system",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -0,0 +1,75 @@
1
+ const ERROR_MESSAGE =
2
+ 'Do not use VJoyInput with unit property, use VJoyInputNumber instead.';
3
+
4
+ function isUnitAttribute(node) {
5
+ if (!node || node.type !== 'VAttribute') {
6
+ return false;
7
+ }
8
+
9
+ if (!node.directive) {
10
+ return node.key && node.key.name === 'unit';
11
+ }
12
+
13
+ const directiveName = node.key && node.key.name && node.key.name.name;
14
+ const argumentName = node.key && node.key.argument && node.key.argument.name;
15
+
16
+ return directiveName === 'bind' && argumentName === 'unit';
17
+ }
18
+
19
+ function isVJoyInputElement(node) {
20
+ if (!node || node.type !== 'VElement' || typeof node.name !== 'string') {
21
+ return false;
22
+ }
23
+
24
+ return node.name.toLowerCase() === 'vjoyinput';
25
+ }
26
+
27
+ export default {
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description: 'disallow VJoyInput with unit prop; use VJoyInputNumber',
32
+ recommended: false,
33
+ },
34
+ schema: [],
35
+ messages: {
36
+ useVJoyInputNumber: ERROR_MESSAGE,
37
+ },
38
+ },
39
+ create(context) {
40
+ function visitElement(node) {
41
+ if (!node || node.type !== 'VElement') {
42
+ return;
43
+ }
44
+
45
+ if (isVJoyInputElement(node) && node.startTag && Array.isArray(node.startTag.attributes)) {
46
+ node.startTag.attributes.forEach((attribute) => {
47
+ if (isUnitAttribute(attribute)) {
48
+ context.report({
49
+ node: attribute,
50
+ messageId: 'useVJoyInputNumber',
51
+ });
52
+ }
53
+ });
54
+ }
55
+
56
+ if (!Array.isArray(node.children)) {
57
+ return;
58
+ }
59
+
60
+ node.children.forEach((child) => {
61
+ visitElement(child);
62
+ });
63
+ }
64
+
65
+ return {
66
+ Program(programNode) {
67
+ if (!programNode || !programNode.templateBody) {
68
+ return;
69
+ }
70
+
71
+ visitElement(programNode.templateBody);
72
+ },
73
+ };
74
+ },
75
+ };