@dialpad/eslint-plugin-dialtone 1.0.1 → 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/.eslintrc.js +3 -0
- package/README.md +5 -0
- package/docs/rules/custom-implementation.md +29 -0
- package/docs/rules/{old-svg-icons.md → deprecated-icons.md} +12 -3
- package/lib/rules/custom-implementation.js +69 -0
- package/lib/rules/{old-svg-icons.js → deprecated-icons.js} +7 -14
- package/package.json +1 -1
- package/tests/lib/rules/custom-implementation.js +44 -0
- package/tests/lib/rules/{old-svg-icons.js → deprecated-icons.js} +25 -8
- package/docs/rules/old-vue-icons.md +0 -21
- package/lib/rules/old-vue-icons.js +0 -50
- package/tests/lib/rules/old-vue-icons.js +0 -34
package/.eslintrc.js
CHANGED
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ We use yeoman generator to generate new rules, simply run the command below and
|
|
|
10
10
|
yo eslint:rule
|
|
11
11
|
```
|
|
12
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.
|
|
17
|
+
|
|
13
18
|
## Installation
|
|
14
19
|
|
|
15
20
|
You'll first need to install [ESLint](https://eslint.org/):
|
|
@@ -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
|
+
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Finds
|
|
1
|
+
# Finds deprecated dialtone svg and vue icons usage (deprecated-icons)
|
|
2
2
|
|
|
3
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.
|
|
4
|
+
so we are deprecating old svg and vue icons on dialtone once the migrations are finished.
|
|
5
5
|
|
|
6
6
|
## Rule Details
|
|
7
7
|
|
|
@@ -12,6 +12,8 @@ Examples of **incorrect** code for this rule:
|
|
|
12
12
|
```js
|
|
13
13
|
import svgLockIcon from '@dialpad/dialtone/lib/build/svg/system/lock.svg';
|
|
14
14
|
import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/dist/svg/system/lock.svg';
|
|
15
|
+
import IconSettings from '@dialpad/dialtone/vue/icons/IconSettings';
|
|
16
|
+
import IconSettings from '../node_modules/@dialpad/dialtone/vue/icons/IconSettings';
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
Examples of **correct** code for this rule:
|
|
@@ -23,8 +25,15 @@ import svgLockIcon from '@dialpad/dialtone-icons/dist/svg/lock.svg';
|
|
|
23
25
|
|
|
24
26
|
**If you can use vue**
|
|
25
27
|
```js
|
|
26
|
-
|
|
27
28
|
import { DtIcon } from '@dialpad/dialtone-vue';
|
|
28
29
|
<dt-icon name="lock" />
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Exceptions
|
|
29
33
|
|
|
34
|
+
For now, we are allowing the importing of `brand` and `spot illustrations` icons from dialtone, so this rule will not trigger if you import an
|
|
35
|
+
icon like:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import dialpadAiIcon from '../../node_modules/@dialpad/dialtone/lib/build/svg/brand/dialpad-ai.svg';
|
|
30
39
|
```
|
|
@@ -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
|
+
};
|
|
@@ -13,37 +13,30 @@ module.exports = {
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'suggestion', // `problem`, `suggestion`, or `layout`
|
|
15
15
|
docs: {
|
|
16
|
-
description: 'Finds
|
|
16
|
+
description: 'Finds deprecated svg and vue icon imports from dialtone',
|
|
17
17
|
recommended: false,
|
|
18
|
-
url:
|
|
18
|
+
url: 'https://github.com/dialpad/eslint-plugin-dialtone/blob/main/docs/rules/deprecated-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
|
-
|
|
23
|
+
avoidDeprecatedImport: 'Avoid usage of old dialtone icons [deprecated]. Check https://dialpad.design/components/icon.html for details.',
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
create(context) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//----------------------------------------------------------------------
|
|
30
|
-
// Helpers
|
|
31
|
-
//----------------------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
// any helper functions should go here or else delete this section
|
|
34
|
-
|
|
27
|
+
const iconRegex = /.*@dialpad\/dialtone\/(vue\/.*|.+\.svg)/gm;
|
|
35
28
|
//----------------------------------------------------------------------
|
|
36
29
|
// Public
|
|
37
30
|
//----------------------------------------------------------------------
|
|
38
31
|
|
|
39
32
|
return {
|
|
40
33
|
ImportDeclaration(node) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
34
|
+
const matched = iconRegex.exec(node.source.value.toLowerCase());
|
|
35
|
+
if (!matched ||matched.input.includes('/brand/') || matched.input.includes('/spot/')) return;
|
|
43
36
|
|
|
44
37
|
context.report({
|
|
45
38
|
node: node,
|
|
46
|
-
messageId: '
|
|
39
|
+
messageId: 'avoidDeprecatedImport',
|
|
47
40
|
});
|
|
48
41
|
}
|
|
49
42
|
};
|
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
|
+
});
|
|
@@ -8,20 +8,28 @@
|
|
|
8
8
|
// Requirements
|
|
9
9
|
//------------------------------------------------------------------------------
|
|
10
10
|
|
|
11
|
-
const rule = require("../../../lib/rules/
|
|
11
|
+
const rule = require("../../../lib/rules/deprecated-icons"), RuleTester = require("eslint").RuleTester;
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
//------------------------------------------------------------------------------
|
|
15
15
|
// Tests
|
|
16
16
|
//------------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
-
const ruleTester = new RuleTester({parserOptions: {
|
|
19
|
-
ruleTester.run("
|
|
18
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
19
|
+
ruleTester.run("deprecated-icons", rule, {
|
|
20
20
|
valid: [
|
|
21
21
|
{
|
|
22
22
|
name: 'New icon import',
|
|
23
23
|
code: "import svgLockIcon from '@dialpad/dialtone-icons/dist/svg/lock.svg';",
|
|
24
24
|
},
|
|
25
|
+
{
|
|
26
|
+
name: 'Brand icon import',
|
|
27
|
+
code: "import dialpadAiIcon from '../../node_modules/@dialpad/dialtone/lib/build/svg/brand/dialpad-ai.svg';",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Spot illustration import',
|
|
31
|
+
code: "import SpotBrowserTableGraph from '@dialpad/dialtone/vue/spot/SpotBrowserTableGraph';",
|
|
32
|
+
},
|
|
25
33
|
{
|
|
26
34
|
name: 'Dialtone Styles import',
|
|
27
35
|
code: "import dialtoneCSS from '@dialpad/dialtone/lib/build/less/dialtone.less';",
|
|
@@ -30,22 +38,31 @@ ruleTester.run("old-svg-icons", rule, {
|
|
|
30
38
|
|
|
31
39
|
invalid: [
|
|
32
40
|
{
|
|
33
|
-
name: 'Old icon import from build',
|
|
41
|
+
name: 'Old SVG icon import from build',
|
|
34
42
|
code: "import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/build/svg/system/lock.svg';",
|
|
35
43
|
errors: [
|
|
36
44
|
{
|
|
37
|
-
messageId: "
|
|
45
|
+
messageId: "avoidDeprecatedImport"
|
|
38
46
|
}
|
|
39
47
|
],
|
|
40
48
|
},
|
|
41
49
|
{
|
|
42
|
-
name: 'Old icon import from dist',
|
|
50
|
+
name: 'Old SVG icon import from dist',
|
|
43
51
|
code: "import svgLockIcon from '../node_modules/@dialpad/dialtone/lib/dist/svg/system/lock.svg';",
|
|
44
52
|
errors: [
|
|
45
53
|
{
|
|
46
|
-
messageId: "
|
|
54
|
+
messageId: "avoidDeprecatedImport"
|
|
47
55
|
}
|
|
48
56
|
],
|
|
49
|
-
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Old VUE icon import',
|
|
60
|
+
code: "import IconSettings from '@dialpad/dialtone/vue/icons/IconSettings';",
|
|
61
|
+
errors: [
|
|
62
|
+
{
|
|
63
|
+
messageId: "avoidDeprecatedImport"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
},
|
|
50
67
|
],
|
|
51
68
|
});
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Finds old dialtone vue 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 vue icons imports from dialtone',
|
|
17
|
-
recommended: false,
|
|
18
|
-
url: null, // 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
|
-
avoidVueImport: 'Avoid usage of old dialtone vue icons [deprecated]. Use DtIcon component instead https://vue.dialpad.design/?path=/docs/components-icon--default'
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
create(context) {
|
|
28
|
-
// variables should be defined here
|
|
29
|
-
|
|
30
|
-
//----------------------------------------------------------------------
|
|
31
|
-
// Helpers
|
|
32
|
-
//----------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
// any helper functions should go here or else delete this section
|
|
35
|
-
|
|
36
|
-
//----------------------------------------------------------------------
|
|
37
|
-
// Public
|
|
38
|
-
//----------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
ImportDeclaration(node) {
|
|
42
|
-
if (!node.source.value.toLowerCase().includes('@dialpad/dialtone/vue')) return;
|
|
43
|
-
context.report({
|
|
44
|
-
node: node,
|
|
45
|
-
messageId: 'avoidVueImport',
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
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: {ecmaVersion: 7, sourceType: 'module'}});
|
|
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
|
-
});
|