@dialpad/eslint-plugin-dialtone 1.0.0 → 1.0.2
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/.eslintrc.js +3 -0
- package/README.md +14 -1
- package/docs/rules/custom-implementation.md +29 -0
- package/docs/rules/old-svg-icons.md +28 -0
- package/docs/rules/old-vue-icons.md +21 -0
- package/lib/rules/custom-implementation.js +69 -0
- package/lib/rules/old-svg-icons.js +51 -0
- package/lib/rules/{old-dialtone-icons.js → old-vue-icons.js} +11 -11
- package/package.json +1 -1
- package/tests/lib/rules/custom-implementation.js +44 -0
- package/tests/lib/rules/old-svg-icons.js +51 -0
- package/tests/lib/rules/old-vue-icons.js +34 -0
- package/docs/rules/old-dialtone-icons.md +0 -35
- package/tests/lib/rules/old-dialtone-icons.js +0 -31
package/.eslintrc.js
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# eslint-plugin-dialtone
|
|
2
2
|
|
|
3
|
-
dialtone eslint plugin
|
|
3
|
+
dialtone eslint plugin containing rules to help developers maintain dialtone recommended practices.
|
|
4
|
+
|
|
5
|
+
## Adding a new rule
|
|
6
|
+
|
|
7
|
+
We use yeoman generator to generate new rules, simply run the command below and follow the steps.
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
yo eslint:rule
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Writing rules
|
|
14
|
+
|
|
15
|
+
You can try the code you're trying to detect here: https://astexplorer.net/ to know which function you need to call
|
|
16
|
+
inside `create` function.
|
|
4
17
|
|
|
5
18
|
## Installation
|
|
6
19
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Detects custom dialtone icons implementations (custom-implementation)
|
|
2
|
+
|
|
3
|
+
We detected some custom implementations of vue icons.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule aims to detect and prevent custom implementations using require.context and @dIcon, @dSpot
|
|
8
|
+
|
|
9
|
+
Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import SpotFileUpload from '@dSpot/SpotFileUpload';
|
|
13
|
+
import IconDynamicLayout from '@dIcon/IconDynamicLayout';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const requireIcon = require.context(
|
|
18
|
+
'@dialpad/dialtone/lib/dist/vue/icons',
|
|
19
|
+
false,
|
|
20
|
+
/.*\\.vue$/,
|
|
21
|
+
);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Examples of **correct** code for this rule:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { DtIcon } from '@dialpad/dialtone-vue';
|
|
28
|
+
<dt-icon name="settings" />
|
|
29
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Finds old dialtone svg icons usage (old-svg-icons)
|
|
2
|
+
|
|
3
|
+
We separated icons from dialtone into dialtone-icons repo,
|
|
4
|
+
so we are deprecating old svg icons on dialtone once the migrations are finished.
|
|
5
|
+
|
|
6
|
+
## Rule Details
|
|
7
|
+
|
|
8
|
+
This rule aims to inform developers that they're importing icons from dialtone instead of dialtone-icons.
|
|
9
|
+
|
|
10
|
+
Examples of **incorrect** code for this rule:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import svgLockIcon from '@dialpad/dialtone/lib/build/svg/system/lock.svg';
|
|
14
|
+
import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/dist/svg/system/lock.svg';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
**If you can't use vue**:
|
|
20
|
+
```js
|
|
21
|
+
import svgLockIcon from '@dialpad/dialtone-icons/dist/svg/lock.svg';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**If you can use vue**
|
|
25
|
+
```js
|
|
26
|
+
import { DtIcon } from '@dialpad/dialtone-vue';
|
|
27
|
+
<dt-icon name="lock" />
|
|
28
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Finds old dialtone vue icons usage (old-vue-icons)
|
|
2
|
+
|
|
3
|
+
We separated icons from dialtone into dialtone-icons repo,
|
|
4
|
+
so we are deprecating old vue icons on dialtone once the migrations are finished.
|
|
5
|
+
|
|
6
|
+
## Rule Details
|
|
7
|
+
|
|
8
|
+
This rule aims to inform developers that they're importing icons from dialtone instead of using dtIcon component from dialtone-vue.
|
|
9
|
+
|
|
10
|
+
Examples of **incorrect** code for this rule:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import IconSettings from '@dialpad/dialtone/vue/icons/IconSettings';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { DtIcon } from '@dialpad/dialtone-vue';
|
|
20
|
+
<dt-icon name="settings" />
|
|
21
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Detects custom dialtone icons implementations
|
|
3
|
+
* @author julio ortega
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
12
|
+
module.exports = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'suggestion', // `problem`, `suggestion`, or `layout`
|
|
15
|
+
docs: {
|
|
16
|
+
description: "Detects custom dialtone icons implementations",
|
|
17
|
+
recommended: false,
|
|
18
|
+
url: 'https://github.com/dialpad/eslint-plugin-dialtone/blob/main/docs/rules/custom-implementation.md', // URL to the documentation page for this rule
|
|
19
|
+
},
|
|
20
|
+
fixable: null, // Or `code` or `whitespace`
|
|
21
|
+
schema: [], // Add a schema if the rule has options
|
|
22
|
+
messages: {
|
|
23
|
+
avoidRequireContext: 'Avoid custom dialtone icons implementation. Use DtIcon component instead https://vue.dialpad.design/?path=/docs/components-icon--default',
|
|
24
|
+
avoidCustomImport: 'Avoid importing dialtone icons with custom webpack alias'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
create(context) {
|
|
29
|
+
// variables should be defined here
|
|
30
|
+
|
|
31
|
+
//----------------------------------------------------------------------
|
|
32
|
+
// Helpers
|
|
33
|
+
//----------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
// any helper functions should go here or else delete this section
|
|
36
|
+
|
|
37
|
+
//----------------------------------------------------------------------
|
|
38
|
+
// Public
|
|
39
|
+
//----------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
ImportDeclaration(node) {
|
|
43
|
+
const foundIndex = node.source.value.toLowerCase().search(/@d(spot|icon)/g);
|
|
44
|
+
if (foundIndex === -1) return;
|
|
45
|
+
|
|
46
|
+
context.report({
|
|
47
|
+
node: node,
|
|
48
|
+
messageId: 'avoidCustomImport',
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
VariableDeclaration(node) {
|
|
52
|
+
node.declarations.forEach(declaration => {
|
|
53
|
+
const calleeIsRequireContext = declaration?.init?.callee?.object?.name === 'require' && declaration?.init?.callee?.property?.name === 'context';
|
|
54
|
+
if (!calleeIsRequireContext) return;
|
|
55
|
+
|
|
56
|
+
const argumentsIncludeDialtone = declaration?.init?.arguments?.find(argument => {
|
|
57
|
+
if (typeof argument.value !== 'string') return false;
|
|
58
|
+
return argument.value.toLowerCase().search(/@dialpad\/dialtone\/.*\/icons/g) !== -1
|
|
59
|
+
});
|
|
60
|
+
if (!argumentsIncludeDialtone) return;
|
|
61
|
+
context.report({
|
|
62
|
+
node: node,
|
|
63
|
+
messageId: 'avoidRequireContext',
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Finds old dialtone svg icons usage
|
|
3
|
+
* @author julio ortega
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
12
|
+
module.exports = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'suggestion', // `problem`, `suggestion`, or `layout`
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Finds old svg icons imports from dialtone',
|
|
17
|
+
recommended: false,
|
|
18
|
+
url: 'https://github.com/dialpad/eslint-plugin-dialtone/blob/main/docs/rules/old-svg-icons.md', // URL to the documentation page for this rule
|
|
19
|
+
},
|
|
20
|
+
fixable: null, // Or `code` or `whitespace`
|
|
21
|
+
schema: [], // Add a schema if the rule has options
|
|
22
|
+
messages: {
|
|
23
|
+
avoidSVGImport: 'Avoid usage of old dialtone icons [deprecated]. Check https://dialpad.design/components/icon.html for details.',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
create(context) {
|
|
27
|
+
// variables should be defined here
|
|
28
|
+
|
|
29
|
+
//----------------------------------------------------------------------
|
|
30
|
+
// Helpers
|
|
31
|
+
//----------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
// any helper functions should go here or else delete this section
|
|
34
|
+
|
|
35
|
+
//----------------------------------------------------------------------
|
|
36
|
+
// Public
|
|
37
|
+
//----------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
ImportDeclaration(node) {
|
|
41
|
+
const foundIndex = node.source.value.toLowerCase().search(/@dialpad\/dialtone\/.*\.svg/g);
|
|
42
|
+
if (foundIndex === -1) return;
|
|
43
|
+
|
|
44
|
+
context.report({
|
|
45
|
+
node: node,
|
|
46
|
+
messageId: 'avoidSVGImport',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Finds
|
|
2
|
+
* @fileoverview Finds old dialtone vue icons usage
|
|
3
3
|
* @author julio ortega
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
@@ -13,16 +13,17 @@ module.exports = {
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'suggestion', // `problem`, `suggestion`, or `layout`
|
|
15
15
|
docs: {
|
|
16
|
-
description:
|
|
16
|
+
description: 'Finds old vue icons imports from dialtone',
|
|
17
17
|
recommended: false,
|
|
18
|
-
url:
|
|
18
|
+
url: 'https://github.com/dialpad/eslint-plugin-dialtone/blob/main/docs/rules/old-vue-icons.md', // URL to the documentation page for this rule
|
|
19
19
|
},
|
|
20
20
|
fixable: null, // Or `code` or `whitespace`
|
|
21
21
|
schema: [], // Add a schema if the rule has options
|
|
22
22
|
messages: {
|
|
23
|
-
|
|
24
|
-
}
|
|
23
|
+
avoidVueImport: 'Avoid usage of old dialtone vue icons [deprecated]. Use DtIcon component instead https://vue.dialpad.design/?path=/docs/components-icon--default'
|
|
24
|
+
}
|
|
25
25
|
},
|
|
26
|
+
|
|
26
27
|
create(context) {
|
|
27
28
|
// variables should be defined here
|
|
28
29
|
|
|
@@ -38,12 +39,11 @@ module.exports = {
|
|
|
38
39
|
|
|
39
40
|
return {
|
|
40
41
|
ImportDeclaration(node) {
|
|
41
|
-
if (node.source.value.includes('@dialpad/dialtone/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
42
|
+
if (!node.source.value.toLowerCase().includes('@dialpad/dialtone/vue')) return;
|
|
43
|
+
context.report({
|
|
44
|
+
node: node,
|
|
45
|
+
messageId: 'avoidVueImport',
|
|
46
|
+
});
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
},
|
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Detects custom dialtone icons implementations
|
|
3
|
+
* @author julio ortega
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/custom-implementation"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
20
|
+
ruleTester.run("custom-implementation", rule, {
|
|
21
|
+
valid: [
|
|
22
|
+
{
|
|
23
|
+
name: 'Dialtone-vue DtIcon import',
|
|
24
|
+
code: "import { DtIcon } from '@dialpad/dialtone-vue';",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
|
|
28
|
+
invalid: [
|
|
29
|
+
{
|
|
30
|
+
name: 'require context',
|
|
31
|
+
code: "const requireIcon = require.context(\n" +
|
|
32
|
+
" '@dialpad/dialtone/lib/dist/vue/icons',\n" +
|
|
33
|
+
" false,\n" +
|
|
34
|
+
" /.*\\.vue$/\n" +
|
|
35
|
+
");",
|
|
36
|
+
errors: [{messageId: 'avoidRequireContext'}],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'custom import',
|
|
40
|
+
code: 'import SpotFileUpload from \'@dSpot/SpotFileUpload\';',
|
|
41
|
+
errors: [{messageId: 'avoidCustomImport'}],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Finds old dialtone svg icons usage
|
|
3
|
+
* @author julio ortega
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/old-svg-icons"), RuleTester = require("eslint").RuleTester;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Tests
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
19
|
+
ruleTester.run("old-svg-icons", rule, {
|
|
20
|
+
valid: [
|
|
21
|
+
{
|
|
22
|
+
name: 'New icon import',
|
|
23
|
+
code: "import svgLockIcon from '@dialpad/dialtone-icons/dist/svg/lock.svg';",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'Dialtone Styles import',
|
|
27
|
+
code: "import dialtoneCSS from '@dialpad/dialtone/lib/build/less/dialtone.less';",
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
invalid: [
|
|
32
|
+
{
|
|
33
|
+
name: 'Old icon import from build',
|
|
34
|
+
code: "import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/build/svg/system/lock.svg';",
|
|
35
|
+
errors: [
|
|
36
|
+
{
|
|
37
|
+
messageId: "avoidSVGImport"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'Old icon import from dist',
|
|
43
|
+
code: "import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/dist/svg/system/lock.svg';",
|
|
44
|
+
errors: [
|
|
45
|
+
{
|
|
46
|
+
messageId: "avoidSVGImport"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Finds old dialtone vue icons usage
|
|
3
|
+
* @author julio ortega
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/old-vue-icons"), RuleTester = require("eslint").RuleTester;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Tests
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
19
|
+
ruleTester.run("old-vue-icons", rule, {
|
|
20
|
+
valid: [
|
|
21
|
+
{
|
|
22
|
+
name: 'Dialtone-vue DtIcon import',
|
|
23
|
+
code: "import { DtIcon } from '@dialpad/dialtone-vue';",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
invalid: [
|
|
28
|
+
{
|
|
29
|
+
name: 'Dialtone vue icon import',
|
|
30
|
+
code: "import IconSettingsOld from '@dialpad/dialtone/vue/icons/IconSettings';",
|
|
31
|
+
errors: [{ messageId: 'avoidVueImport' }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Finds and warns about old dialtone icons usage (old-dialtone-icons)
|
|
2
|
-
|
|
3
|
-
Please describe the origin of the rule here.
|
|
4
|
-
|
|
5
|
-
## Rule Details
|
|
6
|
-
|
|
7
|
-
This rule aims to...
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
|
|
13
|
-
// fill me in
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Examples of **correct** code for this rule:
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
|
|
21
|
-
// fill me in
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Options
|
|
26
|
-
|
|
27
|
-
If there are any options, describe them here. Otherwise, delete this section.
|
|
28
|
-
|
|
29
|
-
## When Not To Use It
|
|
30
|
-
|
|
31
|
-
Give a short description of when it would be appropriate to turn off this rule.
|
|
32
|
-
|
|
33
|
-
## Further Reading
|
|
34
|
-
|
|
35
|
-
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Finds and warns about old dialtone icons usage
|
|
3
|
-
* @author julio ortega
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Requirements
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
const rule = require("../../../lib/rules/old-dialtone-icons"),
|
|
12
|
-
RuleTester = require("eslint").RuleTester;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//------------------------------------------------------------------------------
|
|
16
|
-
// Tests
|
|
17
|
-
//------------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
const ruleTester = new RuleTester();
|
|
20
|
-
ruleTester.run("old-dialtone-icons", rule, {
|
|
21
|
-
valid: [
|
|
22
|
-
// give me some code that won't trigger a warning
|
|
23
|
-
],
|
|
24
|
-
|
|
25
|
-
invalid: [
|
|
26
|
-
{
|
|
27
|
-
code: "import svgLockIcon from '@dialpad/dialtone/lib/build/svg/system/lock.svg';",
|
|
28
|
-
errors: [{ message: "Fill me in.", type: "Me too" }],
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
});
|