@adyen/eslint-plugin-bento 2.9.0 → 2.10.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/configs/vue-recommended.js +5 -0
  3. package/configs/vue-strict.js +5 -0
  4. package/index.js +5 -0
  5. package/package.json +1 -1
  6. package/rules/deprecation-bento-popover-modifiers-prop/README.md +23 -0
  7. package/rules/deprecation-bento-popover-modifiers-prop/__tests__/deprecation-bento-popover-modifiers-prop.vue +9 -0
  8. package/rules/deprecation-bento-popover-modifiers-prop/__tests__/eslint.config.js +26 -0
  9. package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.integration.test.ts +24 -0
  10. package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.js +78 -0
  11. package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.test.ts +109 -0
  12. package/rules/deprecation-bento-timeline-item-variant-prop/README.md +25 -0
  13. package/rules/deprecation-bento-timeline-item-variant-prop/__tests__/deprecation-bento-timeline-item-variant-prop.vue +9 -0
  14. package/rules/deprecation-bento-timeline-item-variant-prop/__tests__/eslint.config.js +26 -0
  15. package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.integration.test.ts +31 -0
  16. package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.js +78 -0
  17. package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.test.ts +66 -0
  18. package/rules/deprecation-components-aria-label-prop/README.md +62 -0
  19. package/rules/deprecation-components-aria-label-prop/__tests__/deprecation-components-aria-label-prop.vue +25 -0
  20. package/rules/deprecation-components-aria-label-prop/__tests__/eslint.config.js +26 -0
  21. package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.integration.test.ts +36 -0
  22. package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.js +79 -0
  23. package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.test.ts +194 -0
  24. package/rules/deprecation-components-has-error-prop/README.md +34 -0
  25. package/rules/deprecation-components-has-error-prop/__tests__/deprecation-components-has-error-prop.vue +13 -0
  26. package/rules/deprecation-components-has-error-prop/__tests__/eslint.config.js +26 -0
  27. package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.integration.test.ts +29 -0
  28. package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.js +77 -0
  29. package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.test.ts +133 -0
  30. package/rules/deprecation-input-filter-dropdown-options/README.md +44 -0
  31. package/rules/deprecation-input-filter-dropdown-options/__tests__/deprecation-input-filter-dropdown-options.vue +46 -0
  32. package/rules/deprecation-input-filter-dropdown-options/__tests__/eslint.config.js +26 -0
  33. package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.integration.test.ts +27 -0
  34. package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.js +135 -0
  35. package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.test.ts +392 -0
