@adyen/eslint-plugin-bento 1.0.3 → 1.1.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 +20 -0
- package/index.js +6 -0
- package/package.json +2 -1
- package/rules/deprecation-currency-default-slot/README.md +50 -0
- package/rules/deprecation-currency-default-slot/__tests__/.eslintrc.js +8 -0
- package/rules/deprecation-currency-default-slot/__tests__/deprecation-currency-default-slot.vue +7 -0
- package/rules/deprecation-currency-default-slot/deprecation-currency-default-slot.integration.test.ts +36 -0
- package/rules/deprecation-currency-default-slot/deprecation-currency-default-slot.js +34 -0
- package/rules/deprecation-currency-default-slot/deprecation-currency-default-slot.test.ts +94 -0
- package/rules/deprecation-tag-default-slot/README.md +46 -0
- package/rules/deprecation-tag-default-slot/__tests__/.eslintrc.js +8 -0
- package/rules/deprecation-tag-default-slot/__tests__/deprecation-tag-default-slot.vue +5 -0
- package/rules/deprecation-tag-default-slot/deprecation-tag-default-slot.integration.test.ts +36 -0
- package/rules/deprecation-tag-default-slot/deprecation-tag-default-slot.js +33 -0
- package/rules/deprecation-tag-default-slot/deprecation-tag-default-slot.test.ts +105 -0
- package/utils/component-slot-migration.js +61 -0
package/README.md
CHANGED
|
@@ -54,3 +54,23 @@ Disallow the use of ADL space utility classes in favor of Bento _spacer_ utility
|
|
|
54
54
|
The recommended configuration contains pre-configured rules and their severity
|
|
55
55
|
|
|
56
56
|
- `@adyen/bento/vue-old-spacer-tokens`: `warn`
|
|
57
|
+
|
|
58
|
+
### `@adyen/bento/deprecation-currency-default-slot`
|
|
59
|
+
|
|
60
|
+
Disallow the use of the `default` slot in `bento-currency` instances
|
|
61
|
+
|
|
62
|
+
### Recommended
|
|
63
|
+
|
|
64
|
+
The recommended configuration contains pre-configured rules and their severity
|
|
65
|
+
|
|
66
|
+
- `@adyen/bento/deprecation-currency-default-slot`: `warn`
|
|
67
|
+
|
|
68
|
+
### `@adyen/bento/deprecation-tag-default-slot`
|
|
69
|
+
|
|
70
|
+
Disallow the use of the `default` slot in `bento-tag` instances
|
|
71
|
+
|
|
72
|
+
### Recommended
|
|
73
|
+
|
|
74
|
+
The recommended configuration contains pre-configured rules and their severity
|
|
75
|
+
|
|
76
|
+
- `@adyen/bento/deprecation-tag-default-slot`: `warn`
|
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const deprecationCurrencyDefaultSlot = require('./rules/deprecation-currency-default-slot/deprecation-currency-default-slot');
|
|
3
|
+
const deprecationTagDefaultSlot = require('./rules/deprecation-tag-default-slot/deprecation-tag-default-slot');
|
|
2
4
|
const spacerTokens = require('./rules/vue-old-spacer-tokens/vue-old-spacer-tokens');
|
|
3
5
|
|
|
4
6
|
// The package name and version must be in sync with 'package.json'
|
|
@@ -14,11 +16,15 @@ module.exports = {
|
|
|
14
16
|
parser: 'vue-eslint-parser',
|
|
15
17
|
plugins: ['@adyen/bento'],
|
|
16
18
|
rules: {
|
|
19
|
+
'@adyen/bento/deprecation-currency-default-slot': 'warn',
|
|
20
|
+
'@adyen/bento/deprecation-tag-default-slot': 'warn',
|
|
17
21
|
'@adyen/bento/vue-old-spacer-tokens': 'warn',
|
|
18
22
|
},
|
|
19
23
|
},
|
|
20
24
|
},
|
|
21
25
|
rules: {
|
|
26
|
+
'deprecation-currency-default-slot': deprecationCurrencyDefaultSlot,
|
|
27
|
+
'deprecation-tag-default-slot': deprecationTagDefaultSlot,
|
|
22
28
|
'vue-old-spacer-tokens': spacerTokens,
|
|
23
29
|
},
|
|
24
30
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @adyen/bento/deprecation-currency-default-slot
|
|
2
|
+
|
|
3
|
+
> Disallow the use of the `default` slot in `bento-currency` instances
|
|
4
|
+
|
|
5
|
+
- This rule is included in the `plugin:@adyen/bento/recommended` configuration.
|
|
6
|
+
- 🔧 The `--fix` option can automatically fix the problems reported by this rule.
|
|
7
|
+
|
|
8
|
+
This rule prevents using the deprecated `default` slot within the `Currency` component.
|
|
9
|
+
|
|
10
|
+
## ✗ BAD
|
|
11
|
+
|
|
12
|
+
<!-- prettier-ignore -->
|
|
13
|
+
```html
|
|
14
|
+
<template>
|
|
15
|
+
<bento-currency currency="USD">
|
|
16
|
+
12345
|
|
17
|
+
</bento-currency>
|
|
18
|
+
|
|
19
|
+
<bento-currency currency="USD">
|
|
20
|
+
12345.67
|
|
21
|
+
</bento-currency>
|
|
22
|
+
|
|
23
|
+
<bento-currency>
|
|
24
|
+
{{ thisIsMyVariableWithCurrencyValue }}
|
|
25
|
+
</bento-currency>
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## ✓ Good
|
|
30
|
+
|
|
31
|
+
<!-- prettier-ignore -->
|
|
32
|
+
```html
|
|
33
|
+
<template>
|
|
34
|
+
<bento-currency
|
|
35
|
+
:value="12345"
|
|
36
|
+
currency="USD"
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
<bento-currency
|
|
40
|
+
:value="12345.67"
|
|
41
|
+
currency="USD"
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
<bento-currency
|
|
45
|
+
:value="thisIsMyVariableWithCurrencyValue"
|
|
46
|
+
:currency="BentoCurrencyISOCode.USD"
|
|
47
|
+
major-units
|
|
48
|
+
/>
|
|
49
|
+
</template>
|
|
50
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
// ESLint command
|
|
5
|
+
const ESLINT = 'pnpm eslint';
|
|
6
|
+
|
|
7
|
+
describe('@adyen/bento/deprecation-currency-default-slot', () => {
|
|
8
|
+
it('should lint with warning', () => {
|
|
9
|
+
// Load .eslintrc
|
|
10
|
+
const eslintrc = path.resolve(__dirname, '__tests__', '.eslintrc.js');
|
|
11
|
+
// Load the test file
|
|
12
|
+
const vueFile = path.resolve(__dirname, '__tests__', 'deprecation-currency-default-slot.vue');
|
|
13
|
+
|
|
14
|
+
// Execute the linter
|
|
15
|
+
const result = JSON.parse(
|
|
16
|
+
execSync(`${ESLINT} --format=json -c ${eslintrc} ${vueFile}`, {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Expects a warning with a suggestion/fix and an error message
|
|
22
|
+
expect(result[0].warningCount).toBe(1);
|
|
23
|
+
expect(result[0].messages[0]).toStrictEqual({
|
|
24
|
+
ruleId: '@adyen/bento/deprecation-currency-default-slot',
|
|
25
|
+
severity: 1,
|
|
26
|
+
message: '"default" slot is deprecated in favor of the "value" property',
|
|
27
|
+
messageId: 'migrateDefaultSlot',
|
|
28
|
+
line: 2,
|
|
29
|
+
column: 5,
|
|
30
|
+
nodeType: 'VElement',
|
|
31
|
+
endLine: 4,
|
|
32
|
+
endColumn: 22,
|
|
33
|
+
fix: { range: [30, 101], text: ' :value="`${thisIsMyVariableWithCurrencyValue}`" />' },
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
|
+
const { componentSlotMigration } = require('../../utils/component-slot-migration');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'Replaces Currency usage of "default" slot in favor of the "value" property',
|
|
9
|
+
category: 'Best Practices',
|
|
10
|
+
url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/deprecate-currency-default-slot/README.md',
|
|
11
|
+
recommended: true,
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
migrateDefaultSlot: '"default" slot is deprecated in favor of the "value" property',
|
|
15
|
+
},
|
|
16
|
+
fixable: 'code',
|
|
17
|
+
schema: [], // No options are needed for this rule
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const sourceCode = context.getSourceCode();
|
|
21
|
+
const template =
|
|
22
|
+
sourceCode.parserServices.getTemplateBodyTokenStore &&
|
|
23
|
+
sourceCode.parserServices.getTemplateBodyTokenStore();
|
|
24
|
+
|
|
25
|
+
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
26
|
+
'VElement[name=bento-currency]': componentSlotMigration({
|
|
27
|
+
propertyName: 'value',
|
|
28
|
+
context,
|
|
29
|
+
template,
|
|
30
|
+
alwaysExpression: true,
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint';
|
|
2
|
+
import deprecationCurrencyDefaultSlot from './deprecation-currency-default-slot';
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parser: require.resolve('vue-eslint-parser'),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('@adyen/bento/deprecation-currency-default-slot should suggest the usage of "label" property instead of "default" slot', () => {
|
|
9
|
+
ruleTester.run('deprecation-currency-default-slot', deprecationCurrencyDefaultSlot, {
|
|
10
|
+
valid: [
|
|
11
|
+
{
|
|
12
|
+
name: 'BentoCurrency with "value" property',
|
|
13
|
+
filename: 'test.vue',
|
|
14
|
+
code: `
|
|
15
|
+
<template>
|
|
16
|
+
<bento-currency :value="12345" currency="USD" />
|
|
17
|
+
</template>
|
|
18
|
+
`,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'BentoCurrency with closing tag but no children',
|
|
22
|
+
filename: 'test.vue',
|
|
23
|
+
code: `
|
|
24
|
+
<template>
|
|
25
|
+
<bento-currency :value="12345" :currency="BentoCurrencyISOCode.USD" major-units />
|
|
26
|
+
</template>
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'BentoCurrency with closing tag but no children',
|
|
31
|
+
filename: 'test.vue',
|
|
32
|
+
code: `
|
|
33
|
+
<template>
|
|
34
|
+
<bento-currency
|
|
35
|
+
:value="thisIsMyVariableWithCurrencyValue"
|
|
36
|
+
:currency="BentoCurrencyISOCode.USD"
|
|
37
|
+
major-units
|
|
38
|
+
/>
|
|
39
|
+
</template>
|
|
40
|
+
`,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
invalid: [
|
|
44
|
+
{
|
|
45
|
+
name: 'BentoCurrency with VText child',
|
|
46
|
+
code: `
|
|
47
|
+
<template>
|
|
48
|
+
<bento-currency currency="USD">
|
|
49
|
+
12345
|
|
50
|
+
</bento-currency>
|
|
51
|
+
</template>
|
|
52
|
+
`,
|
|
53
|
+
output: `
|
|
54
|
+
<template>
|
|
55
|
+
<bento-currency currency="USD" :value="12345" />
|
|
56
|
+
</template>
|
|
57
|
+
`,
|
|
58
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "value" property' }],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'BentoCurrency with VText child and no attributes',
|
|
62
|
+
code: `
|
|
63
|
+
<template>
|
|
64
|
+
<bento-currency>
|
|
65
|
+
12345.23
|
|
66
|
+
</bento-currency>
|
|
67
|
+
</template>
|
|
68
|
+
`,
|
|
69
|
+
output: `
|
|
70
|
+
<template>
|
|
71
|
+
<bento-currency :value="12345.23" />
|
|
72
|
+
</template>
|
|
73
|
+
`,
|
|
74
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "value" property' }],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'BentoCurrency with property as child',
|
|
78
|
+
code: `
|
|
79
|
+
<template>
|
|
80
|
+
<bento-currency>
|
|
81
|
+
{{ thisIsMyVariableWithCurrencyValue }}
|
|
82
|
+
</bento-currency>
|
|
83
|
+
</template>
|
|
84
|
+
`,
|
|
85
|
+
output: `
|
|
86
|
+
<template>
|
|
87
|
+
<bento-currency :value="\`\${thisIsMyVariableWithCurrencyValue}\`" />
|
|
88
|
+
</template>
|
|
89
|
+
`,
|
|
90
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "value" property' }],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @adyen/bento/deprecation-tag-default-slot
|
|
2
|
+
|
|
3
|
+
> Disallow the use of the slot in `bento-tag` instances
|
|
4
|
+
|
|
5
|
+
- This rule is included in the `plugin:@adyen/bento/recommended` configuration.
|
|
6
|
+
- 🔧 The `--fix` option can automatically fix the problems reported by this rule.
|
|
7
|
+
|
|
8
|
+
This rule prevents using the deprecated `default` slot within the `Tag` component.
|
|
9
|
+
|
|
10
|
+
## ✗ BAD
|
|
11
|
+
|
|
12
|
+
<!-- prettier-ignore -->
|
|
13
|
+
```html
|
|
14
|
+
<template>
|
|
15
|
+
<bento-tag variant="blue">
|
|
16
|
+
Label text
|
|
17
|
+
</bento-tag>
|
|
18
|
+
|
|
19
|
+
<bento-tag>
|
|
20
|
+
Label text
|
|
21
|
+
</bento-tag>
|
|
22
|
+
|
|
23
|
+
<bento-tag>
|
|
24
|
+
{{ thisIsMyVariableWithText }}
|
|
25
|
+
</bento-tag>
|
|
26
|
+
|
|
27
|
+
<bento-tag>
|
|
28
|
+
Value: {{ thisIsAValue }}
|
|
29
|
+
</bento-tag>
|
|
30
|
+
</template>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## ✓ Good
|
|
34
|
+
|
|
35
|
+
<!-- prettier-ignore -->
|
|
36
|
+
```html
|
|
37
|
+
<template>
|
|
38
|
+
<bento-tag label="Label text" variant="blue" />
|
|
39
|
+
|
|
40
|
+
<bento-tag label="Label text" variant="blue" />
|
|
41
|
+
|
|
42
|
+
<bento-tag :label="thisIsMyVariableWithText" variant="blue" />
|
|
43
|
+
|
|
44
|
+
<bento-tag :label="Value: ${thisIsAValue}" />
|
|
45
|
+
</template>
|
|
46
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
// ESLint command
|
|
5
|
+
const ESLINT = 'pnpm eslint';
|
|
6
|
+
|
|
7
|
+
describe('@adyen/bento/deprecation-tag-default-slot', () => {
|
|
8
|
+
it('should lint with warning', () => {
|
|
9
|
+
// Load .eslintrc
|
|
10
|
+
const eslintrc = path.resolve(__dirname, '__tests__', '.eslintrc.js');
|
|
11
|
+
// Load the test file
|
|
12
|
+
const vueFile = path.resolve(__dirname, '__tests__', 'deprecation-tag-default-slot.vue');
|
|
13
|
+
|
|
14
|
+
// Execute the linter
|
|
15
|
+
const result = JSON.parse(
|
|
16
|
+
execSync(`${ESLINT} --format=json -c ${eslintrc} ${vueFile}`, {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Expects a warning with a suggestion/fix and an error message
|
|
22
|
+
expect(result[0].warningCount).toBe(1);
|
|
23
|
+
expect(result[0].messages[0]).toStrictEqual({
|
|
24
|
+
ruleId: '@adyen/bento/deprecation-tag-default-slot',
|
|
25
|
+
severity: 1,
|
|
26
|
+
message: '"default" slot is deprecated in favor of the "label" property',
|
|
27
|
+
messageId: 'migrateDefaultSlot',
|
|
28
|
+
line: 2,
|
|
29
|
+
column: 5,
|
|
30
|
+
nodeType: 'VElement',
|
|
31
|
+
endLine: 2,
|
|
32
|
+
endColumn: 53,
|
|
33
|
+
fix: { range: [25, 63], text: ' :label="`Value: ${thisIsAValue}`" />' },
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
|
+
const { componentSlotMigration } = require('../../utils/component-slot-migration');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'Replaces Tag usage of "default" slot in favor of the "label" property',
|
|
9
|
+
category: 'Best Practices',
|
|
10
|
+
url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/deprecate-tag-default-slot/README.md',
|
|
11
|
+
recommended: true,
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
migrateDefaultSlot: '"default" slot is deprecated in favor of the "label" property',
|
|
15
|
+
},
|
|
16
|
+
fixable: 'code',
|
|
17
|
+
schema: [], // No options are needed for this rule
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const sourceCode = context.getSourceCode();
|
|
21
|
+
const template =
|
|
22
|
+
sourceCode.parserServices.getTemplateBodyTokenStore &&
|
|
23
|
+
sourceCode.parserServices.getTemplateBodyTokenStore();
|
|
24
|
+
|
|
25
|
+
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
26
|
+
'VElement[name=bento-tag]': componentSlotMigration({
|
|
27
|
+
propertyName: 'label',
|
|
28
|
+
context,
|
|
29
|
+
template,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint';
|
|
2
|
+
import deprecationTagDefaultSlot from './deprecation-tag-default-slot';
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parser: require.resolve('vue-eslint-parser'),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('@adyen/bento/deprecation-tag-default-slot should suggest the usage of "label" property instead of "default" slot', () => {
|
|
9
|
+
ruleTester.run('deprecation-tag-default-slot', deprecationTagDefaultSlot, {
|
|
10
|
+
valid: [
|
|
11
|
+
{
|
|
12
|
+
name: 'BentoTag with "label" property',
|
|
13
|
+
filename: 'test.vue',
|
|
14
|
+
code: `
|
|
15
|
+
<template>
|
|
16
|
+
<bento-tag label="Label text" variant="blue" />
|
|
17
|
+
</template>
|
|
18
|
+
`,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'BentoTag with closing tag but no children',
|
|
22
|
+
filename: 'test.vue',
|
|
23
|
+
code: `
|
|
24
|
+
<template>
|
|
25
|
+
<bento-tag label="Label text" variant="blue" />
|
|
26
|
+
`,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'BentoTag with expression as value for "label" property',
|
|
30
|
+
filename: 'test.vue',
|
|
31
|
+
code: `
|
|
32
|
+
<template>
|
|
33
|
+
<bento-tag :label="thisIsMyVariableWithText" variant="blue" />
|
|
34
|
+
`,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
invalid: [
|
|
38
|
+
{
|
|
39
|
+
name: 'BentoTag with VText child',
|
|
40
|
+
code: `
|
|
41
|
+
<template>
|
|
42
|
+
<bento-tag variant="blue">
|
|
43
|
+
Label text
|
|
44
|
+
</bento-tag>
|
|
45
|
+
</template>
|
|
46
|
+
`,
|
|
47
|
+
output: `
|
|
48
|
+
<template>
|
|
49
|
+
<bento-tag variant="blue" label="Label text" />
|
|
50
|
+
</template>
|
|
51
|
+
`,
|
|
52
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "label" property' }],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'BentoTag with VText child and no attributes',
|
|
56
|
+
code: `
|
|
57
|
+
<template>
|
|
58
|
+
<bento-tag>
|
|
59
|
+
Label text
|
|
60
|
+
</bento-tag>
|
|
61
|
+
</template>
|
|
62
|
+
`,
|
|
63
|
+
output: `
|
|
64
|
+
<template>
|
|
65
|
+
<bento-tag label="Label text" />
|
|
66
|
+
</template>
|
|
67
|
+
`,
|
|
68
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "label" property' }],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'BentoTag with property as child',
|
|
72
|
+
code: `
|
|
73
|
+
<template>
|
|
74
|
+
<bento-tag>
|
|
75
|
+
{{ thisIsMyVariableWithText }}
|
|
76
|
+
</bento-tag>
|
|
77
|
+
</template>
|
|
78
|
+
`,
|
|
79
|
+
output: `
|
|
80
|
+
<template>
|
|
81
|
+
<bento-tag :label="\`\${thisIsMyVariableWithText}\`" />
|
|
82
|
+
</template>
|
|
83
|
+
`,
|
|
84
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "label" property' }],
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
name: 'BentoTag with text and property as child',
|
|
89
|
+
code: `
|
|
90
|
+
<template>
|
|
91
|
+
<bento-tag>
|
|
92
|
+
Value: {{ thisIsAValue }}
|
|
93
|
+
</bento-tag>
|
|
94
|
+
</template>
|
|
95
|
+
`,
|
|
96
|
+
output: `
|
|
97
|
+
<template>
|
|
98
|
+
<bento-tag :label="\`Value: \${thisIsAValue}\`" />
|
|
99
|
+
</template>
|
|
100
|
+
`,
|
|
101
|
+
errors: [{ message: '"default" slot is deprecated in favor of the "label" property' }],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a report with a fix to those VElements containing a deprecated default slot.
|
|
3
|
+
*
|
|
4
|
+
* It moves the content of the "default" slot into a prop with the "propertyName" value.
|
|
5
|
+
*
|
|
6
|
+
* @param props Contains the name of the property by which it will be replace and the context
|
|
7
|
+
*/
|
|
8
|
+
export function componentSlotMigration({ propertyName, context, template, alwaysExpression = false }) {
|
|
9
|
+
return node => {
|
|
10
|
+
if (!node.children.length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Turned true if one of the children is an expression
|
|
15
|
+
let hasExpression = false;
|
|
16
|
+
|
|
17
|
+
const transformNodeToText = ({ value, type, expression }) => {
|
|
18
|
+
if (type === 'VText') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (type === 'VExpressionContainer') {
|
|
23
|
+
hasExpression = true;
|
|
24
|
+
|
|
25
|
+
return `\${${expression.name}}`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Opening tag closing brace ">"
|
|
30
|
+
const closingBrace = template.getLastToken(node.startTag);
|
|
31
|
+
// Get all content and concat
|
|
32
|
+
const slotContent = node.children
|
|
33
|
+
// .map(({ value }) => value)
|
|
34
|
+
.map(transformNodeToText)
|
|
35
|
+
.join('')
|
|
36
|
+
.trim();
|
|
37
|
+
|
|
38
|
+
const attributeFormat = () => {
|
|
39
|
+
if (alwaysExpression) {
|
|
40
|
+
return `:${propertyName}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return hasExpression ? `:${propertyName}` : propertyName;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
context.report({
|
|
47
|
+
node,
|
|
48
|
+
loc: node.loc,
|
|
49
|
+
messageId: 'migrateDefaultSlot',
|
|
50
|
+
*fix(fixer) {
|
|
51
|
+
const attribute = attributeFormat();
|
|
52
|
+
// Add attribute at the end of opening tag
|
|
53
|
+
const attributeValue = hasExpression ? `\`${slotContent}\`` : slotContent;
|
|
54
|
+
yield fixer.insertTextBefore(closingBrace, ` ${attribute}="${attributeValue}" /`);
|
|
55
|
+
|
|
56
|
+
// Remove everything after the closing brace
|
|
57
|
+
yield fixer.removeRange([closingBrace.range[0] + 1, node.range[1]]);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
}
|