@hero-design/eslint-plugin 9.0.1-rc2.2 → 9.0.1
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/CHANGELOG.md
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
# @hero-design/eslint-plugin
|
|
2
2
|
|
|
3
|
-
## 9.0.1
|
|
3
|
+
## 9.0.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
8
|
-
|
|
9
|
-
- [#2647](https://github.com/Thinkei/hero-design/pull/2647) [`d24b42494`](https://github.com/Thinkei/hero-design/commit/d24b42494b3915b2500067a51b3970a528224c5b) Thanks [@ttkien](https://github.com/ttkien)! - fix release flow
|
|
10
|
-
|
|
11
|
-
## 9.0.1-rc2.1
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- [#2647](https://github.com/Thinkei/hero-design/pull/2647) [`286e61897`](https://github.com/Thinkei/hero-design/commit/286e61897f3d3a187dfec6f62f46ec8e0028801f) Thanks [@ttkien](https://github.com/ttkien)! - update release flow
|
|
16
|
-
|
|
17
|
-
## 9.0.1-rc2.0
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- [#2647](https://github.com/Thinkei/hero-design/pull/2647) [`96d0a79e0`](https://github.com/Thinkei/hero-design/commit/96d0a79e008db83c915bbadc8d70a5403d6bd4e3) Thanks [@ttkien](https://github.com/ttkien)! - add pre-commit
|
|
22
|
-
|
|
23
|
-
- [#2647](https://github.com/Thinkei/hero-design/pull/2647) [`35fcc3812`](https://github.com/Thinkei/hero-design/commit/35fcc3812a090140848c80ed8d5f39026c4c5ee2) Thanks [@ttkien](https://github.com/ttkien)! - yarn install after bump version
|
|
7
|
+
- [#3187](https://github.com/Thinkei/hero-design/pull/3187) [`c580bccd6`](https://github.com/Thinkei/hero-design/commit/c580bccd6958dd5accc6f7c17192a822630e6536) Thanks [@vinhphan-eh](https://github.com/vinhphan-eh)! - Implement no-direct-color-palette-access rule
|
|
24
8
|
|
|
25
9
|
## 9.0.0
|
|
26
10
|
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
+
const { findIndentifierPath } = require('../utils');
|
|
8
|
+
|
|
7
9
|
//------------------------------------------------------------------------------
|
|
8
10
|
// Rule Definition
|
|
9
11
|
//------------------------------------------------------------------------------
|
|
@@ -46,27 +48,13 @@ module.exports = {
|
|
|
46
48
|
const oldKeys = context.options[0].keys.map((k) => k.old);
|
|
47
49
|
const newKeys = context.options[0].keys.map((k) => k.new);
|
|
48
50
|
|
|
49
|
-
const findPath = (node, identifiers) => {
|
|
50
|
-
const property = node.property;
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
property != null &&
|
|
54
|
-
property.type === 'Identifier' &&
|
|
55
|
-
property.name != null
|
|
56
|
-
) {
|
|
57
|
-
return findPath(node.parent, [...identifiers, property.name]);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return identifiers.join('.');
|
|
61
|
-
};
|
|
62
|
-
|
|
63
51
|
return {
|
|
64
52
|
MemberExpression(node) {
|
|
65
53
|
const object = node.object;
|
|
66
54
|
if (object == null) return;
|
|
67
55
|
|
|
68
56
|
if (object.type === 'Identifier' && object.name === 'theme') {
|
|
69
|
-
const path =
|
|
57
|
+
const path = findIndentifierPath(node, []);
|
|
70
58
|
const deprecatedKeyIndex = oldKeys.findIndex((k) => k === path);
|
|
71
59
|
|
|
72
60
|
if (deprecatedKeyIndex >= 0) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Disallow direct access of color palette.
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const { findIndentifierPath } = require('../utils');
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Rule Definition
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
13
|
+
module.exports = {
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Disallow direct access of color palette.',
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
invalidColorAccess: 'Unexpected direct access of palette colors, use semantic colors instead.',
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
create(context) {
|
|
26
|
+
return {
|
|
27
|
+
MemberExpression(node) {
|
|
28
|
+
const object = node.object;
|
|
29
|
+
if (object == null) return;
|
|
30
|
+
|
|
31
|
+
// For example: theme.colors.pallete.redLight30
|
|
32
|
+
if (object.type === 'Identifier' && object.name === 'theme') {
|
|
33
|
+
const path = findIndentifierPath(node, []);
|
|
34
|
+
|
|
35
|
+
if (path.includes('colors.palette')) {
|
|
36
|
+
context.report({
|
|
37
|
+
node,
|
|
38
|
+
messageId: 'invalidColorAccess',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// For example: colors.pallete.redLight30
|
|
43
|
+
else if (object.type === 'Identifier' && object.name === 'colors') {
|
|
44
|
+
const path = findIndentifierPath(node, []);
|
|
45
|
+
|
|
46
|
+
if (path.includes('palette')) {
|
|
47
|
+
context.report({
|
|
48
|
+
node,
|
|
49
|
+
messageId: 'invalidColorAccess',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const findIndentifierPath = (node, identifiers) => {
|
|
2
|
+
const property = node.property;
|
|
3
|
+
|
|
4
|
+
if (
|
|
5
|
+
property != null &&
|
|
6
|
+
property.type === 'Identifier' &&
|
|
7
|
+
property.name != null
|
|
8
|
+
) {
|
|
9
|
+
return findIndentifierPath(node.parent, [...identifiers, property.name]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return identifiers.join('.');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
findIndentifierPath,
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/eslint-plugin",
|
|
3
|
-
"version": "9.0.1
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Hero Design's eslint plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"eslint-plugin-eslint-plugin": "^5.0.0",
|
|
27
27
|
"eslint-plugin-node": "^11.1.0",
|
|
28
28
|
"jest": "^29.2.1",
|
|
29
|
-
"prettier-config-hd": "8.42.
|
|
29
|
+
"prettier-config-hd": "8.42.4"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": "^14.17.0 || ^16.0.0 || >= 18.0.0"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const rule = require('../../../lib/rules/no-direct-color-palette-access');
|
|
2
|
+
const RuleTester = require('eslint').RuleTester;
|
|
3
|
+
|
|
4
|
+
//------------------------------------------------------------------------------
|
|
5
|
+
// Tests
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
const config = {
|
|
9
|
+
parserOptions: {
|
|
10
|
+
sourceType: 'module',
|
|
11
|
+
ecmaVersion: 6,
|
|
12
|
+
ecmaFeatures: { jsx: true },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const ruleTester = new RuleTester();
|
|
17
|
+
ruleTester.run('no-direct-color-palette-access', rule, {
|
|
18
|
+
valid: [
|
|
19
|
+
{
|
|
20
|
+
code: 'const color = theme.colors.hoverDanger',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
code: '<Box sx={{ backgroundColor: theme.colors.hoverDanger }} />',
|
|
24
|
+
},
|
|
25
|
+
].map((test) => ({ ...test, ...config })),
|
|
26
|
+
invalid: [
|
|
27
|
+
{
|
|
28
|
+
code: 'const color = theme.colors.palette.redLight30',
|
|
29
|
+
errors: [{ messageId: 'invalidColorAccess' }],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
code: 'const color = theme.colors.palette',
|
|
33
|
+
errors: [{ messageId: 'invalidColorAccess' }],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: '<Box sx={{ backgroundColor: theme.colors.palette.redLight30 }} />',
|
|
37
|
+
errors: [{ messageId: 'invalidColorAccess' }],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
code: `const colors = theme.colors;
|
|
41
|
+
const color = colors.palette.redLight30`,
|
|
42
|
+
errors: [{ messageId: 'invalidColorAccess' }],
|
|
43
|
+
}
|
|
44
|
+
].map((test) => ({ ...test, ...config })),
|
|
45
|
+
});
|