@@ -0,0 +1,133 @@
1
+ import { RuleTester } from 'eslint';
2
+ import vueParser from 'vue-eslint-parser';
3
+ import tsParser from '@typescript-eslint/parser';
4
+ import deprecationComponentsHasErrorProp from './deprecation-components-has-error-prop';
5
+
6
+ const ruleTester = new RuleTester({
7
+ languageOptions: {
8
+ ecmaVersion: 'latest',
9
+ sourceType: 'module',
10
+ parser: vueParser,
11
+ parserOptions: {
12
+ parser: tsParser,
13
+ },
14
+ },
15
+ });
16
+
17
+ describe('@adyen/bento/deprecation-components-has-error-prop', () => {
18
+ ruleTester.run('deprecation-components-has-error-prop', deprecationComponentsHasErrorProp, {
19
+ valid: [
20
+ {
21
+ name: 'Valid usage for bento-checkbox-group',
22
+ filename: 'test.vue',
23
+ code: `
24
+ <template>
25
+ <bento-checkbox-group errorMessage="val" />
26
+ </template>
27
+ `,
28
+ },
29
+ {
30
+ name: 'Valid usage for bento-radio-group',
31
+ filename: 'test.vue',
32
+ code: `
33
+ <template>
34
+ <bento-radio-group errorMessage="val" />
35
+ </template>
36
+ `,
37
+ },
38
+ ],
39
+ invalid: [
40
+ // bento-checkbox-group: Static
41
+ {
42
+ name: 'Invalid: Static prop on bento-checkbox-group',
43
+ filename: 'test.vue',
44
+ code: `<template><bento-checkbox-group has-error="val" /></template>`,
45
+ errors: [{ messageId: 'deprecation' }],
46
+ },
47
+ // bento-checkbox-group: Shorthand
48
+ {
49
+ name: 'Invalid: Dynamic prop on bento-checkbox-group',
50
+ filename: 'test.vue',
51
+ code: `<template><bento-checkbox-group :has-error="val" /></template>`,
52
+ errors: [{ messageId: 'deprecation' }],
53
+ },
54
+ // bento-radio-group: Static
55
+ {
56
+ name: 'Invalid: Static prop on bento-radio-group',
57
+ filename: 'test.vue',
58
+ code: `<template><bento-radio-group has-error="val" /></template>`,
59
+ errors: [{ messageId: 'deprecation' }],
60
+ },
61
+ // bento-radio-group: Shorthand
62
+ {
63
+ name: 'Invalid: Dynamic prop on bento-radio-group',
64
+ filename: 'test.vue',
65
+ code: `<template><bento-radio-group :has-error="val" /></template>`,
66
+ errors: [{ messageId: 'deprecation' }],
67
+ },
68
+ ],
69
+ });
70
+
71
+ /* ------------------------------------------------ */
72
+ /* AUTOFIX TESTS */
73
+ /* ------------------------------------------------ */
74
+ ruleTester.run('deprecation-components-has-error-prop (autofix enabled)', deprecationComponentsHasErrorProp, {
75
+ valid: [
76
+ {
77
+ name: 'Valid: error-message prop on bento-checkbox-group (autofix enabled)',
78
+ filename: 'test.vue',
79
+ options: [{ autofix: true }],
80
+ code: `<template><bento-checkbox-group error-message="val" /></template>`,
81
+ },
82
+ ],
83
+ invalid: [
84
+ {
85
+ name: 'Autofix: static prop on bento-checkbox-group',
86
+ filename: 'test.vue',
87
+ options: [{ autofix: true }],
88
+ code: `<template><bento-checkbox-group has-error="val" /></template>`,
89
+ output: `<template><bento-checkbox-group error-message="val" /></template>`,
90
+ errors: [{ messageId: 'deprecation' }],
91
+ },
92
+ {
93
+ name: 'Autofix: dynamic prop on bento-checkbox-group',
94
+ filename: 'test.vue',
95
+ options: [{ autofix: true }],
96
+ code: `<template><bento-checkbox-group :has-error="val" /></template>`,
97
+ output: `<template><bento-checkbox-group :error-message="val" /></template>`,
98
+ errors: [{ messageId: 'deprecation' }],
99
+ },
100
+ {
101
+ name: 'Autofix: static prop on bento-radio-group',
102
+ filename: 'test.vue',
103
+ options: [{ autofix: true }],
104
+ code: `<template><bento-radio-group has-error="val" /></template>`,
105
+ output: `<template><bento-radio-group error-message="val" /></template>`,
106
+ errors: [{ messageId: 'deprecation' }],
107
+ },
108
+ {
109
+ name: 'Autofix: dynamic prop on bento-radio-group',
110
+ filename: 'test.vue',
111
+ options: [{ autofix: true }],
112
+ code: `<template><bento-radio-group :has-error="val" /></template>`,
113
+ output: `<template><bento-radio-group :error-message="val" /></template>`,
114
+ errors: [{ messageId: 'deprecation' }],
115
+ },
116
+ {
117
+ name: 'Autofix: v-bind longhand on bento-radio-group',
118
+ filename: 'test.vue',
119
+ options: [{ autofix: true }],
120
+ code: `<template><bento-radio-group v-bind:has-error="val" /></template>`,
121
+ output: `<template><bento-radio-group v-bind:error-message="val" /></template>`,
122
+ errors: [{ messageId: 'deprecation' }],
123
+ },
124
+ {
125
+ name: 'Autofix: does not fix when autofix is false',
126
+ filename: 'test.vue',
127
+ options: [{ autofix: false }],
128
+ code: `<template><bento-checkbox-group has-error="val" /></template>`,
129
+ errors: [{ messageId: 'deprecation' }],
130
+ },
131
+ ],
132
+ });
133
+ });
@@ -0,0 +1,44 @@
1
+ # deprecation-input-filter-dropdown-options
2
+
3
+ Deprecates usage of `dropdown`, `dropdownPosition`, and `variant` properties inside `BentoInputFilterOptions`.
4
+
5
+ These properties were used to configure the input filter as a dropdown variant. They should be replaced by using
6
+ `BentoFilterItemType.INPUT_DROPDOWN` instead of `BentoFilterItemType.INPUT`.
7
+
8
+ ## Examples
9
+
10
+ ### Invalid
11
+
12
+ ```vue
13
+ <script setup>
14
+ const config = [
15
+ {
16
+ field: 'name',
17
+ label: 'Name',
18
+ type: BentoFilterItemType.INPUT,
19
+ options: { dropdown: { items: [] }, dropdownPosition: 'end', variant: 'dropdown' },
20
+ },
21
+ ];
22
+ </script>
23
+ <template>
24
+ <bento-filter-bar :config="config" />
25
+ </template>
26
+ ```
27
+
28
+ ### Valid
29
+
30
+ ```vue
31
+ <script setup>
32
+ const config = [
33
+ {
34
+ field: 'name',
35
+ label: 'Name',
36
+ type: BentoFilterItemType.INPUT_DROPDOWN,
37
+ options: { dropdown: { items: [] }, dropdownPosition: 'end' },
38
+ },
39
+ ];
40
+ </script>
41
+ <template>
42
+ <bento-filter-bar :config="config" />
43
+ </template>
44
+ ```
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <div>
3
+ <bento-filter-bar :config="filterBarConfig" />
4
+ <bento-data-grid :filters="dataGridFilters" />
5
+ <bento-filter-bar
6
+ :config="[
7
+ {
8
+ field: 'inline',
9
+ label: 'Inline',
10
+ type: BentoFilterItemType.INPUT,
11
+ options: { dropdown: { items: [] } },
12
+ },
13
+ ]"
14
+ />
15
+ <bento-data-grid
16
+ :filters="[
17
+ {
18
+ field: 'inlineGrid',
19
+ label: 'Inline Grid',
20
+ type: BentoFilterItemType.INPUT,
21
+ options: { variant: 'dropdown' },
22
+ },
23
+ ]"
24
+ />
25
+ </div>
26
+ </template>
27
+
28
+ <script setup>
29
+ const filterBarConfig = [
30
+ {
31
+ field: 'name',
32
+ label: 'Name',
33
+ type: BentoFilterItemType.INPUT,
34
+ options: { dropdown: { items: [] }, dropdownPosition: 'end', variant: 'dropdown' },
35
+ },
36
+ ];
37
+
38
+ const dataGridFilters = [
39
+ {
40
+ field: 'status',
41
+ label: 'Status',
42
+ type: BentoFilterItemType.INPUT,
43
+ options: { dropdown: { items: [] } },
44
+ },
45
+ ];
46
+ </script>
@@ -0,0 +1,26 @@
1
+ // eslint.config.js
2
+ const { defineConfig } = require('eslint/config');
3
+ const vueParser = require('vue-eslint-parser');
4
+ const tsParser = require('@typescript-eslint/parser');
5
+ const adyenBento = require('@adyen/eslint-plugin-bento');
6
+
7
+ module.exports = defineConfig([
8
+ {
9
+ languageOptions: {
10
+ ecmaVersion: 'latest',
11
+ sourceType: 'module',
12
+ parser: vueParser,
13
+ parserOptions: {
14
+ parser: tsParser,
15
+ },
16
+ },
17
+ plugins: {
18
+ '@adyen/bento': adyenBento,
19
+ },
20
+ rules: {
21
+ // Register the specific rule we are testing
22
+ '@adyen/bento/deprecation-input-filter-dropdown-options': 'warn',
23
+ },
24
+ files: ['**/*.vue'],
25
+ },
26
+ ]);
@@ -0,0 +1,27 @@
1
+ import path from 'node:path';
2
+ import { execFileSyncEslintVueFiles } from '../../utils/exec-file-sync-eslint-vue-files';
3
+
4
+ describe('@adyen/bento/deprecation-input-filter-dropdown-options', () => {
5
+ it('should lint with warning', () => {
6
+ const eslintrc = path.resolve(__dirname, '__tests__', 'eslint.config.js');
7
+ const vueFile = path.resolve(__dirname, '__tests__', 'deprecation-input-filter-dropdown-options.vue');
8
+
9
+ const result = JSON.parse(execFileSyncEslintVueFiles(eslintrc, vueFile));
10
+
11
+ // 3 from filterBarConfig (dropdown, dropdownPosition, variant)
12
+ // + 1 from dataGridFilters (dropdown)
13
+ // + 1 from inline bento-filter-bar (dropdown)
14
+ // + 1 from inline bento-data-grid (variant)
15
+ expect(result[0].warningCount).toBe(6);
16
+
17
+ expect(result[0].messages).toEqual(
18
+ expect.arrayContaining([
19
+ expect.objectContaining({
20
+ ruleId: '@adyen/bento/deprecation-input-filter-dropdown-options',
21
+ severity: 1,
22
+ messageId: 'deprecation',
23
+ }),
24
+ ])
25
+ );
26
+ });
27
+ });
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @typedef {import('eslint').Rule.RuleContext} RuleContext
3
+ */
4
+ /**
5
+ * @typedef {import('eslint-plugin-vue/lib/utils').RuleModule} RuleModule
6
+ */
7
+
8
+ const VueUtils = require('eslint-plugin-vue/lib/utils');
9
+
10
+ const DEPRECATED_KEYS = ['dropdown', 'dropdownPosition', 'variant'];
11
+
12
+ /** @type {RuleModule} */
13
+ module.exports = {
14
+ meta: {
15
+ type: 'suggestion',
16
+ docs: {
17
+ description:
18
+ 'Deprecates usage of "dropdown", "dropdownPosition", and "variant" properties inside BentoInputFilterOptions. Use BentoFilterItemType.INPUT_DROPDOWN instead.',
19
+ category: 'Deprecations',
20
+ url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/deprecation-input-filter-dropdown-options/README.md',
21
+ recommended: true,
22
+ },
23
+ messages: {
24
+ deprecation:
25
+ 'The "{{ key }}" property in BentoInputFilterOptions is deprecated. Use "BentoFilterItemType.INPUT_DROPDOWN" instead of "BentoFilterItemType.INPUT".',
26
+ },
27
+ fixable: 'code',
28
+ schema: [
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ autofix: {
33
+ type: 'boolean',
34
+ default: false,
35
+ },
36
+ },
37
+ additionalProperties: false,
38
+ },
39
+ ],
40
+ },
41
+
42
+ /** @param {RuleContext} context */
43
+ create(context) {
44
+ const options = context.options[0] || {};
45
+ const autofix = options.autofix === true;
46
+
47
+ function getStaticPropertyName(prop) {
48
+ if (prop.type !== 'Property' || prop.computed) {
49
+ return null;
50
+ }
51
+ return prop.key.type === 'Identifier'
52
+ ? prop.key.name
53
+ : prop.key.type === 'Literal'
54
+ ? String(prop.key.value)
55
+ : null;
56
+ }
57
+
58
+ function reportDeprecatedKeys(node, typeValueNode) {
59
+ if (!node || node.type !== 'ObjectExpression') {
60
+ return;
61
+ }
62
+
63
+ for (const prop of node.properties) {
64
+ const keyName = getStaticPropertyName(prop);
65
+
66
+ if (keyName && DEPRECATED_KEYS.includes(keyName)) {
67
+ context.report({
68
+ node: prop.key,
69
+ messageId: 'deprecation',
70
+ data: { key: keyName },
71
+ ...(autofix && {
72
+ fix(fixer) {
73
+ if (typeValueNode.type === 'MemberExpression') {
74
+ return fixer.replaceText(typeValueNode.property, 'INPUT_DROPDOWN');
75
+ }
76
+ return fixer.replaceText(typeValueNode, "'BentoInputWithDropdownFilter'");
77
+ },
78
+ }),
79
+ });
80
+ }
81
+ }
82
+ }
83
+
84
+ function isInputFilterType(valueNode) {
85
+ if (
86
+ valueNode.type === 'MemberExpression' &&
87
+ valueNode.object.type === 'Identifier' &&
88
+ valueNode.object.name === 'BentoFilterItemType' &&
89
+ valueNode.property.type === 'Identifier' &&
90
+ valueNode.property.name === 'INPUT'
91
+ ) {
92
+ return true;
93
+ }
94
+
95
+ if (valueNode.type === 'Literal' && valueNode.value === 'BentoInputFilter') {
96
+ return true;
97
+ }
98
+
99
+ return false;
100
+ }
101
+
102
+ function checkFilterConfigObject(node) {
103
+ if (node.type !== 'ObjectExpression') {
104
+ return;
105
+ }
106
+
107
+ let typeValueNode = null;
108
+ let optionsNode = null;
109
+
110
+ for (const prop of node.properties) {
111
+ const keyName = getStaticPropertyName(prop);
112
+
113
+ if (keyName === 'type' && isInputFilterType(prop.value)) {
114
+ typeValueNode = prop.value;
115
+ }
116
+
117
+ if (keyName === 'options' && prop.value.type === 'ObjectExpression') {
118
+ optionsNode = prop.value;
119
+ }
120
+ }
121
+
122
+ if (typeValueNode && optionsNode) {
123
+ reportDeprecatedKeys(optionsNode, typeValueNode);
124
+ }
125
+ }
126
+
127
+ const visitor = {
128
+ ObjectExpression(node) {
129
+ checkFilterConfigObject(node);
130
+ },
131
+ };
132
+
133
+ return VueUtils.defineTemplateBodyVisitor(context, visitor, visitor);
134
+ },
135
+ };