@elastic/eslint-plugin-eui 0.2.0 → 2.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 +13 -17
- package/lib/cjs/index.js +2 -5
- package/lib/cjs/utils/resolve_member_expression_root.d.ts.map +1 -1
- package/lib/esm/index.js +0 -3
- package/lib/esm/index.js.map +1 -1
- package/package.json +8 -9
- package/lib/cjs/rules/prefer_css_attribute_for_eui_components.d.ts +0 -3
- package/lib/cjs/rules/prefer_css_attribute_for_eui_components.d.ts.map +0 -1
- package/lib/cjs/rules/prefer_css_attribute_for_eui_components.js +0 -63
- package/lib/esm/rules/prefer_css_attribute_for_eui_components.d.ts +0 -2
- package/lib/esm/rules/prefer_css_attribute_for_eui_components.js +0 -63
- package/lib/esm/rules/prefer_css_attribute_for_eui_components.js.map +0 -1
package/README.md
CHANGED
|
@@ -128,33 +128,29 @@ function MyComponent() {
|
|
|
128
128
|
|
|
129
129
|
It's worth pointing out that although the examples provided are specific to EUI components, this rule applies to all JSX elements.
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
This rule warns about the use of `style` attribute and encourages to replace it with `css` attribute. Using the `css` attribute ensures better integration with Emotion's styling capabilities.
|
|
134
|
-
|
|
135
|
-
#### Example
|
|
136
|
-
|
|
137
|
-
The following code:
|
|
131
|
+
## Testing
|
|
138
132
|
|
|
139
|
-
|
|
140
|
-
<EuiCode style={{ color: '#dd4040' }}>This is a test</EuiCode>
|
|
141
|
-
```
|
|
133
|
+
### Running unit tests
|
|
142
134
|
|
|
143
|
-
|
|
135
|
+
Run unit tests using the following command:
|
|
144
136
|
|
|
145
|
-
```
|
|
146
|
-
|
|
137
|
+
```bash
|
|
138
|
+
yarn test
|
|
147
139
|
```
|
|
148
140
|
|
|
149
|
-
|
|
141
|
+
Unit tests are written using `RuleTester` from `@typescript-eslint/rule-tester`.
|
|
150
142
|
|
|
151
143
|
### Against an existing package
|
|
152
144
|
|
|
153
145
|
To test the local changes to the plugin, you must:
|
|
154
146
|
|
|
155
|
-
1.
|
|
156
|
-
2.
|
|
157
|
-
3.
|
|
147
|
+
1. Install `yalc` globally if you haven't already: `npm install -g yalc`.
|
|
148
|
+
2. Open a terminal and navigate to this folder: `cd packages/eslint-plugin`
|
|
149
|
+
3. Build the package: `yarn build`
|
|
150
|
+
4. Run `yalc publish` in the plugin's directory to publish it locally.
|
|
151
|
+
5. In your project's directory, run `yalc add @elastic/eslint-plugin-eui` to link the locally published package.
|
|
152
|
+
6. Install dependencies: `yarn` (if you're a Kibana contributor, run `yarn kbn bootstrap --no-validate`).
|
|
153
|
+
7. After making further changes to the plugin, repeat the steps from 3.
|
|
158
154
|
|
|
159
155
|
## Publishing
|
|
160
156
|
|
package/lib/cjs/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var _href_or_on_click = require("./rules/href_or_on_click");
|
|
4
4
|
var _no_restricted_eui_imports = require("./rules/no_restricted_eui_imports");
|
|
5
5
|
var _no_css_color = require("./rules/no_css_color");
|
|
6
|
-
var _prefer_css_attribute_for_eui_components = require("./rules/prefer_css_attribute_for_eui_components");
|
|
7
6
|
/*
|
|
8
7
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
9
8
|
* license agreements. See the NOTICE file distributed with
|
|
@@ -27,8 +26,7 @@ const config = {
|
|
|
27
26
|
rules: {
|
|
28
27
|
'href-or-on-click': _href_or_on_click.HrefOnClick,
|
|
29
28
|
'no-restricted-eui-imports': _no_restricted_eui_imports.NoRestrictedEuiImports,
|
|
30
|
-
'no-css-color': _no_css_color.NoCssColor
|
|
31
|
-
'prefer-css-attributes-for-eui-components': _prefer_css_attribute_for_eui_components.PreferCSSAttributeForEuiComponents
|
|
29
|
+
'no-css-color': _no_css_color.NoCssColor
|
|
32
30
|
},
|
|
33
31
|
configs: {
|
|
34
32
|
recommended: {
|
|
@@ -36,8 +34,7 @@ const config = {
|
|
|
36
34
|
rules: {
|
|
37
35
|
'@elastic/eui/href-or-on-click': 'warn',
|
|
38
36
|
'@elastic/eui/no-restricted-eui-imports': 'warn',
|
|
39
|
-
'@elastic/eui/no-css-color': 'warn'
|
|
40
|
-
'@elastic/eui/prefer-css-attributes-for-eui-components': 'warn'
|
|
37
|
+
'@elastic/eui/no-css-color': 'warn'
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve_member_expression_root.d.ts","sourceRoot":"","sources":["../../../src/utils/resolve_member_expression_root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAEhE,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"resolve_member_expression_root.d.ts","sourceRoot":"","sources":["../../../src/utils/resolve_member_expression_root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAEhE,eAAO,MAAM,2BAA2B,GACtC,MAAM,QAAQ,CAAC,gBAAgB,KAC9B,QAAQ,CAAC,UAMX,CAAC"}
|
package/lib/esm/index.js
CHANGED
|
@@ -21,13 +21,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
const href_or_on_click_1 = require("./rules/href_or_on_click");
|
|
22
22
|
const no_restricted_eui_imports_1 = require("./rules/no_restricted_eui_imports");
|
|
23
23
|
const no_css_color_1 = require("./rules/no_css_color");
|
|
24
|
-
const prefer_css_attribute_for_eui_components_1 = require("./rules/prefer_css_attribute_for_eui_components");
|
|
25
24
|
const config = {
|
|
26
25
|
rules: {
|
|
27
26
|
'href-or-on-click': href_or_on_click_1.HrefOnClick,
|
|
28
27
|
'no-restricted-eui-imports': no_restricted_eui_imports_1.NoRestrictedEuiImports,
|
|
29
28
|
'no-css-color': no_css_color_1.NoCssColor,
|
|
30
|
-
'prefer-css-attributes-for-eui-components': prefer_css_attribute_for_eui_components_1.PreferCSSAttributeForEuiComponents,
|
|
31
29
|
},
|
|
32
30
|
configs: {
|
|
33
31
|
recommended: {
|
|
@@ -36,7 +34,6 @@ const config = {
|
|
|
36
34
|
'@elastic/eui/href-or-on-click': 'warn',
|
|
37
35
|
'@elastic/eui/no-restricted-eui-imports': 'warn',
|
|
38
36
|
'@elastic/eui/no-css-color': 'warn',
|
|
39
|
-
'@elastic/eui/prefer-css-attributes-for-eui-components': 'warn',
|
|
40
37
|
},
|
|
41
38
|
},
|
|
42
39
|
},
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,+DAAuD;AACvD,iFAA2E;AAC3E,uDAAkD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,+DAAuD;AACvD,iFAA2E;AAC3E,uDAAkD;AAElD,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,kBAAkB,EAAE,8BAAW;QAC/B,2BAA2B,EAAE,kDAAsB;QACnD,cAAc,EAAE,yBAAU;KAC3B;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,OAAO,EAAE,CAAC,4BAA4B,CAAC;YACvC,KAAK,EAAE;gBACL,+BAA+B,EAAE,MAAM;gBACvC,wCAAwC,EAAE,MAAM;gBAChD,2BAA2B,EAAE,MAAM;aACpC;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/eslint-plugin-eui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@types/dedent": "^0.7.2",
|
|
28
28
|
"@types/jest": "^29.5.14",
|
|
29
29
|
"@types/micromatch": "^4.0.9",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
31
|
-
"@typescript-eslint/parser": "^8.
|
|
32
|
-
"@typescript-eslint/rule-tester": "^8.
|
|
33
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
34
|
-
"@typescript-eslint/utils": "^8.
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
|
31
|
+
"@typescript-eslint/parser": "^8.31.1",
|
|
32
|
+
"@typescript-eslint/rule-tester": "^8.31.1",
|
|
33
|
+
"@typescript-eslint/typescript-estree": "^8.31.1",
|
|
34
|
+
"@typescript-eslint/utils": "^8.31.1",
|
|
35
35
|
"cssstyle": "^4.2.1",
|
|
36
36
|
"dedent": "^1.5.3",
|
|
37
37
|
"eslint": "^8.57.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"rimraf": "^6.0.1",
|
|
41
41
|
"ts-jest": "^29.2.5",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
|
-
"typescript": "^5.
|
|
43
|
+
"typescript": "^5.8.3"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"test": "jest src",
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
"build:clean": "rimraf lib/",
|
|
49
49
|
"build:compile:esm": "tsc --project ./tsconfig.esm.json",
|
|
50
50
|
"build:compile": "NODE_ENV=production babel src --out-dir=lib/cjs --extensions .js,.ts,.tsx",
|
|
51
|
-
"build:types": "NODE_ENV=production tsc --project tsconfig.types.json"
|
|
52
|
-
"build:pack": "yarn build && npm pack"
|
|
51
|
+
"build:types": "NODE_ENV=production tsc --project tsconfig.types.json"
|
|
53
52
|
},
|
|
54
53
|
"files": [
|
|
55
54
|
"lib",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const PreferCSSAttributeForEuiComponents: ESLintUtils.RuleModule<"preferCSSAttributeForEuiComponents", [], unknown, ESLintUtils.RuleListener>;
|
|
3
|
-
//# sourceMappingURL=prefer_css_attribute_for_eui_components.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefer_css_attribute_for_eui_components.d.ts","sourceRoot":"","sources":["../../../src/rules/prefer_css_attribute_for_eui_components.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAY,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEjE,eAAO,MAAM,kCAAkC,qGA0D3C,CAAC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PreferCSSAttributeForEuiComponents = void 0;
|
|
7
|
-
var _utils = require("@typescript-eslint/utils");
|
|
8
|
-
/*
|
|
9
|
-
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
10
|
-
* license agreements. See the NOTICE file distributed with
|
|
11
|
-
* this work for additional information regarding copyright
|
|
12
|
-
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
13
|
-
* the Apache License, Version 2.0 (the "License"); you may
|
|
14
|
-
* not use this file except in compliance with the License.
|
|
15
|
-
* You may obtain a copy of the License at
|
|
16
|
-
*
|
|
17
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
-
*
|
|
19
|
-
* Unless required by applicable law or agreed to in writing,
|
|
20
|
-
* software distributed under the License is distributed on an
|
|
21
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
22
|
-
* KIND, either express or implied. See the License for the
|
|
23
|
-
* specific language governing permissions and limitations
|
|
24
|
-
* under the License.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const PreferCSSAttributeForEuiComponents = exports.PreferCSSAttributeForEuiComponents = _utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
28
|
-
create(context) {
|
|
29
|
-
const isNamedEuiComponentRegex = /^Eui[A-Z]*/;
|
|
30
|
-
return {
|
|
31
|
-
JSXOpeningElement(node) {
|
|
32
|
-
if (node.name.type === 'JSXIdentifier' && isNamedEuiComponentRegex.test(node.name.name)) {
|
|
33
|
-
let styleAttrNode;
|
|
34
|
-
if (styleAttrNode = node.attributes.filter(attr => attr.type === 'JSXAttribute').find(attr => attr.name.name === 'style')) {
|
|
35
|
-
context.report({
|
|
36
|
-
node: styleAttrNode?.parent,
|
|
37
|
-
messageId: 'preferCSSAttributeForEuiComponents',
|
|
38
|
-
fix(fixer) {
|
|
39
|
-
const cssAttr = node.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'css');
|
|
40
|
-
if (cssAttr) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return fixer.replaceTextRange(styleAttrNode?.name?.range, 'css');
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
meta: {
|
|
52
|
-
type: 'suggestion',
|
|
53
|
-
docs: {
|
|
54
|
-
description: 'Prefer the JSX css attribute for EUI components'
|
|
55
|
-
},
|
|
56
|
-
messages: {
|
|
57
|
-
preferCSSAttributeForEuiComponents: 'Prefer the css attribute for EUI components'
|
|
58
|
-
},
|
|
59
|
-
fixable: 'code',
|
|
60
|
-
schema: []
|
|
61
|
-
},
|
|
62
|
-
defaultOptions: []
|
|
63
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
4
|
-
* license agreements. See the NOTICE file distributed with
|
|
5
|
-
* this work for additional information regarding copyright
|
|
6
|
-
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
7
|
-
* the Apache License, Version 2.0 (the "License"); you may
|
|
8
|
-
* not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing,
|
|
14
|
-
* software distributed under the License is distributed on an
|
|
15
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
-
* KIND, either express or implied. See the License for the
|
|
17
|
-
* specific language governing permissions and limitations
|
|
18
|
-
* under the License.
|
|
19
|
-
*/
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.PreferCSSAttributeForEuiComponents = void 0;
|
|
22
|
-
const utils_1 = require("@typescript-eslint/utils");
|
|
23
|
-
exports.PreferCSSAttributeForEuiComponents = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
24
|
-
create(context) {
|
|
25
|
-
const isNamedEuiComponentRegex = /^Eui[A-Z]*/;
|
|
26
|
-
return {
|
|
27
|
-
JSXOpeningElement(node) {
|
|
28
|
-
if (node.name.type === 'JSXIdentifier' &&
|
|
29
|
-
isNamedEuiComponentRegex.test(node.name.name)) {
|
|
30
|
-
let styleAttrNode;
|
|
31
|
-
if ((styleAttrNode = node.attributes
|
|
32
|
-
.filter((attr) => attr.type === 'JSXAttribute')
|
|
33
|
-
.find((attr) => attr.name.name === 'style'))) {
|
|
34
|
-
context.report({
|
|
35
|
-
node: styleAttrNode?.parent,
|
|
36
|
-
messageId: 'preferCSSAttributeForEuiComponents',
|
|
37
|
-
fix(fixer) {
|
|
38
|
-
const cssAttr = node.attributes.find((attr) => attr.type === 'JSXAttribute' && attr.name.name === 'css');
|
|
39
|
-
if (cssAttr) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
return fixer.replaceTextRange(styleAttrNode?.name?.range, 'css');
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
meta: {
|
|
51
|
-
type: 'suggestion',
|
|
52
|
-
docs: {
|
|
53
|
-
description: 'Prefer the JSX css attribute for EUI components',
|
|
54
|
-
},
|
|
55
|
-
messages: {
|
|
56
|
-
preferCSSAttributeForEuiComponents: 'Prefer the css attribute for EUI components',
|
|
57
|
-
},
|
|
58
|
-
fixable: 'code',
|
|
59
|
-
schema: [],
|
|
60
|
-
},
|
|
61
|
-
defaultOptions: [],
|
|
62
|
-
});
|
|
63
|
-
//# sourceMappingURL=prefer_css_attribute_for_eui_components.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefer_css_attribute_for_eui_components.js","sourceRoot":"","sources":["../../../src/rules/prefer_css_attribute_for_eui_components.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,oDAAiE;AAEpD,QAAA,kCAAkC,GAC7C,mBAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IAClC,MAAM,CAAC,OAAO;QACZ,MAAM,wBAAwB,GAAG,YAAY,CAAC;QAE9C,OAAO;YACL,iBAAiB,CAAC,IAAgC;gBAChD,IACE,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBAClC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAC7C,CAAC;oBACD,IAAI,aAAgD,CAAC;oBAErD,IACE,CAAC,aAAa,GAAG,IAAI,CAAC,UAAU;yBAC7B,MAAM,CACL,CAAC,IAAI,EAAiC,EAAE,CACtC,IAAI,CAAC,IAAI,KAAK,cAAc,CAC/B;yBACA,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,EAC9C,CAAC;wBACD,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,aAAa,EAAE,MAAM;4BAC3B,SAAS,EAAE,oCAAoC;4BAC/C,GAAG,CAAC,KAAK;gCACP,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAClC,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAC3D,CAAC;gCAEF,IAAI,OAAO,EAAE,CAAC;oCACZ,OAAO,IAAI,CAAC;gCACd,CAAC;gCAED,OAAO,KAAK,CAAC,gBAAgB,CAC3B,aAAa,EAAE,IAAI,EAAE,KAAM,EAC3B,KAAK,CACN,CAAC;4BACJ,CAAC;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,iDAAiD;SAC/D;QACD,QAAQ,EAAE;YACR,kCAAkC,EAChC,6CAA6C;SAChD;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC"}
|