@adyen/eslint-plugin-bento 0.0.0 → 1.0.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
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Bento ESLint
|
|
2
|
+
|
|
3
|
+
The Bento ESLint package helps improving the usage of Bento components and utility classes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev eslint@8 vue-eslint-parser@7 @adyen/eslint-plugin-bento
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
<!-- prettier-ignore -->
|
|
12
|
+
> Requirements
|
|
13
|
+
>
|
|
14
|
+
> ESLint v6.0.0 up to v8.0.0
|
|
15
|
+
> Node.js v12.22.x, v14.17.x, v16.x and above
|
|
16
|
+
> `vue-eslint-parser` v7.0.0
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
The `@adyen/bento` plugin hasn't been tested in ESLint9 nor with the flat config (i.e. `eslint.config.js`).
|
|
21
|
+
|
|
22
|
+
### Legacy Config (`.eslintrc`)
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
module.exports = {
|
|
26
|
+
extends: ['plugin:@adyen/bento/recommended'],
|
|
27
|
+
rules: {
|
|
28
|
+
// override/add rules settings here, such as:
|
|
29
|
+
// '@adyen/bento/spacer-tokens': 'error',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or without the recommended config:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
module.exports = {
|
|
38
|
+
parser: 'vue-eslint-parser',
|
|
39
|
+
plugins: ['@adyen/bento'],
|
|
40
|
+
rules: {
|
|
41
|
+
'@adyen/bento/vue-old-spacer-tokens': 'warn',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Rules
|
|
47
|
+
|
|
48
|
+
### `@adyen/bento/vue-old-spacer-tokens`
|
|
49
|
+
|
|
50
|
+
Disallow the use of ADL space utility classes in favor of Bento _spacer_ utility classes.
|
|
51
|
+
|
|
52
|
+
### Recommended
|
|
53
|
+
|
|
54
|
+
The recommended configuration contains pre-configured rules and their severity
|
|
55
|
+
|
|
56
|
+
- `@adyen/bento/vue-old-spacer-tokens`: `warn`
|
package/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const spacerTokens = require('./rules/vue-old-spacer-tokens/vue-old-spacer-tokens');
|
|
3
|
+
|
|
4
|
+
// The package name and version must be in sync with 'package.json'
|
|
5
|
+
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
meta: {
|
|
9
|
+
name: pkg.name,
|
|
10
|
+
version: pkg.version,
|
|
11
|
+
},
|
|
12
|
+
configs: {
|
|
13
|
+
recommended: {
|
|
14
|
+
parser: 'vue-eslint-parser',
|
|
15
|
+
plugins: ['@adyen/bento'],
|
|
16
|
+
rules: {
|
|
17
|
+
'@adyen/bento/vue-old-spacer-tokens': 'warn',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
'vue-old-spacer-tokens': spacerTokens,
|
|
23
|
+
},
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
"name": "@adyen/eslint-plugin-bento",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Adyen Bento ESLint rules",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"rules/*",
|
|
9
|
+
"!**/__tests__",
|
|
10
|
+
"!**/*.test.ts"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"lint": "eslint -c ./.eslintrc.js ./ --exit-on-fatal-error",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:coverage": "npm run test -- --coverage",
|
|
19
|
+
"test:watch": "vitest watch"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git@github.com:Adyen/bento.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"eslint": "^8.57.0",
|
|
28
|
+
"vue-eslint-parser": "^7.11.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"eslint": "^8.0",
|
|
32
|
+
"vue-eslint-parser": "^7.0"
|
|
33
|
+
}
|
|
5
34
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @adyen/bento/vue-old-spacer-tokens
|
|
2
|
+
|
|
3
|
+
> Disallow the use of ADL space utility classes in favor of Bento _spacer_ utility classes.
|
|
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 is use to help developers migrate some of the ADL space utility classes into Bento _spacer_ utility classes
|
|
9
|
+
based on the following mapping table:
|
|
10
|
+
|
|
11
|
+
| ADL | Bento | Pixels |
|
|
12
|
+
| -------------- | --------------- | ------ |
|
|
13
|
+
| `u-padding-0` | `b-padding-000` | `0` |
|
|
14
|
+
| `u-padding-2` | `b-padding-010` | `2` |
|
|
15
|
+
| `u-padding-4` | `b-padding-020` | `4` |
|
|
16
|
+
| `u-padding-8` | `b-padding-040` | `8` |
|
|
17
|
+
| `u-padding-16` | `b-padding-070` | `16` |
|
|
18
|
+
| `u-padding-24` | `b-padding-090` | `24` |
|
|
19
|
+
| `u-padding-32` | `b-padding-100` | `32` |
|
|
20
|
+
| `u-padding-40` | `b-padding-110` | `40` |
|
|
21
|
+
| `u-padding-48` | `b-padding-120` | `48` |
|
|
22
|
+
| `u-padding-56` | `b-padding-130` | `56` |
|
|
23
|
+
| `u-padding-64` | `b-padding-140` | `64` |
|
|
24
|
+
| `u-margin-0` | `b-margin-000` | `0` |
|
|
25
|
+
| `u-margin-2` | `b-margin-010` | `2` |
|
|
26
|
+
| `u-margin-4` | `b-margin-020` | `4` |
|
|
27
|
+
| `u-margin-8` | `b-margin-040` | `8` |
|
|
28
|
+
| `u-margin-16` | `b-margin-070` | `16` |
|
|
29
|
+
| `u-margin-24` | `b-margin-090` | `24` |
|
|
30
|
+
| `u-margin-32` | `b-margin-100` | `32` |
|
|
31
|
+
| `u-margin-40` | `b-margin-110` | `40` |
|
|
32
|
+
| `u-margin-48` | `b-margin-120` | `48` |
|
|
33
|
+
| `u-margin-56` | `b-margin-130` | `56` |
|
|
34
|
+
| `u-margin-64` | `b-margin-140` | `64` |
|
|
35
|
+
|
|
36
|
+
Each of these values in all their variants are translated to their Bento counterpart:
|
|
37
|
+
|
|
38
|
+
- top: `u-{padding|margin}-top-{pixels}`
|
|
39
|
+
- bottom: `u-{padding|margin}-bottom-{pixels}`
|
|
40
|
+
- right: `u-{padding|margin}-right-{pixels}`
|
|
41
|
+
- left: `u-{padding|margin}-left-{pixels}`
|
|
42
|
+
- x - horizontal space: `u-{padding|margin}-x-{pixels}`
|
|
43
|
+
- y - vertical space: `u-{padding|margin}-y-{pixels}`
|
|
44
|
+
- space all directions: `u-{padding|margin}-{pixels}`
|
|
45
|
+
|
|
46
|
+
The following values **are not mapped** and they are left to the discretion of the developer to migrate:
|
|
47
|
+
|
|
48
|
+
| ADL |
|
|
49
|
+
| ------------ |
|
|
50
|
+
| u-padding-72 |
|
|
51
|
+
| u-padding-80 |
|
|
52
|
+
| u-padding-88 |
|
|
53
|
+
| u-padding-96 |
|
|
54
|
+
|
|
55
|
+
## ✗ BAD
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
<template>
|
|
59
|
+
<div class="u-spacer-4"></div>
|
|
60
|
+
<div class="u-spacer-top-32 u-spacer-bottom-32"></div>
|
|
61
|
+
<div class="u-spacer-x-4 u-spacer-y-4"></div>
|
|
62
|
+
<div class="u-spacer-right-4 u-spacer-left-4"></div>
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## ✓ Good
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
<template>
|
|
70
|
+
<div class="b-spacer-020"></div>
|
|
71
|
+
<div class="b-spacer-top-100 b-spacer-bottom-100"></div>
|
|
72
|
+
<div class="b-spacer-x-020 b-spacer-y-020"></div>
|
|
73
|
+
<div class="b-spacer-right-020 b-spacer-left-020"></div>
|
|
74
|
+
</template>
|
|
75
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const VueUtils = require('eslint-plugin-vue/lib/utils');
|
|
2
|
+
|
|
3
|
+
// Mappings for the classes that can to be replaced
|
|
4
|
+
const CLASS_MAP = {
|
|
5
|
+
'0': '000',
|
|
6
|
+
'2': '010',
|
|
7
|
+
'4': '020',
|
|
8
|
+
'8': '040',
|
|
9
|
+
'16': '070',
|
|
10
|
+
'24': '090',
|
|
11
|
+
'32': '100',
|
|
12
|
+
'40': '110',
|
|
13
|
+
'48': '120',
|
|
14
|
+
'56': '130',
|
|
15
|
+
'64': '140',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'suggestion', // The type can be "problem", "suggestion", or "layout"
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Replace old utility margin and padding classes with new ones',
|
|
23
|
+
category: 'Best Practices',
|
|
24
|
+
url: 'https://github.com/Adyen/bento/blob/main/packages/eslint/rules/vue-old-spacer-tokens/README.md',
|
|
25
|
+
recommended: true,
|
|
26
|
+
},
|
|
27
|
+
messages: {
|
|
28
|
+
updateUtilityClass: 'Found outdated class names that need replacing',
|
|
29
|
+
},
|
|
30
|
+
fixable: 'code',
|
|
31
|
+
schema: [], // No options are needed for this rule
|
|
32
|
+
},
|
|
33
|
+
create(context) {
|
|
34
|
+
return VueUtils.defineTemplateBodyVisitor(context, {
|
|
35
|
+
VLiteral: node => {
|
|
36
|
+
if (typeof node.value === 'string') {
|
|
37
|
+
let fixed = node.value;
|
|
38
|
+
let hasReplacements = false;
|
|
39
|
+
|
|
40
|
+
// Check if the class list has "padding" or "margin" utilities
|
|
41
|
+
const regexPaddingMargin = /\bu-(padding|margin)\b/g;
|
|
42
|
+
if (regexPaddingMargin.test(fixed)) {
|
|
43
|
+
// Loop through the list of classes and replace them
|
|
44
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
45
|
+
for (const [oldClass, newClass] of Object.entries(CLASS_MAP)) {
|
|
46
|
+
// Check if the utility can be fixed/re-mapped
|
|
47
|
+
// by checking if the digit has a Bento counterpart
|
|
48
|
+
const regexOldNewMapping = new RegExp(`\\b${oldClass}\\b`, 'g');
|
|
49
|
+
if (regexOldNewMapping.test(fixed)) {
|
|
50
|
+
hasReplacements = true;
|
|
51
|
+
|
|
52
|
+
// Replace values to Bento
|
|
53
|
+
fixed = fixed
|
|
54
|
+
.replace(regexOldNewMapping, newClass) // Replace numbers
|
|
55
|
+
.replace(/u-/g, 'b-'); // Replace class to Bento
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// If replacements were made, report and provide a fix
|
|
61
|
+
if (hasReplacements) {
|
|
62
|
+
context.report({
|
|
63
|
+
node,
|
|
64
|
+
messageId: 'updateUtilityClass',
|
|
65
|
+
fix(fixer) {
|
|
66
|
+
return fixer.replaceText(node, `"${fixed}"`);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
};
|