@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.
- package/CHANGELOG.md +15 -0
- package/configs/vue-recommended.js +5 -0
- package/configs/vue-strict.js +5 -0
- package/index.js +5 -0
- package/package.json +1 -1
- package/rules/deprecation-bento-popover-modifiers-prop/README.md +23 -0
- package/rules/deprecation-bento-popover-modifiers-prop/__tests__/deprecation-bento-popover-modifiers-prop.vue +9 -0
- package/rules/deprecation-bento-popover-modifiers-prop/__tests__/eslint.config.js +26 -0
- package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.integration.test.ts +24 -0
- package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.js +78 -0
- package/rules/deprecation-bento-popover-modifiers-prop/deprecation-bento-popover-modifiers-prop.test.ts +109 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/README.md +25 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/__tests__/deprecation-bento-timeline-item-variant-prop.vue +9 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/__tests__/eslint.config.js +26 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.integration.test.ts +31 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.js +78 -0
- package/rules/deprecation-bento-timeline-item-variant-prop/deprecation-bento-timeline-item-variant-prop.test.ts +66 -0
- package/rules/deprecation-components-aria-label-prop/README.md +62 -0
- package/rules/deprecation-components-aria-label-prop/__tests__/deprecation-components-aria-label-prop.vue +25 -0
- package/rules/deprecation-components-aria-label-prop/__tests__/eslint.config.js +26 -0
- package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.integration.test.ts +36 -0
- package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.js +79 -0
- package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.test.ts +194 -0
- package/rules/deprecation-components-has-error-prop/README.md +34 -0
- package/rules/deprecation-components-has-error-prop/__tests__/deprecation-components-has-error-prop.vue +13 -0
- package/rules/deprecation-components-has-error-prop/__tests__/eslint.config.js +26 -0
- package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.integration.test.ts +29 -0
- package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.js +77 -0
- package/rules/deprecation-components-has-error-prop/deprecation-components-has-error-prop.test.ts +133 -0
- package/rules/deprecation-input-filter-dropdown-options/README.md +44 -0
- package/rules/deprecation-input-filter-dropdown-options/__tests__/deprecation-input-filter-dropdown-options.vue +46 -0
- package/rules/deprecation-input-filter-dropdown-options/__tests__/eslint.config.js +26 -0
- package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.integration.test.ts +27 -0
- package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.js +135 -0
- package/rules/deprecation-input-filter-dropdown-options/deprecation-input-filter-dropdown-options.test.ts +392 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<bento-dropdown ariaLabel="value" />
|
|
4
|
+
<bento-dropdown :ariaLabel="value" />
|
|
5
|
+
<bento-dropdown v-bind:ariaLabel="value" />
|
|
6
|
+
|
|
7
|
+
<bento-input-field ariaLabel="value" />
|
|
8
|
+
<bento-input-field :ariaLabel="value" />
|
|
9
|
+
<bento-input-field v-bind:ariaLabel="value" />
|
|
10
|
+
|
|
11
|
+
<bento-pagination ariaLabel="value" />
|
|
12
|
+
<bento-pagination :ariaLabel="value" />
|
|
13
|
+
<bento-pagination v-bind:ariaLabel="value" />
|
|
14
|
+
|
|
15
|
+
<bento-popover ariaLabel="value" />
|
|
16
|
+
<bento-popover :ariaLabel="value" />
|
|
17
|
+
<bento-popover v-bind:ariaLabel="value" />
|
|
18
|
+
|
|
19
|
+
<bento-segmented-control ariaLabel="value" />
|
|
20
|
+
<bento-segmented-control :ariaLabel="value" />
|
|
21
|
+
<bento-segmented-control v-bind:ariaLabel="value" />
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup></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-components-aria-label-prop': 'warn',
|
|
23
|
+
},
|
|
24
|
+
files: ['**/*.vue'],
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { execFileSyncEslintVueFiles } from '../../utils/exec-file-sync-eslint-vue-files';
|
|
3
|
+
|
|
4
|
+
describe('@adyen/bento/deprecation-components-aria-label-prop', () => {
|
|
5
|
+
it('should lint with warning', () => {
|
|
6
|
+
// Load .eslintrc
|
|
7
|
+
const eslintrc = path.resolve(__dirname, '__tests__', 'eslint.config.js');
|
|
8
|
+
// Load the test file generated alongside this one
|
|
9
|
+
const vueFile = path.resolve(__dirname, '__tests__', 'deprecation-components-aria-label-prop.vue');
|
|
10
|
+
|
|
11
|
+
// Execute the linter
|
|
12
|
+
const result = JSON.parse(execFileSyncEslintVueFiles(eslintrc, vueFile));
|
|
13
|
+
|
|
14
|
+
/* ------------------------------------------------ */
|
|
15
|
+
/* CASE 2: SINGLE REPLACEMENT */
|
|
16
|
+
/* ------------------------------------------------ */
|
|
17
|
+
|
|
18
|
+
// For props, we generate 3 examples (static, shorthand, longhand) FOR EACH component.
|
|
19
|
+
// Total = (Number of Components) * 3
|
|
20
|
+
const numberOfComponents = 5;
|
|
21
|
+
expect(result[0].warningCount).toBe(numberOfComponents * 3);
|
|
22
|
+
|
|
23
|
+
// Verify the message structure on the first error found.
|
|
24
|
+
// Since the rule is the same for all components, checking the first one confirms the message is correct.
|
|
25
|
+
expect(result[0].messages[0]).toMatchObject({
|
|
26
|
+
ruleId: '@adyen/bento/deprecation-components-aria-label-prop',
|
|
27
|
+
severity: 1,
|
|
28
|
+
|
|
29
|
+
messageId: 'deprecation',
|
|
30
|
+
message: `The "ariaLabel" prop is deprecated. Please use "aria-label" instead.`,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Without autofix option, no fix should be present
|
|
34
|
+
expect(result[0].messages[0].fix).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
});
|
package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
/** @type {RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'suggestion',
|
|
14
|
+
docs: {
|
|
15
|
+
description:
|
|
16
|
+
'Deprecates usage of ariaLabel prop in bento-dropdown, bento-input-field, bento-pagination, bento-popover, bento-segmented-control',
|
|
17
|
+
category: 'Deprecations',
|
|
18
|
+
url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/deprecation-components-aria-label-prop/README.md',
|
|
19
|
+
recommended: true,
|
|
20
|
+
},
|
|
21
|
+
messages: {
|
|
22
|
+
deprecation: `The "ariaLabel" prop is deprecated. Please use "aria-label" instead.`,
|
|
23
|
+
},
|
|
24
|
+
fixable: 'code',
|
|
25
|
+
schema: [
|
|
26
|
+
{
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
autofix: {
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
default: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/** @param {RuleContext} context */
|
|
40
|
+
create(context) {
|
|
41
|
+
const options = context.options[0] || {};
|
|
42
|
+
const autofix = options.autofix === true;
|
|
43
|
+
|
|
44
|
+
/* ------------------------------------------------ */
|
|
45
|
+
/* CASE 2: PROP DEPRECATION (Multiple Components) */
|
|
46
|
+
/* ------------------------------------------------ */
|
|
47
|
+
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
48
|
+
// 1. STATIC: ariaLabel="foo" (parser lowercases to "arialabel")
|
|
49
|
+
[`VElement:matches([name="bento-dropdown"], [name="BentoDropdown"], [name="bento-input-field"], [name="BentoInputField"], [name="bento-pagination"], [name="BentoPagination"], [name="bento-popover"], [name="BentoPopover"], [name="bento-segmented-control"], [name="BentoSegmentedControl"]) > VStartTag > VAttribute[directive=false][key.name="arialabel"]`](
|
|
50
|
+
node
|
|
51
|
+
) {
|
|
52
|
+
context.report({
|
|
53
|
+
node,
|
|
54
|
+
messageId: 'deprecation',
|
|
55
|
+
...(autofix && {
|
|
56
|
+
fix(fixer) {
|
|
57
|
+
return fixer.replaceText(node.key, 'aria-label');
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
// 2. DYNAMIC: :ariaLabel="foo" or v-bind:ariaLabel="foo" (parser lowercases to "arialabel")
|
|
64
|
+
[`VElement:matches([name="bento-dropdown"], [name="BentoDropdown"], [name="bento-input-field"], [name="BentoInputField"], [name="bento-pagination"], [name="BentoPagination"], [name="bento-popover"], [name="BentoPopover"], [name="bento-segmented-control"], [name="BentoSegmentedControl"]) > VStartTag > VAttribute[directive=true][key.name.name="bind"][key.argument.name="arialabel"]`](
|
|
65
|
+
node
|
|
66
|
+
) {
|
|
67
|
+
context.report({
|
|
68
|
+
node,
|
|
69
|
+
messageId: 'deprecation',
|
|
70
|
+
...(autofix && {
|
|
71
|
+
fix(fixer) {
|
|
72
|
+
return fixer.replaceText(node.key.argument, 'aria-label');
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
package/rules/deprecation-components-aria-label-prop/deprecation-components-aria-label-prop.test.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint';
|
|
2
|
+
import vueParser from 'vue-eslint-parser';
|
|
3
|
+
import tsParser from '@typescript-eslint/parser';
|
|
4
|
+
import deprecationComponentsAriaLabelProp from './deprecation-components-aria-label-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-aria-label-prop', () => {
|
|
18
|
+
ruleTester.run('deprecation-components-aria-label-prop', deprecationComponentsAriaLabelProp, {
|
|
19
|
+
valid: [
|
|
20
|
+
{
|
|
21
|
+
name: 'Valid usage for bento-dropdown',
|
|
22
|
+
filename: 'test.vue',
|
|
23
|
+
code: `
|
|
24
|
+
<template>
|
|
25
|
+
<bento-dropdown aria-label="val" />
|
|
26
|
+
</template>
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Valid usage for bento-input-field',
|
|
31
|
+
filename: 'test.vue',
|
|
32
|
+
code: `
|
|
33
|
+
<template>
|
|
34
|
+
<bento-input-field aria-label="val" />
|
|
35
|
+
</template>
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'Valid usage for bento-pagination',
|
|
40
|
+
filename: 'test.vue',
|
|
41
|
+
code: `
|
|
42
|
+
<template>
|
|
43
|
+
<bento-pagination aria-label="val" />
|
|
44
|
+
</template>
|
|
45
|
+
`,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'Valid usage for bento-popover',
|
|
49
|
+
filename: 'test.vue',
|
|
50
|
+
code: `
|
|
51
|
+
<template>
|
|
52
|
+
<bento-popover aria-label="val" />
|
|
53
|
+
</template>
|
|
54
|
+
`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'Valid usage for bento-segmented-control',
|
|
58
|
+
filename: 'test.vue',
|
|
59
|
+
code: `
|
|
60
|
+
<template>
|
|
61
|
+
<bento-segmented-control aria-label="val" />
|
|
62
|
+
</template>
|
|
63
|
+
`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
invalid: [
|
|
67
|
+
// bento-dropdown: Static
|
|
68
|
+
{
|
|
69
|
+
name: 'Invalid: Static prop on bento-dropdown',
|
|
70
|
+
filename: 'test.vue',
|
|
71
|
+
code: `<template><bento-dropdown ariaLabel="val" /></template>`,
|
|
72
|
+
errors: [{ messageId: 'deprecation' }],
|
|
73
|
+
},
|
|
74
|
+
// bento-dropdown: Shorthand
|
|
75
|
+
{
|
|
76
|
+
name: 'Invalid: Dynamic prop on bento-dropdown',
|
|
77
|
+
filename: 'test.vue',
|
|
78
|
+
code: `<template><bento-dropdown :ariaLabel="val" /></template>`,
|
|
79
|
+
errors: [{ messageId: 'deprecation' }],
|
|
80
|
+
},
|
|
81
|
+
// bento-input-field: Static
|
|
82
|
+
{
|
|
83
|
+
name: 'Invalid: Static prop on bento-input-field',
|
|
84
|
+
filename: 'test.vue',
|
|
85
|
+
code: `<template><bento-input-field ariaLabel="val" /></template>`,
|
|
86
|
+
errors: [{ messageId: 'deprecation' }],
|
|
87
|
+
},
|
|
88
|
+
// bento-input-field: Shorthand
|
|
89
|
+
{
|
|
90
|
+
name: 'Invalid: Dynamic prop on bento-input-field',
|
|
91
|
+
filename: 'test.vue',
|
|
92
|
+
code: `<template><bento-input-field :ariaLabel="val" /></template>`,
|
|
93
|
+
errors: [{ messageId: 'deprecation' }],
|
|
94
|
+
},
|
|
95
|
+
// bento-pagination: Static
|
|
96
|
+
{
|
|
97
|
+
name: 'Invalid: Static prop on bento-pagination',
|
|
98
|
+
filename: 'test.vue',
|
|
99
|
+
code: `<template><bento-pagination ariaLabel="val" /></template>`,
|
|
100
|
+
errors: [{ messageId: 'deprecation' }],
|
|
101
|
+
},
|
|
102
|
+
// bento-pagination: Shorthand
|
|
103
|
+
{
|
|
104
|
+
name: 'Invalid: Dynamic prop on bento-pagination',
|
|
105
|
+
filename: 'test.vue',
|
|
106
|
+
code: `<template><bento-pagination :ariaLabel="val" /></template>`,
|
|
107
|
+
errors: [{ messageId: 'deprecation' }],
|
|
108
|
+
},
|
|
109
|
+
// bento-popover: Static
|
|
110
|
+
{
|
|
111
|
+
name: 'Invalid: Static prop on bento-popover',
|
|
112
|
+
filename: 'test.vue',
|
|
113
|
+
code: `<template><bento-popover ariaLabel="val" /></template>`,
|
|
114
|
+
errors: [{ messageId: 'deprecation' }],
|
|
115
|
+
},
|
|
116
|
+
// bento-popover: Shorthand
|
|
117
|
+
{
|
|
118
|
+
name: 'Invalid: Dynamic prop on bento-popover',
|
|
119
|
+
filename: 'test.vue',
|
|
120
|
+
code: `<template><bento-popover :ariaLabel="val" /></template>`,
|
|
121
|
+
errors: [{ messageId: 'deprecation' }],
|
|
122
|
+
},
|
|
123
|
+
// bento-segmented-control: Static
|
|
124
|
+
{
|
|
125
|
+
name: 'Invalid: Static prop on bento-segmented-control',
|
|
126
|
+
filename: 'test.vue',
|
|
127
|
+
code: `<template><bento-segmented-control ariaLabel="val" /></template>`,
|
|
128
|
+
errors: [{ messageId: 'deprecation' }],
|
|
129
|
+
},
|
|
130
|
+
// bento-segmented-control: Shorthand
|
|
131
|
+
{
|
|
132
|
+
name: 'Invalid: Dynamic prop on bento-segmented-control',
|
|
133
|
+
filename: 'test.vue',
|
|
134
|
+
code: `<template><bento-segmented-control :ariaLabel="val" /></template>`,
|
|
135
|
+
errors: [{ messageId: 'deprecation' }],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/* ------------------------------------------------ */
|
|
141
|
+
/* AUTOFIX TESTS */
|
|
142
|
+
/* ------------------------------------------------ */
|
|
143
|
+
ruleTester.run('deprecation-components-aria-label-prop (autofix enabled)', deprecationComponentsAriaLabelProp, {
|
|
144
|
+
valid: [
|
|
145
|
+
{
|
|
146
|
+
name: 'Valid: aria-label (kebab-case) on bento-dropdown (autofix enabled)',
|
|
147
|
+
filename: 'test.vue',
|
|
148
|
+
options: [{ autofix: true }],
|
|
149
|
+
code: `<template><bento-dropdown aria-label="val" /></template>`,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
invalid: [
|
|
153
|
+
{
|
|
154
|
+
name: 'Autofix: static prop on bento-dropdown',
|
|
155
|
+
filename: 'test.vue',
|
|
156
|
+
options: [{ autofix: true }],
|
|
157
|
+
code: `<template><bento-dropdown ariaLabel="val" /></template>`,
|
|
158
|
+
output: `<template><bento-dropdown aria-label="val" /></template>`,
|
|
159
|
+
errors: [{ messageId: 'deprecation' }],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'Autofix: dynamic prop on bento-dropdown',
|
|
163
|
+
filename: 'test.vue',
|
|
164
|
+
options: [{ autofix: true }],
|
|
165
|
+
code: `<template><bento-dropdown :ariaLabel="val" /></template>`,
|
|
166
|
+
output: `<template><bento-dropdown :aria-label="val" /></template>`,
|
|
167
|
+
errors: [{ messageId: 'deprecation' }],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'Autofix: static prop on bento-segmented-control',
|
|
171
|
+
filename: 'test.vue',
|
|
172
|
+
options: [{ autofix: true }],
|
|
173
|
+
code: `<template><bento-segmented-control ariaLabel="val" /></template>`,
|
|
174
|
+
output: `<template><bento-segmented-control aria-label="val" /></template>`,
|
|
175
|
+
errors: [{ messageId: 'deprecation' }],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'Autofix: v-bind longhand on bento-popover',
|
|
179
|
+
filename: 'test.vue',
|
|
180
|
+
options: [{ autofix: true }],
|
|
181
|
+
code: `<template><bento-popover v-bind:ariaLabel="val" /></template>`,
|
|
182
|
+
output: `<template><bento-popover v-bind:aria-label="val" /></template>`,
|
|
183
|
+
errors: [{ messageId: 'deprecation' }],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Autofix: does not fix when autofix is false',
|
|
187
|
+
filename: 'test.vue',
|
|
188
|
+
options: [{ autofix: false }],
|
|
189
|
+
code: `<template><bento-dropdown ariaLabel="val" /></template>`,
|
|
190
|
+
errors: [{ messageId: 'deprecation' }],
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# deprecation-components-has-error-prop
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
The `hasError` prop in the following components is deprecated:
|
|
6
|
+
|
|
7
|
+
- `bento-checkbox-group`
|
|
8
|
+
- `bento-radio-group`
|
|
9
|
+
|
|
10
|
+
Please use `errorMessage` instead.
|
|
11
|
+
|
|
12
|
+
## Rule Details
|
|
13
|
+
|
|
14
|
+
This rule reports usages of the deprecated item.
|
|
15
|
+
|
|
16
|
+
### ❌ Incorrect
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<bento-checkbox-group has-error="value" /> <bento-checkbox-group :has-error="value" />
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<bento-radio-group has-error="value" /> <bento-radio-group :has-error="value" />
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### ✅ Correct
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<bento-checkbox-group errorMessage="value" />
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<bento-radio-group errorMessage="value" />
|
|
34
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<bento-checkbox-group has-error="value" />
|
|
4
|
+
<bento-checkbox-group :has-error="value" />
|
|
5
|
+
<bento-checkbox-group :has-error="value" />
|
|
6
|
+
|
|
7
|
+
<bento-radio-group has-error="value" />
|
|
8
|
+
<bento-radio-group :has-error="value" />
|
|
9
|
+
<bento-radio-group :has-error="value" />
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup></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-components-has-error-prop': 'warn',
|
|
23
|
+
},
|
|
24
|
+
files: ['**/*.vue'],
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { execFileSyncEslintVueFiles } from '../../utils/exec-file-sync-eslint-vue-files';
|
|
3
|
+
|
|
4
|
+
describe('@adyen/bento/deprecation-components-has-error-prop', () => {
|
|
5
|
+
it('should lint with warning', () => {
|
|
6
|
+
// Load .eslintrc
|
|
7
|
+
const eslintrc = path.resolve(__dirname, '__tests__', 'eslint.config.js');
|
|
8
|
+
// Load the test file generated alongside this one
|
|
9
|
+
const vueFile = path.resolve(__dirname, '__tests__', 'deprecation-components-has-error-prop.vue');
|
|
10
|
+
|
|
11
|
+
// Execute the linter
|
|
12
|
+
const result = JSON.parse(execFileSyncEslintVueFiles(eslintrc, vueFile));
|
|
13
|
+
|
|
14
|
+
// 3 examples (static, shorthand, longhand) FOR EACH component.
|
|
15
|
+
// Total = 2 components * 3 = 6
|
|
16
|
+
expect(result[0].warningCount).toBe(6);
|
|
17
|
+
|
|
18
|
+
expect(result[0].messages[0]).toMatchObject({
|
|
19
|
+
ruleId: '@adyen/bento/deprecation-components-has-error-prop',
|
|
20
|
+
severity: 1,
|
|
21
|
+
|
|
22
|
+
messageId: 'deprecation',
|
|
23
|
+
message: `The "has-error" prop is deprecated. Please use "error-message" instead.`,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Without autofix option, no fix should be present
|
|
27
|
+
expect(result[0].messages[0].fix).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
/** @type {RuleModule} */
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'suggestion',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Deprecates usage of hasError prop in bento-checkbox-group, bento-radio-group',
|
|
16
|
+
category: 'Deprecations',
|
|
17
|
+
url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/deprecation-components-has-error-prop/README.md',
|
|
18
|
+
recommended: true,
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
deprecation: `The "has-error" prop is deprecated. Please use "error-message" instead.`,
|
|
22
|
+
},
|
|
23
|
+
fixable: 'code',
|
|
24
|
+
schema: [
|
|
25
|
+
{
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
autofix: {
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
default: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/** @param {RuleContext} context */
|
|
39
|
+
create(context) {
|
|
40
|
+
const options = context.options[0] || {};
|
|
41
|
+
const autofix = options.autofix === true;
|
|
42
|
+
/* ------------------------------------------------ */
|
|
43
|
+
/* CASE 2: PROP DEPRECATION (Multiple Components) */
|
|
44
|
+
/* ------------------------------------------------ */
|
|
45
|
+
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
46
|
+
// 1. STATIC: value="foo"
|
|
47
|
+
[`VElement:matches([name="bento-checkbox-group"], [name="BentoCheckboxGroup"], [name="bento-radio-group"], [name="BentoRadioGroup"]) > VStartTag > VAttribute[directive=false][key.name="has-error"]`](
|
|
48
|
+
node
|
|
49
|
+
) {
|
|
50
|
+
context.report({
|
|
51
|
+
node,
|
|
52
|
+
messageId: 'deprecation',
|
|
53
|
+
...(autofix && {
|
|
54
|
+
fix(fixer) {
|
|
55
|
+
return fixer.replaceText(node.key, 'error-message');
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// 2. DYNAMIC: :value="foo" or v-bind:value="foo"
|
|
62
|
+
[`VElement:matches([name="bento-checkbox-group"], [name="BentoCheckboxGroup"], [name="bento-radio-group"], [name="BentoRadioGroup"]) > VStartTag > VAttribute[directive=true][key.name.name="bind"][key.argument.name="has-error"]`](
|
|
63
|
+
node
|
|
64
|
+
) {
|
|
65
|
+
context.report({
|
|
66
|
+
node,
|
|
67
|
+
messageId: 'deprecation',
|
|
68
|
+
...(autofix && {
|
|
69
|
+
fix(fixer) {
|
|
70
|
+
return fixer.replaceText(node.key.argument, 'error-message');
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|