@maltjoy/eslint-rules 0.2.0 → 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
@@ -2,6 +2,8 @@
2
2
 
3
3
  Custom ESLint rules for Maltjoy design system usage.
4
4
 
5
+ This package is **ESM-only** (`"type": "module"`). Use `import` from `eslint.config.mjs` / `eslint.config.js` (with ESM).
6
+
5
7
  ## Rules
6
8
 
7
9
  - `no-vjoybutton-circle`: disallow `circle` prop usage on `VJoyButton`.
@@ -12,15 +14,21 @@ Message:
12
14
 
13
15
  - `no-vjoyinput-type-password`: disallow `VJoyInput` with `type="password"` (or a literal `:type` bound to `password`). Use `VJoyInputPassword` instead.
14
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
+
15
23
  ## Usage (flat config)
16
24
 
17
25
  **Preset (recommended)** — active toutes les règles du design system d’un coup :
18
26
 
19
27
  ```js
20
- const maltjoyRules = require('@maltjoy/eslint-rules');
21
- const vueParser = require('vue-eslint-parser');
28
+ import maltjoyRules from '@maltjoy/eslint-rules';
29
+ import vueParser from 'vue-eslint-parser';
22
30
 
23
- module.exports = [
31
+ export default [
24
32
  {
25
33
  files: ['**/*.vue'],
26
34
  languageOptions: {
@@ -45,9 +53,9 @@ Les sévérités par défaut du preset sont en `error`. Pour assouplir une règl
45
53
  **Règles à la carte** (sans preset) :
46
54
 
47
55
  ```js
48
- const maltjoyRules = require('@maltjoy/eslint-rules');
56
+ import maltjoyRules from '@maltjoy/eslint-rules';
49
57
 
50
- module.exports = [
58
+ export default [
51
59
  {
52
60
  plugins: {'@maltjoy/eslint-rules': maltjoyRules},
53
61
  rules: {
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type {Linter, Rule} from 'eslint';
2
+
3
+ /**
4
+ * `@maltjoy/eslint-rules` — ESLint plugin (flat config) for Maltjoy Vue design-system rules.
5
+ *
6
+ * Types depend on the `eslint` package (peer dependency); install `eslint` in the project that consumes this plugin.
7
+ */
8
+ declare const maltjoyEslintRules: {
9
+ readonly rules: Readonly<Record<string, Rule.RuleModule>>;
10
+ readonly configs: {
11
+ readonly recommended: ReadonlyArray<Linter.Config>;
12
+ };
13
+ };
14
+
15
+ export default maltjoyEslintRules;
package/index.js CHANGED
@@ -1,9 +1,11 @@
1
- const noVJoyButtonCircle = require('./rules/no-vjoybutton-circle');
2
- const noVJoyInputTypePassword = require('./rules/no-vjoyinput-type-password');
1
+ import noVJoyButtonCircle from './rules/no-vjoybutton-circle.js';
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,8 +22,9 @@ 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
  ];
26
29
 
27
- module.exports = plugin;
30
+ export default plugin;
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "@maltjoy/eslint-rules",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Custom ESLint rules for the @maltjoy/core-vue design system",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.js",
12
+ "default": "./index.js"
13
+ }
14
+ },
6
15
  "files": [
7
16
  "index.js",
17
+ "index.d.ts",
8
18
  "rules",
9
19
  "README.md"
10
20
  ],
@@ -23,7 +23,7 @@ function isVJoyButtonElement(node) {
23
23
  return node.name.toLowerCase() === 'vjoybutton';
24
24
  }
25
25
 
26
- module.exports = {
26
+ export default {
27
27
  meta: {
28
28
  type: 'suggestion',
29
29
  docs: {
@@ -60,7 +60,7 @@ function isVJoyInputElement(node) {
60
60
  return node.name.toLowerCase() === 'vjoyinput';
61
61
  }
62
62
 
63
- module.exports = {
63
+ export default {
64
64
  meta: {
65
65
  type: 'suggestion',
66
66
  docs: {
@@ -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
+ };