eslint-plugin-primer-react 3.0.0 → 4.0.0-rc.1e980db

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.
@@ -0,0 +1,62 @@
1
+ const {flattenComponents} = require('../flatten-components')
2
+
3
+ const mockComponents = function(passedObj) {
4
+ return {
5
+ Button: 'button',
6
+ Link: 'a',
7
+ Spinner: 'svg',
8
+ Radio: 'input',
9
+ TextInput: {
10
+ Action: 'button',
11
+ self: 'input'
12
+ },
13
+ ...passedObj
14
+ }
15
+ }
16
+
17
+ describe('getElementType', function() {
18
+ it('flattens passed object 1-level deep', function() {
19
+ const result = flattenComponents(mockComponents())
20
+
21
+ const expectedResult = {
22
+ Button: 'button',
23
+ Link: 'a',
24
+ Spinner: 'svg',
25
+ Radio: 'input',
26
+ TextInput: 'input',
27
+ 'TextInput.Action': 'button'
28
+ }
29
+
30
+ expect(result).toEqual(expectedResult)
31
+ })
32
+
33
+ it('ignores objects nested deeper than 1-level', function() {
34
+ const result = flattenComponents(
35
+ mockComponents({
36
+ Select: {
37
+ Items: {
38
+ self: 'div'
39
+ },
40
+ Option: 'option',
41
+ self: 'select'
42
+ }
43
+ })
44
+ )
45
+
46
+ const expectedResult = {
47
+ Button: 'button',
48
+ Link: 'a',
49
+ Spinner: 'svg',
50
+ Radio: 'input',
51
+ TextInput: 'input',
52
+ 'TextInput.Action': 'button',
53
+ 'Select.Items': {
54
+ self: 'div'
55
+ },
56
+ Select: 'select',
57
+ 'Select.Option': 'option'
58
+ }
59
+
60
+ expect(result).toEqual(expectedResult)
61
+ })
62
+ })
@@ -0,0 +1,17 @@
1
+ function flattenComponents(componentObj) {
2
+ let result = {};
3
+
4
+ Object.keys(componentObj).forEach((key) => {
5
+ if (typeof componentObj[key] === 'object') {
6
+ const test = Object.keys(componentObj[key]).forEach((item) => {
7
+ result = { ...result, [`${key}${item !== 'self' ? `.${item}` : ''}`]: componentObj[key][item] };
8
+ });
9
+ } else {
10
+ result = {...result, [key]: componentObj[key]}
11
+ }
12
+ });
13
+
14
+ return result;
15
+ }
16
+
17
+ exports.flattenComponents = flattenComponents
@@ -0,0 +1,10 @@
1
+ function getJSXOpeningElementAttribute(openingEl, name) {
2
+ const attributes = openingEl.attributes
3
+ const attribute = attributes.find(attribute => {
4
+ return attribute.name && attribute.name.name === name
5
+ })
6
+
7
+ return attribute
8
+ }
9
+
10
+ exports.getJSXOpeningElementAttribute = getJSXOpeningElementAttribute