@atlaskit/eslint-plugin-design-system 14.1.0 → 14.2.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/CHANGELOG.md +7 -0
- package/dist/cjs/rules/no-readonly-or-disabled-inputs/index.js +30 -14
- package/dist/cjs/rules/use-should-render-to-parent/index.js +32 -9
- package/dist/es2019/rules/no-readonly-or-disabled-inputs/index.js +25 -13
- package/dist/es2019/rules/use-should-render-to-parent/index.js +32 -9
- package/dist/esm/rules/no-readonly-or-disabled-inputs/index.js +29 -14
- package/dist/esm/rules/use-should-render-to-parent/index.js +32 -9
- package/dist/types/rules/no-readonly-or-disabled-inputs/index.d.ts +2 -2
- package/dist/types-ts4.5/rules/no-readonly-or-disabled-inputs/index.d.ts +8 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 14.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`ec906640e3e00`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ec906640e3e00) -
|
|
8
|
+
Add new components to the `use-should-render-to-parent` rule.
|
|
9
|
+
|
|
3
10
|
## 14.1.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.default = exports.UNWANTED_HTML_ATTRIBUTES = exports.UNWANTED_ATLASKIT_ATTRIBUTES = exports.AFFECTED_HTML_ELEMENTS = exports.AFFECTED_ATLASKIT_PACKAGES = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
10
|
var _jsxElement = require("../../ast-nodes/jsx-element");
|
|
9
11
|
var _createRule = require("../utils/create-rule");
|
|
@@ -13,15 +15,26 @@ var AFFECTED_ATLASKIT_PACKAGES = exports.AFFECTED_ATLASKIT_PACKAGES = {
|
|
|
13
15
|
'@atlaskit/textfield': ['default']
|
|
14
16
|
};
|
|
15
17
|
var UNWANTED_HTML_ATTRIBUTES = exports.UNWANTED_HTML_ATTRIBUTES = ['disabled', 'readonly'];
|
|
18
|
+
var isUnwantedHTMLAtrribute = function isUnwantedHTMLAtrribute(s) {
|
|
19
|
+
var attrs = UNWANTED_HTML_ATTRIBUTES;
|
|
20
|
+
return attrs.includes(s);
|
|
21
|
+
};
|
|
16
22
|
var UNWANTED_ATLASKIT_ATTRIBUTES = exports.UNWANTED_ATLASKIT_ATTRIBUTES = ['isDisabled', 'isReadOnly'];
|
|
23
|
+
var isUnwantedAtlaskitAtrribute = function isUnwantedAtlaskitAtrribute(s) {
|
|
24
|
+
var attrs = UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
25
|
+
return attrs.includes(s);
|
|
26
|
+
};
|
|
27
|
+
var isUnwantedAttribute = function isUnwantedAttribute(s) {
|
|
28
|
+
return isUnwantedHTMLAtrribute(s) || isUnwantedAtlaskitAtrribute(s);
|
|
29
|
+
};
|
|
17
30
|
var hasUnwantedAttributes = function hasUnwantedAttributes(node, type) {
|
|
18
|
-
var attrNames = type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
31
|
+
var attrNames = (0, _toConsumableArray2.default)(type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES);
|
|
19
32
|
var unwantedAttrs = node.openingElement.attributes.filter(function (attr) {
|
|
20
33
|
return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute');
|
|
21
34
|
}).map(function (attr) {
|
|
22
35
|
return String(attr.name.name);
|
|
23
|
-
}).filter(function (
|
|
24
|
-
return attrNames.includes(
|
|
36
|
+
}).filter(isUnwantedAttribute).filter(function (unwantedAttribute) {
|
|
37
|
+
return attrNames.includes(unwantedAttribute);
|
|
25
38
|
});
|
|
26
39
|
return unwantedAttrs;
|
|
27
40
|
};
|
|
@@ -68,7 +81,6 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
68
81
|
});
|
|
69
82
|
if (usesDefaultImport && defaultImport.length && defaultImport[0].local) {
|
|
70
83
|
localComponentNames.push(defaultImport[0].local.name);
|
|
71
|
-
// or if popup and using a named import
|
|
72
84
|
} else if (possibleNamedImports.length >= 1 && namedImport.length) {
|
|
73
85
|
namedImport.forEach(function (imp) {
|
|
74
86
|
if (imp.type === 'ImportSpecifier' && 'name' in imp.imported && possibleNamedImports.includes(imp.imported.name)) {
|
|
@@ -85,20 +97,22 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
85
97
|
if (!elName) {
|
|
86
98
|
return false;
|
|
87
99
|
}
|
|
100
|
+
var fixes = [];
|
|
88
101
|
|
|
89
102
|
// If it is one of the affected native HTML elements
|
|
90
103
|
if (AFFECTED_HTML_ELEMENTS.includes(elName)) {
|
|
91
104
|
var unwantedAttributes = hasUnwantedAttributes(node, 'html');
|
|
92
105
|
if (unwantedAttributes.includes('disabled')) {
|
|
93
|
-
|
|
106
|
+
fixes.push(context.report({
|
|
94
107
|
node: node.openingElement,
|
|
95
108
|
messageId: 'noDisabled'
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
if (unwantedAttributes.includes('readonly')) {
|
|
112
|
+
fixes.push(context.report({
|
|
99
113
|
node: node.openingElement,
|
|
100
114
|
messageId: 'noReadOnly'
|
|
101
|
-
});
|
|
115
|
+
}));
|
|
102
116
|
}
|
|
103
117
|
// Else, it is a React component
|
|
104
118
|
} else {
|
|
@@ -112,17 +126,19 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
112
126
|
}
|
|
113
127
|
var _unwantedAttributes = hasUnwantedAttributes(node, 'atlaskit');
|
|
114
128
|
if (_unwantedAttributes.includes('isDisabled')) {
|
|
115
|
-
|
|
129
|
+
fixes.push(context.report({
|
|
116
130
|
node: node.openingElement,
|
|
117
131
|
messageId: 'noDisabled'
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
if (_unwantedAttributes.includes('isReadOnly')) {
|
|
135
|
+
fixes.push(context.report({
|
|
121
136
|
node: node.openingElement,
|
|
122
137
|
messageId: 'noReadOnly'
|
|
123
|
-
});
|
|
138
|
+
}));
|
|
124
139
|
}
|
|
125
140
|
}
|
|
141
|
+
return fixes;
|
|
126
142
|
}
|
|
127
143
|
};
|
|
128
144
|
}
|
|
@@ -13,7 +13,23 @@ var PROP_NAME = 'shouldRenderToParent';
|
|
|
13
13
|
var message = "Setting the `".concat(PROP_NAME, "` prop to anything other than `true` causes accessibility issues. Only set to `false` as a last resort.");
|
|
14
14
|
var addProp = exports.addProp = "Add `".concat(PROP_NAME, "` prop.");
|
|
15
15
|
var setPropToTrue = exports.setPropToTrue = "Set `".concat(PROP_NAME, "` prop to `true`.");
|
|
16
|
-
var components =
|
|
16
|
+
var components = {
|
|
17
|
+
'@atlaskit/popup': {
|
|
18
|
+
default: true,
|
|
19
|
+
named: 'Popup'
|
|
20
|
+
},
|
|
21
|
+
'@atlaskit/dropdown-menu': {
|
|
22
|
+
default: true
|
|
23
|
+
},
|
|
24
|
+
'@atlassian/entry-points/dropdown-trigger': {
|
|
25
|
+
default: false,
|
|
26
|
+
named: 'DropdownTrigger'
|
|
27
|
+
},
|
|
28
|
+
'@atlassian/entry-points/popup-trigger': {
|
|
29
|
+
default: false,
|
|
30
|
+
named: 'PopupTrigger'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
17
33
|
var rule = (0, _createRule.createLintRule)({
|
|
18
34
|
meta: {
|
|
19
35
|
name: RULE_NAME,
|
|
@@ -33,11 +49,12 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
33
49
|
var componentLocalName;
|
|
34
50
|
return {
|
|
35
51
|
ImportDeclaration: function ImportDeclaration(node) {
|
|
52
|
+
var _components$source;
|
|
36
53
|
var source = node.source.value;
|
|
37
54
|
if (typeof source !== 'string') {
|
|
38
55
|
return;
|
|
39
56
|
}
|
|
40
|
-
if (!
|
|
57
|
+
if (!(source in components)) {
|
|
41
58
|
return;
|
|
42
59
|
}
|
|
43
60
|
if (!node.specifiers.length) {
|
|
@@ -46,17 +63,23 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
46
63
|
var defaultImport = node.specifiers.filter(function (spec) {
|
|
47
64
|
return spec.type === 'ImportDefaultSpecifier';
|
|
48
65
|
});
|
|
49
|
-
var
|
|
66
|
+
var namedImports = node.specifiers.filter(function (spec) {
|
|
50
67
|
return spec.type === 'ImportSpecifier';
|
|
51
68
|
});
|
|
52
|
-
|
|
53
|
-
// If popup or dropdown menu and using a default import
|
|
54
|
-
if (defaultImport.length && defaultImport[0].local) {
|
|
69
|
+
if (defaultImport.length && defaultImport[0].local && (_components$source = components[source]) !== null && _components$source !== void 0 && _components$source.default) {
|
|
55
70
|
componentLocalName = defaultImport[0].local.name;
|
|
56
|
-
// or if popup and using a named import
|
|
57
|
-
} else if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && 'name' in namedImport[0].imported && namedImport[0].imported.name === 'Popup') {
|
|
58
|
-
componentLocalName = namedImport[0].local.name;
|
|
59
71
|
}
|
|
72
|
+
if (!namedImports.length) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Iterate through all of them, only one should ever be found
|
|
77
|
+
namedImports.forEach(function (namedImport) {
|
|
78
|
+
var _components$source2;
|
|
79
|
+
if (namedImport.type === 'ImportSpecifier' && 'name' in namedImport.imported && namedImport.imported.name === ((_components$source2 = components[source]) === null || _components$source2 === void 0 ? void 0 : _components$source2.named)) {
|
|
80
|
+
componentLocalName = namedImport.local.name;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
60
83
|
},
|
|
61
84
|
JSXElement: function JSXElement(node) {
|
|
62
85
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
@@ -7,10 +7,19 @@ export const AFFECTED_ATLASKIT_PACKAGES = {
|
|
|
7
7
|
'@atlaskit/textfield': ['default']
|
|
8
8
|
};
|
|
9
9
|
export const UNWANTED_HTML_ATTRIBUTES = ['disabled', 'readonly'];
|
|
10
|
+
const isUnwantedHTMLAtrribute = s => {
|
|
11
|
+
const attrs = UNWANTED_HTML_ATTRIBUTES;
|
|
12
|
+
return attrs.includes(s);
|
|
13
|
+
};
|
|
10
14
|
export const UNWANTED_ATLASKIT_ATTRIBUTES = ['isDisabled', 'isReadOnly'];
|
|
15
|
+
const isUnwantedAtlaskitAtrribute = s => {
|
|
16
|
+
const attrs = UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
17
|
+
return attrs.includes(s);
|
|
18
|
+
};
|
|
19
|
+
const isUnwantedAttribute = s => isUnwantedHTMLAtrribute(s) || isUnwantedAtlaskitAtrribute(s);
|
|
11
20
|
const hasUnwantedAttributes = (node, type) => {
|
|
12
|
-
const attrNames = type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
13
|
-
const unwantedAttrs = node.openingElement.attributes.filter(attr => isNodeOfType(attr, 'JSXAttribute')).map(attr => String(attr.name.name)).filter(
|
|
21
|
+
const attrNames = [...(type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES)];
|
|
22
|
+
const unwantedAttrs = node.openingElement.attributes.filter(attr => isNodeOfType(attr, 'JSXAttribute')).map(attr => String(attr.name.name)).filter(isUnwantedAttribute).filter(unwantedAttribute => attrNames.includes(unwantedAttribute));
|
|
14
23
|
return unwantedAttrs;
|
|
15
24
|
};
|
|
16
25
|
const rule = createLintRule({
|
|
@@ -50,7 +59,6 @@ const rule = createLintRule({
|
|
|
50
59
|
const possibleNamedImports = importNames.filter(importName => importName !== 'default');
|
|
51
60
|
if (usesDefaultImport && defaultImport.length && defaultImport[0].local) {
|
|
52
61
|
localComponentNames.push(defaultImport[0].local.name);
|
|
53
|
-
// or if popup and using a named import
|
|
54
62
|
} else if (possibleNamedImports.length >= 1 && namedImport.length) {
|
|
55
63
|
namedImport.forEach(imp => {
|
|
56
64
|
if (imp.type === 'ImportSpecifier' && 'name' in imp.imported && possibleNamedImports.includes(imp.imported.name)) {
|
|
@@ -67,20 +75,22 @@ const rule = createLintRule({
|
|
|
67
75
|
if (!elName) {
|
|
68
76
|
return false;
|
|
69
77
|
}
|
|
78
|
+
const fixes = [];
|
|
70
79
|
|
|
71
80
|
// If it is one of the affected native HTML elements
|
|
72
81
|
if (AFFECTED_HTML_ELEMENTS.includes(elName)) {
|
|
73
82
|
const unwantedAttributes = hasUnwantedAttributes(node, 'html');
|
|
74
83
|
if (unwantedAttributes.includes('disabled')) {
|
|
75
|
-
|
|
84
|
+
fixes.push(context.report({
|
|
76
85
|
node: node.openingElement,
|
|
77
86
|
messageId: 'noDisabled'
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
if (unwantedAttributes.includes('readonly')) {
|
|
90
|
+
fixes.push(context.report({
|
|
81
91
|
node: node.openingElement,
|
|
82
92
|
messageId: 'noReadOnly'
|
|
83
|
-
});
|
|
93
|
+
}));
|
|
84
94
|
}
|
|
85
95
|
// Else, it is a React component
|
|
86
96
|
} else {
|
|
@@ -94,17 +104,19 @@ const rule = createLintRule({
|
|
|
94
104
|
}
|
|
95
105
|
const unwantedAttributes = hasUnwantedAttributes(node, 'atlaskit');
|
|
96
106
|
if (unwantedAttributes.includes('isDisabled')) {
|
|
97
|
-
|
|
107
|
+
fixes.push(context.report({
|
|
98
108
|
node: node.openingElement,
|
|
99
109
|
messageId: 'noDisabled'
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
if (unwantedAttributes.includes('isReadOnly')) {
|
|
113
|
+
fixes.push(context.report({
|
|
103
114
|
node: node.openingElement,
|
|
104
115
|
messageId: 'noReadOnly'
|
|
105
|
-
});
|
|
116
|
+
}));
|
|
106
117
|
}
|
|
107
118
|
}
|
|
119
|
+
return fixes;
|
|
108
120
|
}
|
|
109
121
|
};
|
|
110
122
|
}
|
|
@@ -7,7 +7,23 @@ const PROP_NAME = 'shouldRenderToParent';
|
|
|
7
7
|
const message = `Setting the \`${PROP_NAME}\` prop to anything other than \`true\` causes accessibility issues. Only set to \`false\` as a last resort.`;
|
|
8
8
|
export const addProp = `Add \`${PROP_NAME}\` prop.`;
|
|
9
9
|
export const setPropToTrue = `Set \`${PROP_NAME}\` prop to \`true\`.`;
|
|
10
|
-
const components =
|
|
10
|
+
const components = {
|
|
11
|
+
'@atlaskit/popup': {
|
|
12
|
+
default: true,
|
|
13
|
+
named: 'Popup'
|
|
14
|
+
},
|
|
15
|
+
'@atlaskit/dropdown-menu': {
|
|
16
|
+
default: true
|
|
17
|
+
},
|
|
18
|
+
'@atlassian/entry-points/dropdown-trigger': {
|
|
19
|
+
default: false,
|
|
20
|
+
named: 'DropdownTrigger'
|
|
21
|
+
},
|
|
22
|
+
'@atlassian/entry-points/popup-trigger': {
|
|
23
|
+
default: false,
|
|
24
|
+
named: 'PopupTrigger'
|
|
25
|
+
}
|
|
26
|
+
};
|
|
11
27
|
const rule = createLintRule({
|
|
12
28
|
meta: {
|
|
13
29
|
name: RULE_NAME,
|
|
@@ -27,26 +43,33 @@ const rule = createLintRule({
|
|
|
27
43
|
let componentLocalName;
|
|
28
44
|
return {
|
|
29
45
|
ImportDeclaration(node) {
|
|
46
|
+
var _components$source;
|
|
30
47
|
const source = node.source.value;
|
|
31
48
|
if (typeof source !== 'string') {
|
|
32
49
|
return;
|
|
33
50
|
}
|
|
34
|
-
if (!
|
|
51
|
+
if (!(source in components)) {
|
|
35
52
|
return;
|
|
36
53
|
}
|
|
37
54
|
if (!node.specifiers.length) {
|
|
38
55
|
return;
|
|
39
56
|
}
|
|
40
57
|
const defaultImport = node.specifiers.filter(spec => spec.type === 'ImportDefaultSpecifier');
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
// If popup or dropdown menu and using a default import
|
|
44
|
-
if (defaultImport.length && defaultImport[0].local) {
|
|
58
|
+
const namedImports = node.specifiers.filter(spec => spec.type === 'ImportSpecifier');
|
|
59
|
+
if (defaultImport.length && defaultImport[0].local && (_components$source = components[source]) !== null && _components$source !== void 0 && _components$source.default) {
|
|
45
60
|
componentLocalName = defaultImport[0].local.name;
|
|
46
|
-
// or if popup and using a named import
|
|
47
|
-
} else if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && 'name' in namedImport[0].imported && namedImport[0].imported.name === 'Popup') {
|
|
48
|
-
componentLocalName = namedImport[0].local.name;
|
|
49
61
|
}
|
|
62
|
+
if (!namedImports.length) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Iterate through all of them, only one should ever be found
|
|
67
|
+
namedImports.forEach(namedImport => {
|
|
68
|
+
var _components$source2;
|
|
69
|
+
if (namedImport.type === 'ImportSpecifier' && 'name' in namedImport.imported && namedImport.imported.name === ((_components$source2 = components[source]) === null || _components$source2 === void 0 ? void 0 : _components$source2.named)) {
|
|
70
|
+
componentLocalName = namedImport.local.name;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
50
73
|
},
|
|
51
74
|
JSXElement(node) {
|
|
52
75
|
if (!isNodeOfType(node, 'JSXElement')) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
3
|
import { JSXElement as _JSXElement } from '../../ast-nodes/jsx-element';
|
|
3
4
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -7,15 +8,26 @@ export var AFFECTED_ATLASKIT_PACKAGES = {
|
|
|
7
8
|
'@atlaskit/textfield': ['default']
|
|
8
9
|
};
|
|
9
10
|
export var UNWANTED_HTML_ATTRIBUTES = ['disabled', 'readonly'];
|
|
11
|
+
var isUnwantedHTMLAtrribute = function isUnwantedHTMLAtrribute(s) {
|
|
12
|
+
var attrs = UNWANTED_HTML_ATTRIBUTES;
|
|
13
|
+
return attrs.includes(s);
|
|
14
|
+
};
|
|
10
15
|
export var UNWANTED_ATLASKIT_ATTRIBUTES = ['isDisabled', 'isReadOnly'];
|
|
16
|
+
var isUnwantedAtlaskitAtrribute = function isUnwantedAtlaskitAtrribute(s) {
|
|
17
|
+
var attrs = UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
18
|
+
return attrs.includes(s);
|
|
19
|
+
};
|
|
20
|
+
var isUnwantedAttribute = function isUnwantedAttribute(s) {
|
|
21
|
+
return isUnwantedHTMLAtrribute(s) || isUnwantedAtlaskitAtrribute(s);
|
|
22
|
+
};
|
|
11
23
|
var hasUnwantedAttributes = function hasUnwantedAttributes(node, type) {
|
|
12
|
-
var attrNames = type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES;
|
|
24
|
+
var attrNames = _toConsumableArray(type === 'html' ? UNWANTED_HTML_ATTRIBUTES : UNWANTED_ATLASKIT_ATTRIBUTES);
|
|
13
25
|
var unwantedAttrs = node.openingElement.attributes.filter(function (attr) {
|
|
14
26
|
return isNodeOfType(attr, 'JSXAttribute');
|
|
15
27
|
}).map(function (attr) {
|
|
16
28
|
return String(attr.name.name);
|
|
17
|
-
}).filter(function (
|
|
18
|
-
return attrNames.includes(
|
|
29
|
+
}).filter(isUnwantedAttribute).filter(function (unwantedAttribute) {
|
|
30
|
+
return attrNames.includes(unwantedAttribute);
|
|
19
31
|
});
|
|
20
32
|
return unwantedAttrs;
|
|
21
33
|
};
|
|
@@ -62,7 +74,6 @@ var rule = createLintRule({
|
|
|
62
74
|
});
|
|
63
75
|
if (usesDefaultImport && defaultImport.length && defaultImport[0].local) {
|
|
64
76
|
localComponentNames.push(defaultImport[0].local.name);
|
|
65
|
-
// or if popup and using a named import
|
|
66
77
|
} else if (possibleNamedImports.length >= 1 && namedImport.length) {
|
|
67
78
|
namedImport.forEach(function (imp) {
|
|
68
79
|
if (imp.type === 'ImportSpecifier' && 'name' in imp.imported && possibleNamedImports.includes(imp.imported.name)) {
|
|
@@ -79,20 +90,22 @@ var rule = createLintRule({
|
|
|
79
90
|
if (!elName) {
|
|
80
91
|
return false;
|
|
81
92
|
}
|
|
93
|
+
var fixes = [];
|
|
82
94
|
|
|
83
95
|
// If it is one of the affected native HTML elements
|
|
84
96
|
if (AFFECTED_HTML_ELEMENTS.includes(elName)) {
|
|
85
97
|
var unwantedAttributes = hasUnwantedAttributes(node, 'html');
|
|
86
98
|
if (unwantedAttributes.includes('disabled')) {
|
|
87
|
-
|
|
99
|
+
fixes.push(context.report({
|
|
88
100
|
node: node.openingElement,
|
|
89
101
|
messageId: 'noDisabled'
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
if (unwantedAttributes.includes('readonly')) {
|
|
105
|
+
fixes.push(context.report({
|
|
93
106
|
node: node.openingElement,
|
|
94
107
|
messageId: 'noReadOnly'
|
|
95
|
-
});
|
|
108
|
+
}));
|
|
96
109
|
}
|
|
97
110
|
// Else, it is a React component
|
|
98
111
|
} else {
|
|
@@ -106,17 +119,19 @@ var rule = createLintRule({
|
|
|
106
119
|
}
|
|
107
120
|
var _unwantedAttributes = hasUnwantedAttributes(node, 'atlaskit');
|
|
108
121
|
if (_unwantedAttributes.includes('isDisabled')) {
|
|
109
|
-
|
|
122
|
+
fixes.push(context.report({
|
|
110
123
|
node: node.openingElement,
|
|
111
124
|
messageId: 'noDisabled'
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
if (_unwantedAttributes.includes('isReadOnly')) {
|
|
128
|
+
fixes.push(context.report({
|
|
115
129
|
node: node.openingElement,
|
|
116
130
|
messageId: 'noReadOnly'
|
|
117
|
-
});
|
|
131
|
+
}));
|
|
118
132
|
}
|
|
119
133
|
}
|
|
134
|
+
return fixes;
|
|
120
135
|
}
|
|
121
136
|
};
|
|
122
137
|
}
|
|
@@ -7,7 +7,23 @@ var PROP_NAME = 'shouldRenderToParent';
|
|
|
7
7
|
var message = "Setting the `".concat(PROP_NAME, "` prop to anything other than `true` causes accessibility issues. Only set to `false` as a last resort.");
|
|
8
8
|
export var addProp = "Add `".concat(PROP_NAME, "` prop.");
|
|
9
9
|
export var setPropToTrue = "Set `".concat(PROP_NAME, "` prop to `true`.");
|
|
10
|
-
var components =
|
|
10
|
+
var components = {
|
|
11
|
+
'@atlaskit/popup': {
|
|
12
|
+
default: true,
|
|
13
|
+
named: 'Popup'
|
|
14
|
+
},
|
|
15
|
+
'@atlaskit/dropdown-menu': {
|
|
16
|
+
default: true
|
|
17
|
+
},
|
|
18
|
+
'@atlassian/entry-points/dropdown-trigger': {
|
|
19
|
+
default: false,
|
|
20
|
+
named: 'DropdownTrigger'
|
|
21
|
+
},
|
|
22
|
+
'@atlassian/entry-points/popup-trigger': {
|
|
23
|
+
default: false,
|
|
24
|
+
named: 'PopupTrigger'
|
|
25
|
+
}
|
|
26
|
+
};
|
|
11
27
|
var rule = createLintRule({
|
|
12
28
|
meta: {
|
|
13
29
|
name: RULE_NAME,
|
|
@@ -27,11 +43,12 @@ var rule = createLintRule({
|
|
|
27
43
|
var componentLocalName;
|
|
28
44
|
return {
|
|
29
45
|
ImportDeclaration: function ImportDeclaration(node) {
|
|
46
|
+
var _components$source;
|
|
30
47
|
var source = node.source.value;
|
|
31
48
|
if (typeof source !== 'string') {
|
|
32
49
|
return;
|
|
33
50
|
}
|
|
34
|
-
if (!
|
|
51
|
+
if (!(source in components)) {
|
|
35
52
|
return;
|
|
36
53
|
}
|
|
37
54
|
if (!node.specifiers.length) {
|
|
@@ -40,17 +57,23 @@ var rule = createLintRule({
|
|
|
40
57
|
var defaultImport = node.specifiers.filter(function (spec) {
|
|
41
58
|
return spec.type === 'ImportDefaultSpecifier';
|
|
42
59
|
});
|
|
43
|
-
var
|
|
60
|
+
var namedImports = node.specifiers.filter(function (spec) {
|
|
44
61
|
return spec.type === 'ImportSpecifier';
|
|
45
62
|
});
|
|
46
|
-
|
|
47
|
-
// If popup or dropdown menu and using a default import
|
|
48
|
-
if (defaultImport.length && defaultImport[0].local) {
|
|
63
|
+
if (defaultImport.length && defaultImport[0].local && (_components$source = components[source]) !== null && _components$source !== void 0 && _components$source.default) {
|
|
49
64
|
componentLocalName = defaultImport[0].local.name;
|
|
50
|
-
// or if popup and using a named import
|
|
51
|
-
} else if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && 'name' in namedImport[0].imported && namedImport[0].imported.name === 'Popup') {
|
|
52
|
-
componentLocalName = namedImport[0].local.name;
|
|
53
65
|
}
|
|
66
|
+
if (!namedImports.length) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Iterate through all of them, only one should ever be found
|
|
71
|
+
namedImports.forEach(function (namedImport) {
|
|
72
|
+
var _components$source2;
|
|
73
|
+
if (namedImport.type === 'ImportSpecifier' && 'name' in namedImport.imported && namedImport.imported.name === ((_components$source2 = components[source]) === null || _components$source2 === void 0 ? void 0 : _components$source2.named)) {
|
|
74
|
+
componentLocalName = namedImport.local.name;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
54
77
|
},
|
|
55
78
|
JSXElement: function JSXElement(node) {
|
|
56
79
|
if (!isNodeOfType(node, 'JSXElement')) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const AFFECTED_HTML_ELEMENTS: string[];
|
|
2
2
|
export declare const AFFECTED_ATLASKIT_PACKAGES: Record<string, string[]>;
|
|
3
|
-
export declare const UNWANTED_HTML_ATTRIBUTES:
|
|
4
|
-
export declare const UNWANTED_ATLASKIT_ATTRIBUTES:
|
|
3
|
+
export declare const UNWANTED_HTML_ATTRIBUTES: readonly ["disabled", "readonly"];
|
|
4
|
+
export declare const UNWANTED_ATLASKIT_ATTRIBUTES: readonly ["isDisabled", "isReadOnly"];
|
|
5
5
|
declare const rule: import('eslint').Rule.RuleModule;
|
|
6
6
|
export default rule;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export declare const AFFECTED_HTML_ELEMENTS: string[];
|
|
2
2
|
export declare const AFFECTED_ATLASKIT_PACKAGES: Record<string, string[]>;
|
|
3
|
-
export declare const UNWANTED_HTML_ATTRIBUTES:
|
|
4
|
-
|
|
3
|
+
export declare const UNWANTED_HTML_ATTRIBUTES: readonly [
|
|
4
|
+
"disabled",
|
|
5
|
+
"readonly"
|
|
6
|
+
];
|
|
7
|
+
export declare const UNWANTED_ATLASKIT_ATTRIBUTES: readonly [
|
|
8
|
+
"isDisabled",
|
|
9
|
+
"isReadOnly"
|
|
10
|
+
];
|
|
5
11
|
declare const rule: import('eslint').Rule.RuleModule;
|
|
6
12
|
export default rule;
|
package/package.json
CHANGED