@dialpad/eslint-plugin-dialtone 1.0.1 → 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 +5 -0
- package/docs/rules/custom-implementation.md +29 -0
- package/docs/rules/old-svg-icons.md +0 -2
- package/lib/rules/custom-implementation.js +69 -0
- package/lib/rules/old-svg-icons.js +1 -1
- package/lib/rules/old-vue-icons.js +1 -1
- package/package.json +1 -1
- package/tests/lib/rules/custom-implementation.js +44 -0
- package/tests/lib/rules/old-svg-icons.js +1 -1
- package/tests/lib/rules/old-vue-icons.js +1 -1
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
|
+
```
|
|
@@ -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
|
+
};
|
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
|
15
15
|
docs: {
|
|
16
16
|
description: 'Finds old svg icons imports from dialtone',
|
|
17
17
|
recommended: false,
|
|
18
|
-
url:
|
|
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
19
|
},
|
|
20
20
|
fixable: null, // Or `code` or `whitespace`
|
|
21
21
|
schema: [], // Add a schema if the rule has options
|
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
|
15
15
|
docs: {
|
|
16
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
|
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
|
+
});
|
|
@@ -15,7 +15,7 @@ const rule = require("../../../lib/rules/old-svg-icons"), RuleTester = require("
|
|
|
15
15
|
// Tests
|
|
16
16
|
//------------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
-
const ruleTester = new RuleTester({parserOptions: {
|
|
18
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
19
19
|
ruleTester.run("old-svg-icons", rule, {
|
|
20
20
|
valid: [
|
|
21
21
|
{
|
|
@@ -15,7 +15,7 @@ const rule = require("../../../lib/rules/old-vue-icons"), RuleTester = require("
|
|
|
15
15
|
// Tests
|
|
16
16
|
//------------------------------------------------------------------------------
|
|
17
17
|
|
|
18
|
-
const ruleTester = new RuleTester({parserOptions: {
|
|
18
|
+
const ruleTester = new RuleTester({parserOptions: {sourceType: 'module', ecmaVersion: 'latest'}});
|
|
19
19
|
ruleTester.run("old-vue-icons", rule, {
|
|
20
20
|
valid: [
|
|
21
21
|
{
|