@adyen/eslint-plugin-bento 1.2.0 → 1.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/package.json +8 -2
- package/rules/deprecation-currency-default-slot/deprecation-currency-default-slot.js +12 -0
- package/rules/deprecation-tag-default-slot/deprecation-tag-default-slot.js +11 -0
- package/rules/vue-old-spacer-tokens/vue-old-spacer-tokens.js +18 -3
- package/utils/component-slot-migration.js +29 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adyen/eslint-plugin-bento",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Adyen Bento ESLint rules",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -18,11 +18,17 @@
|
|
|
18
18
|
"url": "git@github.com:Adyen/bento.git"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"jscodeshift": "17.1.2"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
25
|
+
"@types/estree": "1.0.6",
|
|
26
|
+
"@types/node": "20.17.24",
|
|
27
|
+
"@types/eslint": "8.56.12",
|
|
22
28
|
"@vitest/coverage-v8": "2.1.9",
|
|
23
29
|
"eslint": "8.57.1",
|
|
24
|
-
"jscodeshift": "17.1.2",
|
|
25
30
|
"vitest": "2.1.9",
|
|
31
|
+
"eslint-plugin-vue": "9.25.0",
|
|
26
32
|
"vue-eslint-parser": "9.3.2"
|
|
27
33
|
},
|
|
28
34
|
"peerDependencies": {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('eslint').Rule.RuleContext} RuleContext
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('eslint-plugin-vue/lib/utils').RuleModule} RuleModule
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
10
|
const { componentSlotMigration } = require('../../utils/component-slot-migration');
|
|
3
11
|
|
|
12
|
+
/** @type {RuleModule} */
|
|
4
13
|
module.exports = {
|
|
5
14
|
meta: {
|
|
6
15
|
type: 'suggestion',
|
|
@@ -16,8 +25,11 @@ module.exports = {
|
|
|
16
25
|
fixable: 'code',
|
|
17
26
|
schema: [], // No options are needed for this rule
|
|
18
27
|
},
|
|
28
|
+
|
|
29
|
+
/** @param {RuleContext} context */
|
|
19
30
|
create(context) {
|
|
20
31
|
const sourceCode = context.getSourceCode();
|
|
32
|
+
|
|
21
33
|
const template =
|
|
22
34
|
sourceCode.parserServices.getTemplateBodyTokenStore &&
|
|
23
35
|
sourceCode.parserServices.getTemplateBodyTokenStore();
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('eslint').Rule.RuleContext} RuleContext
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('eslint-plugin-vue/lib/utils').RuleModule} RuleModule
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
10
|
const { componentSlotMigration } = require('../../utils/component-slot-migration');
|
|
3
11
|
|
|
12
|
+
/** @type {RuleModule} */
|
|
4
13
|
module.exports = {
|
|
5
14
|
meta: {
|
|
6
15
|
type: 'suggestion',
|
|
@@ -16,6 +25,8 @@ module.exports = {
|
|
|
16
25
|
fixable: 'code',
|
|
17
26
|
schema: [], // No options are needed for this rule
|
|
18
27
|
},
|
|
28
|
+
|
|
29
|
+
/** @param {RuleContext} context */
|
|
19
30
|
create(context) {
|
|
20
31
|
const sourceCode = context.getSourceCode();
|
|
21
32
|
const template =
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('eslint').Rule.RuleContext} RuleContext
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('estree').Node} Node
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('vue-eslint-parser/ast').VLiteral} VLiteral
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('eslint-plugin-vue/lib/utils').RuleModule} RuleModule
|
|
12
|
+
*/
|
|
13
|
+
|
|
1
14
|
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
15
|
|
|
3
16
|
// Mappings for the classes that can to be replaced
|
|
@@ -15,6 +28,7 @@ const CLASS_MAP = {
|
|
|
15
28
|
'64': '140',
|
|
16
29
|
};
|
|
17
30
|
|
|
31
|
+
/** @type {RuleModule} */
|
|
18
32
|
module.exports = {
|
|
19
33
|
meta: {
|
|
20
34
|
type: 'suggestion', // The type can be "problem", "suggestion", or "layout"
|
|
@@ -30,16 +44,17 @@ module.exports = {
|
|
|
30
44
|
fixable: 'code',
|
|
31
45
|
schema: [], // No options are needed for this rule
|
|
32
46
|
},
|
|
47
|
+
/** @param {RuleContext} context */
|
|
33
48
|
create(context) {
|
|
34
49
|
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
35
|
-
VLiteral: node => {
|
|
50
|
+
VLiteral: (/** @type {any} */ node) => {
|
|
36
51
|
if (typeof node.value === 'string') {
|
|
37
52
|
let hasReplacements = false;
|
|
38
|
-
const classList = node.value;
|
|
53
|
+
const classList = /** @type {VLiteral['value']} */ node.value;
|
|
39
54
|
|
|
40
55
|
const fixed = classList
|
|
41
56
|
.split(' ')
|
|
42
|
-
.map(cssClass => {
|
|
57
|
+
.map((/** @type {VLiteral['value']} */ cssClass) => {
|
|
43
58
|
// Check if the class list has "padding" or "margin" utilities
|
|
44
59
|
const regexPaddingMargin = /\bu-(padding|margin)\b/g;
|
|
45
60
|
if (regexPaddingMargin.test(cssClass)) {
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
const j = require('jscodeshift');
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('eslint').Rule.RuleContext} RuleContext
|
|
5
|
+
* @typedef {import('eslint').AST.Token} Token
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('vue-eslint-parser/ast').VText} VText
|
|
10
|
+
* @typedef {import('vue-eslint-parser/ast').VExpressionContainer} VExpressionContainer
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef { { propertyName: string, context: RuleContext, template: any, alwaysExpression?: boolean } } ComponentSlotMigrationProps
|
|
15
|
+
* @typedef { (node: any) => void } ComponentSlotMigrationReturn
|
|
16
|
+
*/
|
|
17
|
+
|
|
3
18
|
module.exports = {
|
|
4
19
|
/**
|
|
5
20
|
* Generates a report with a fix to those VElements containing a deprecated default slot.
|
|
6
21
|
*
|
|
7
22
|
* It moves the content of the "default" slot into a prop with the "propertyName" value.
|
|
8
23
|
*
|
|
9
|
-
* @param props Contains the name of the property by which it will be replace and the context
|
|
24
|
+
* @param {ComponentSlotMigrationProps} props Contains the name of the property by which it will be replace and the context
|
|
25
|
+
* @returns {ComponentSlotMigrationReturn}
|
|
10
26
|
*/
|
|
11
27
|
componentSlotMigration({ propertyName, context, template, alwaysExpression = false }) {
|
|
12
28
|
return node => {
|
|
@@ -17,6 +33,11 @@ module.exports = {
|
|
|
17
33
|
// Turned true if one of the children is an expression
|
|
18
34
|
let hasExpression = false;
|
|
19
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @param {VText | VExpressionContainer } node
|
|
38
|
+
* @param {boolean} wrapStringLiteral
|
|
39
|
+
* @returns {string | undefined}
|
|
40
|
+
*/
|
|
20
41
|
function transformNodeToText(node, wrapStringLiteral = false) {
|
|
21
42
|
if (node.type === 'VText') {
|
|
22
43
|
return node.value;
|
|
@@ -31,6 +52,10 @@ module.exports = {
|
|
|
31
52
|
}
|
|
32
53
|
}
|
|
33
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @param { VText | VExpressionContainer } node
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
34
59
|
function removeEmptyVTextNodes(node) {
|
|
35
60
|
if (node.type === 'VText') {
|
|
36
61
|
return !!node.value.trim().length;
|
|
@@ -40,9 +65,11 @@ module.exports = {
|
|
|
40
65
|
}
|
|
41
66
|
|
|
42
67
|
// Opening tag closing brace ">"
|
|
68
|
+
/** @type {Token} */
|
|
43
69
|
const closingBrace = template.getLastToken(node.startTag);
|
|
44
70
|
|
|
45
71
|
// Remove empty nodes
|
|
72
|
+
/** @type { Array<VText | VExpressionContainer> } */
|
|
46
73
|
const filteredNodes = node.children.filter(removeEmptyVTextNodes);
|
|
47
74
|
|
|
48
75
|
// Get all content and concat
|
|
@@ -52,7 +79,7 @@ module.exports = {
|
|
|
52
79
|
}
|
|
53
80
|
|
|
54
81
|
const content = node.children
|
|
55
|
-
.map(node => transformNodeToText(node, true))
|
|
82
|
+
.map((/** @type {VText | VExpressionContainer} */ node) => transformNodeToText(node, true))
|
|
56
83
|
.join('')
|
|
57
84
|
.trim();
|
|
58
85
|
|