@atlaskit/eslint-plugin-design-system 13.5.0 → 13.7.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 +22 -0
- package/README.md +2 -0
- package/dist/cjs/presets/all-flat.codegen.js +3 -1
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended-flat.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
- package/dist/cjs/rules/no-html-button/node-types/styled-component/index.js +2 -2
- package/dist/cjs/rules/no-html-checkbox/index.js +34 -0
- package/dist/cjs/rules/no-html-checkbox/node-types/index.js +12 -0
- package/dist/cjs/rules/no-html-checkbox/node-types/jsx-element/index.js +27 -0
- package/dist/cjs/rules/no-html-checkbox/node-types/supported.js +70 -0
- package/dist/cjs/rules/no-html-image/index.js +40 -0
- package/dist/cjs/rules/no-html-image/node-types/index.js +19 -0
- package/dist/cjs/rules/no-html-image/node-types/jsx-element/index.js +115 -0
- package/dist/cjs/rules/no-html-image/node-types/styled-component/index.js +42 -0
- package/dist/cjs/rules/no-html-image/node-types/supported.js +72 -0
- package/dist/cjs/rules/{no-html-anchor/node-types/styled-component → utils}/get-styled-component-call.js +1 -1
- package/dist/es2019/presets/all-flat.codegen.js +3 -1
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended-flat.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
- package/dist/es2019/rules/no-html-button/node-types/styled-component/index.js +2 -2
- package/dist/es2019/rules/no-html-checkbox/index.js +28 -0
- package/dist/es2019/rules/no-html-checkbox/node-types/index.js +1 -0
- package/dist/es2019/rules/no-html-checkbox/node-types/jsx-element/index.js +19 -0
- package/dist/es2019/rules/no-html-checkbox/node-types/supported.js +60 -0
- package/dist/es2019/rules/no-html-image/index.js +34 -0
- package/dist/es2019/rules/no-html-image/node-types/index.js +2 -0
- package/dist/es2019/rules/no-html-image/node-types/jsx-element/index.js +80 -0
- package/dist/es2019/rules/no-html-image/node-types/styled-component/index.js +37 -0
- package/dist/es2019/rules/no-html-image/node-types/supported.js +62 -0
- package/dist/es2019/rules/{no-html-anchor/node-types/styled-component → utils}/get-styled-component-call.js +1 -1
- package/dist/esm/presets/all-flat.codegen.js +3 -1
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended-flat.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
- package/dist/esm/rules/no-html-button/node-types/styled-component/index.js +2 -2
- package/dist/esm/rules/no-html-checkbox/index.js +28 -0
- package/dist/esm/rules/no-html-checkbox/node-types/index.js +1 -0
- package/dist/esm/rules/no-html-checkbox/node-types/jsx-element/index.js +18 -0
- package/dist/esm/rules/no-html-checkbox/node-types/supported.js +61 -0
- package/dist/esm/rules/no-html-image/index.js +34 -0
- package/dist/esm/rules/no-html-image/node-types/index.js +2 -0
- package/dist/esm/rules/no-html-image/node-types/jsx-element/index.js +106 -0
- package/dist/esm/rules/no-html-image/node-types/styled-component/index.js +36 -0
- package/dist/esm/rules/no-html-image/node-types/supported.js +63 -0
- package/dist/esm/rules/{no-html-button/node-types/styled-component → utils}/get-styled-component-call.js +1 -1
- package/dist/types/index.codegen.d.ts +18 -0
- package/dist/types/presets/all-flat.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -0
- package/dist/types/presets/recommended-flat.codegen.d.ts +2 -0
- package/dist/types/presets/recommended.codegen.d.ts +2 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-html-checkbox/index.d.ts +3 -0
- package/dist/types/rules/no-html-checkbox/node-types/index.d.ts +1 -0
- package/dist/types/rules/no-html-checkbox/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types/rules/no-html-checkbox/node-types/supported.d.ts +7 -0
- package/dist/types/rules/no-html-image/index.d.ts +3 -0
- package/dist/types/rules/no-html-image/node-types/index.d.ts +2 -0
- package/dist/types/rules/no-html-image/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types/rules/no-html-image/node-types/styled-component/index.d.ts +8 -0
- package/dist/types/rules/no-html-image/node-types/supported.d.ts +7 -0
- package/dist/types-ts4.5/index.codegen.d.ts +18 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-html-checkbox/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-html-checkbox/node-types/index.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-html-checkbox/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-checkbox/node-types/supported.d.ts +7 -0
- package/dist/types-ts4.5/rules/no-html-image/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-html-image/node-types/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-html-image/node-types/jsx-element/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-image/node-types/styled-component/index.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-html-image/node-types/supported.d.ts +7 -0
- package/package.json +2 -2
- package/dist/cjs/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +0 -47
- package/dist/es2019/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +0 -42
- package/dist/esm/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +0 -42
- package/dist/types/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.d.ts +0 -6
- package/dist/types/rules/no-html-button/node-types/styled-component/get-styled-component-call.d.ts +0 -6
- /package/dist/cjs/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
- /package/dist/cjs/rules/{no-html-button/utils → utils}/get-jsx-element-by-name.js +0 -0
- /package/dist/es2019/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
- /package/dist/es2019/rules/{no-html-button/utils → utils}/get-jsx-element-by-name.js +0 -0
- /package/dist/esm/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
- /package/dist/esm/rules/{no-html-button/utils → utils}/get-jsx-element-by-name.js +0 -0
- /package/dist/types/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.d.ts +0 -0
- /package/dist/types/rules/{no-html-button/utils → utils}/get-jsx-element-by-name.d.ts +0 -0
- /package/dist/{types-ts4.5/rules/no-html-button/node-types/styled-component → types/rules/utils}/get-styled-component-call.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-html-button/utils → utils}/get-jsx-element-by-name.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-html-anchor/node-types/styled-component → utils}/get-styled-component-call.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::08dc1cc7cbbf7112f2f5733f57a9e2b1>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -23,6 +23,8 @@ export default {
|
|
|
23
23
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
24
24
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
25
25
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
26
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
27
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
26
28
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
27
29
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
28
30
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::81564fd37c062c0be3a14ca6ea1e4271>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,6 +19,8 @@ export default {
|
|
|
19
19
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
20
20
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
21
21
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
23
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
22
24
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
23
25
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
24
26
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::175936d329524b99169a5dc943011231>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -18,6 +18,8 @@ export default {
|
|
|
18
18
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
19
19
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
20
20
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
21
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
21
23
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
22
24
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
23
25
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::3cefc1b277e5c633caf1fd4491d60d94>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import consistentCssPropUsage from './consistent-css-prop-usage';
|
|
@@ -22,6 +22,8 @@ import noExportedCss from './no-exported-css';
|
|
|
22
22
|
import noExportedKeyframes from './no-exported-keyframes';
|
|
23
23
|
import noHtmlAnchor from './no-html-anchor';
|
|
24
24
|
import noHtmlButton from './no-html-button';
|
|
25
|
+
import noHtmlCheckbox from './no-html-checkbox';
|
|
26
|
+
import noHtmlImage from './no-html-image';
|
|
25
27
|
import noInvalidCssMap from './no-invalid-css-map';
|
|
26
28
|
import noKeyframesTaggedTemplateExpression from './no-keyframes-tagged-template-expression';
|
|
27
29
|
import noLegacyIcons from './no-legacy-icons';
|
|
@@ -74,6 +76,8 @@ export const rules = {
|
|
|
74
76
|
'no-exported-keyframes': noExportedKeyframes,
|
|
75
77
|
'no-html-anchor': noHtmlAnchor,
|
|
76
78
|
'no-html-button': noHtmlButton,
|
|
79
|
+
'no-html-checkbox': noHtmlCheckbox,
|
|
80
|
+
'no-html-image': noHtmlImage,
|
|
77
81
|
'no-invalid-css-map': noInvalidCssMap,
|
|
78
82
|
'no-keyframes-tagged-template-expression': noKeyframesTaggedTemplateExpression,
|
|
79
83
|
'no-legacy-icons': noLegacyIcons,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
-
import { getJsxElementByName } from '
|
|
5
|
+
import { getJsxElementByName } from '../../../utils/get-jsx-element-by-name';
|
|
6
|
+
import { getStyledComponentCall } from '../../../utils/get-styled-component-call';
|
|
6
7
|
import { isSupportedForLint } from '../supported';
|
|
7
|
-
import { getStyledComponentCall } from './get-styled-component-call';
|
|
8
8
|
export const StyledComponent = {
|
|
9
9
|
lint(node, {
|
|
10
10
|
context
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
-
import { getJsxElementByName } from '
|
|
5
|
+
import { getJsxElementByName } from '../../../utils/get-jsx-element-by-name';
|
|
6
|
+
import { getStyledComponentCall } from '../../../utils/get-styled-component-call';
|
|
6
7
|
import { isSupportedForLint } from '../supported';
|
|
7
|
-
import { getStyledComponentCall } from './get-styled-component-call';
|
|
8
8
|
export const StyledComponent = {
|
|
9
9
|
lint(node, {
|
|
10
10
|
context
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { JSXElement } from './node-types';
|
|
3
|
+
const rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-html-checkbox',
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
hasSuggestions: true,
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Discourage direct usage of HTML checkbox elements in favor of the Atlassian Design System checkbox component.',
|
|
10
|
+
recommended: true,
|
|
11
|
+
severity: 'warn'
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noHtmlCheckbox: `This <{{ name }}> should be replaced with a checkbox component from the Atlassian Design System. ADS components include event tracking, ensure accessible implementations, and provide access to ADS styling features like design tokens.`
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
// transforms <input type="checkbox" css={...}> usages
|
|
20
|
+
JSXElement(node) {
|
|
21
|
+
JSXElement.lint(node, {
|
|
22
|
+
context
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export default rule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { JSXElement } from './jsx-element';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as ast from '../../../../ast-nodes';
|
|
2
|
+
import { isSupportedForLint } from '../supported';
|
|
3
|
+
export const JSXElement = {
|
|
4
|
+
lint(node, {
|
|
5
|
+
context
|
|
6
|
+
}) {
|
|
7
|
+
if (!isSupportedForLint(node)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const nodeName = ast.JSXElement.getName(node);
|
|
11
|
+
context.report({
|
|
12
|
+
node: node.openingElement,
|
|
13
|
+
messageId: 'noHtmlCheckbox',
|
|
14
|
+
data: {
|
|
15
|
+
name: nodeName
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../ast-nodes';
|
|
3
|
+
const supportedElements = [{
|
|
4
|
+
name: 'input',
|
|
5
|
+
attributes: [{
|
|
6
|
+
name: 'type',
|
|
7
|
+
values: ['checkbox']
|
|
8
|
+
}]
|
|
9
|
+
}];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the given JSX element is a supported element to lint with this rule.
|
|
13
|
+
*/
|
|
14
|
+
export function isSupportedForLint(jsxNode, elementName) {
|
|
15
|
+
if (!isNodeOfType(jsxNode, 'JSXElement')) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Allow passing in the element name because the jsxNode doesn't
|
|
20
|
+
// represent the element name with styled components
|
|
21
|
+
const elName = elementName || ast.JSXElement.getName(jsxNode);
|
|
22
|
+
if (!elName) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Only check native HTML elements, not components
|
|
27
|
+
if (elName[0] !== elName[0].toLowerCase()) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
let supportedElement = supportedElements.find(({
|
|
31
|
+
name
|
|
32
|
+
}) => name === elName);
|
|
33
|
+
if (!supportedElement) {
|
|
34
|
+
supportedElement = supportedElements.find(({
|
|
35
|
+
name
|
|
36
|
+
}) => name === '*');
|
|
37
|
+
}
|
|
38
|
+
if (!supportedElement) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Check if the element has any attributes that are not supported
|
|
43
|
+
const attributes = ast.JSXElement.getAttributes(jsxNode);
|
|
44
|
+
if (supportedElement.attributes && !supportedElement.attributes.every(({
|
|
45
|
+
name,
|
|
46
|
+
values
|
|
47
|
+
}) => {
|
|
48
|
+
return attributes.some(attribute => {
|
|
49
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const isMatchingName = attribute.name.name === name;
|
|
53
|
+
const isMatchingValues = values && attribute.value && attribute.value.type === 'Literal' && typeof attribute.value.value === 'string' && (values === null || values === void 0 ? void 0 : values.includes(attribute.value.value));
|
|
54
|
+
return isMatchingName && isMatchingValues;
|
|
55
|
+
});
|
|
56
|
+
})) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { JSXElement, StyledComponent } from './node-types';
|
|
3
|
+
const rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-html-image',
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
hasSuggestions: true,
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Discourage direct usage of HTML image elements in favor of the Atlassian Design System image component.',
|
|
10
|
+
recommended: true,
|
|
11
|
+
severity: 'warn'
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noHtmlImage: `This <{{ name }}> should be replaced with the image component from the Atlassian Design System. ADS images ensure accessible implementations, and provide access to ADS styling features like design tokens.`
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
// transforms styled.<anchor>(...) usages
|
|
20
|
+
CallExpression(node) {
|
|
21
|
+
StyledComponent.lint(node, {
|
|
22
|
+
context
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
// transforms <anchor css={...}> usages
|
|
26
|
+
JSXElement(node) {
|
|
27
|
+
JSXElement.lint(node, {
|
|
28
|
+
context
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
export default rule;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
|
+
import * as ast from '../../../../ast-nodes';
|
|
4
|
+
import { isSupportedForLint } from '../supported';
|
|
5
|
+
function isImportDeclaration(node) {
|
|
6
|
+
return node.type === 'ImportDeclaration';
|
|
7
|
+
}
|
|
8
|
+
export const JSXElement = {
|
|
9
|
+
lint(node, {
|
|
10
|
+
context
|
|
11
|
+
}) {
|
|
12
|
+
if (!isSupportedForLint(node)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const nodeName = ast.JSXElement.getName(node);
|
|
16
|
+
const sourceCode = getSourceCode(context);
|
|
17
|
+
const importDeclarations = sourceCode.ast.body.filter(isImportDeclaration);
|
|
18
|
+
let existingImageName = null;
|
|
19
|
+
const usedNames = new Set();
|
|
20
|
+
|
|
21
|
+
// Check for existing imports
|
|
22
|
+
for (const declaration of importDeclarations) {
|
|
23
|
+
for (const specifier of declaration.specifiers) {
|
|
24
|
+
usedNames.add(specifier.local.name);
|
|
25
|
+
}
|
|
26
|
+
if (declaration.source.value === '@atlaskit/image') {
|
|
27
|
+
const defaultSpecifier = declaration.specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier');
|
|
28
|
+
if (defaultSpecifier) {
|
|
29
|
+
existingImageName = defaultSpecifier.local.name;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const generateUniqueName = baseName => {
|
|
34
|
+
let index = 1;
|
|
35
|
+
let newName = baseName;
|
|
36
|
+
while (usedNames.has(newName)) {
|
|
37
|
+
newName = `${baseName}${index}`;
|
|
38
|
+
index++;
|
|
39
|
+
}
|
|
40
|
+
return newName;
|
|
41
|
+
};
|
|
42
|
+
const imageName = existingImageName || generateUniqueName('Image');
|
|
43
|
+
context.report({
|
|
44
|
+
node: node.openingElement,
|
|
45
|
+
messageId: 'noHtmlImage',
|
|
46
|
+
data: {
|
|
47
|
+
name: nodeName
|
|
48
|
+
},
|
|
49
|
+
suggest: [{
|
|
50
|
+
desc: 'Replace with Image component from @atlaskit/image',
|
|
51
|
+
fix(fixer) {
|
|
52
|
+
var _node$closingElement;
|
|
53
|
+
const openingTagRange = node.openingElement.range;
|
|
54
|
+
const closingTagRange = (_node$closingElement = node.closingElement) === null || _node$closingElement === void 0 ? void 0 : _node$closingElement.range;
|
|
55
|
+
const attributesText = node.openingElement.attributes.filter(attr => !isNodeOfType(attr, 'JSXAttribute') || attr.name.name !== 'role').map(attr => sourceCode.getText(attr)).join(' ');
|
|
56
|
+
const fixers = [];
|
|
57
|
+
|
|
58
|
+
// Replace <img> with <Image> and retain attributes
|
|
59
|
+
if (openingTagRange) {
|
|
60
|
+
if (node.openingElement.selfClosing) {
|
|
61
|
+
fixers.push(fixer.replaceTextRange([openingTagRange[0] + 1, openingTagRange[1] - 1], `${imageName}${attributesText ? ` ${attributesText}` : ''} /`));
|
|
62
|
+
} else {
|
|
63
|
+
fixers.push(fixer.replaceTextRange([openingTagRange[0] + 1, openingTagRange[1] - 1], `${imageName}${attributesText ? ` ${attributesText}` : ''}`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (closingTagRange && !node.openingElement.selfClosing) {
|
|
67
|
+
fixers.push(fixer.replaceTextRange([closingTagRange[0] + 2, closingTagRange[1] - 1], imageName));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Add import if not present
|
|
71
|
+
if (!existingImageName) {
|
|
72
|
+
const importStatement = `import ${imageName} from '@atlaskit/image';\n`;
|
|
73
|
+
fixers.push(fixer.insertTextBefore(sourceCode.ast, importStatement));
|
|
74
|
+
}
|
|
75
|
+
return fixers;
|
|
76
|
+
}
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
2
|
+
|
|
3
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
+
import { getStyledComponentCall } from '../../../utils/get-styled-component-call';
|
|
6
|
+
import { getJsxElementByName } from '../../utils/get-jsx-element-by-name';
|
|
7
|
+
import { isSupportedForLint } from '../supported';
|
|
8
|
+
export const StyledComponent = {
|
|
9
|
+
lint(node, {
|
|
10
|
+
context
|
|
11
|
+
}) {
|
|
12
|
+
var _getJsxElementByName;
|
|
13
|
+
if (!isNodeOfType(node, 'CallExpression') || !isNodeOfType(node.callee, 'MemberExpression') || !isNodeOfType(node.callee.object, 'Identifier') || !isNodeOfType(node.callee.property, 'Identifier')) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const styles = getStyledComponentCall(node);
|
|
17
|
+
const elementName = node.callee.property.name;
|
|
18
|
+
if (!styles || !isNodeOfType(styles.id, 'Identifier')) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const jsxElement = (_getJsxElementByName = getJsxElementByName(styles.id.name, getScope(context, node))) === null || _getJsxElementByName === void 0 ? void 0 : _getJsxElementByName.parent;
|
|
22
|
+
if (!jsxElement) {
|
|
23
|
+
// If there's no JSX element, we can't determine if it's being used as an image or not
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (jsxElement && !isSupportedForLint(jsxElement, elementName)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
context.report({
|
|
30
|
+
node: styles,
|
|
31
|
+
messageId: 'noHtmlImage',
|
|
32
|
+
data: {
|
|
33
|
+
name: node.callee.property.name
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../ast-nodes';
|
|
3
|
+
const supportedElements = [{
|
|
4
|
+
name: 'img'
|
|
5
|
+
}, {
|
|
6
|
+
name: '*',
|
|
7
|
+
attributes: [{
|
|
8
|
+
name: 'role',
|
|
9
|
+
values: ['img']
|
|
10
|
+
}]
|
|
11
|
+
}];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the given JSX element is a supported element to lint with this rule.
|
|
15
|
+
*/
|
|
16
|
+
export function isSupportedForLint(jsxNode, elementName) {
|
|
17
|
+
if (!isNodeOfType(jsxNode, 'JSXElement')) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Allow passing in the element name because the jsxNode doesn't
|
|
22
|
+
// represent the element name with styled components
|
|
23
|
+
const elName = elementName || ast.JSXElement.getName(jsxNode);
|
|
24
|
+
if (!elName) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Only check native HTML elements, not components
|
|
29
|
+
if (elName[0] !== elName[0].toLowerCase()) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
let supportedElement = supportedElements.find(({
|
|
33
|
+
name
|
|
34
|
+
}) => name === elName);
|
|
35
|
+
if (!supportedElement) {
|
|
36
|
+
supportedElement = supportedElements.find(({
|
|
37
|
+
name
|
|
38
|
+
}) => name === '*');
|
|
39
|
+
}
|
|
40
|
+
if (!supportedElement) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check if the element has any attributes that are not supported
|
|
45
|
+
const attributes = ast.JSXElement.getAttributes(jsxNode);
|
|
46
|
+
if (supportedElement.attributes && !supportedElement.attributes.every(({
|
|
47
|
+
name,
|
|
48
|
+
values
|
|
49
|
+
}) => {
|
|
50
|
+
return attributes.some(attribute => {
|
|
51
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const isMatchingName = attribute.name.name === name;
|
|
55
|
+
const isMatchingValues = values && attribute.value && attribute.value.type === 'Literal' && typeof attribute.value.value === 'string' && (values === null || values === void 0 ? void 0 : values.includes(attribute.value.value));
|
|
56
|
+
return isMatchingName && isMatchingValues;
|
|
57
|
+
});
|
|
58
|
+
})) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
@@ -23,7 +23,7 @@ export const getStyledComponentCall = node => {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Some verbose precondition checks but all it does is check
|
|
26
|
-
* a call expression is of form `styled
|
|
26
|
+
* a call expression is of form `styled.<element>` or `styled2.<element>`
|
|
27
27
|
*/
|
|
28
28
|
const isStyledCallExpression = call => {
|
|
29
29
|
if (!isNodeOfType(call, 'CallExpression')) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::9a179b7d6c19d5c7eafde6b3ae40233b>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -24,6 +24,8 @@ export default {
|
|
|
24
24
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
25
25
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
26
26
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
27
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
28
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
27
29
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
28
30
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
29
31
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::08dc1cc7cbbf7112f2f5733f57a9e2b1>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -23,6 +23,8 @@ export default {
|
|
|
23
23
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
24
24
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
25
25
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
26
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
27
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
26
28
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
27
29
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
28
30
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::81564fd37c062c0be3a14ca6ea1e4271>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,6 +19,8 @@ export default {
|
|
|
19
19
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
20
20
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
21
21
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
23
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
22
24
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
23
25
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
24
26
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::175936d329524b99169a5dc943011231>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -18,6 +18,8 @@ export default {
|
|
|
18
18
|
'@atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop': 'error',
|
|
19
19
|
'@atlaskit/design-system/no-html-anchor': 'warn',
|
|
20
20
|
'@atlaskit/design-system/no-html-button': 'warn',
|
|
21
|
+
'@atlaskit/design-system/no-html-checkbox': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-html-image': 'warn',
|
|
21
23
|
'@atlaskit/design-system/no-invalid-css-map': ['error', {
|
|
22
24
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
23
25
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::3cefc1b277e5c633caf1fd4491d60d94>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import consistentCssPropUsage from './consistent-css-prop-usage';
|
|
@@ -22,6 +22,8 @@ import noExportedCss from './no-exported-css';
|
|
|
22
22
|
import noExportedKeyframes from './no-exported-keyframes';
|
|
23
23
|
import noHtmlAnchor from './no-html-anchor';
|
|
24
24
|
import noHtmlButton from './no-html-button';
|
|
25
|
+
import noHtmlCheckbox from './no-html-checkbox';
|
|
26
|
+
import noHtmlImage from './no-html-image';
|
|
25
27
|
import noInvalidCssMap from './no-invalid-css-map';
|
|
26
28
|
import noKeyframesTaggedTemplateExpression from './no-keyframes-tagged-template-expression';
|
|
27
29
|
import noLegacyIcons from './no-legacy-icons';
|
|
@@ -74,6 +76,8 @@ export var rules = {
|
|
|
74
76
|
'no-exported-keyframes': noExportedKeyframes,
|
|
75
77
|
'no-html-anchor': noHtmlAnchor,
|
|
76
78
|
'no-html-button': noHtmlButton,
|
|
79
|
+
'no-html-checkbox': noHtmlCheckbox,
|
|
80
|
+
'no-html-image': noHtmlImage,
|
|
77
81
|
'no-invalid-css-map': noInvalidCssMap,
|
|
78
82
|
'no-keyframes-tagged-template-expression': noKeyframesTaggedTemplateExpression,
|
|
79
83
|
'no-legacy-icons': noLegacyIcons,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
-
import { getJsxElementByName } from '
|
|
5
|
+
import { getJsxElementByName } from '../../../utils/get-jsx-element-by-name';
|
|
6
|
+
import { getStyledComponentCall } from '../../../utils/get-styled-component-call';
|
|
6
7
|
import { isSupportedForLint } from '../supported';
|
|
7
|
-
import { getStyledComponentCall } from './get-styled-component-call';
|
|
8
8
|
export var StyledComponent = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var _getJsxElementByName;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
|
-
import { getJsxElementByName } from '
|
|
5
|
+
import { getJsxElementByName } from '../../../utils/get-jsx-element-by-name';
|
|
6
|
+
import { getStyledComponentCall } from '../../../utils/get-styled-component-call';
|
|
6
7
|
import { isSupportedForLint } from '../supported';
|
|
7
|
-
import { getStyledComponentCall } from './get-styled-component-call';
|
|
8
8
|
export var StyledComponent = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
10
|
var _getJsxElementByName;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { JSXElement as _JSXElement } from './node-types';
|
|
3
|
+
var rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-html-checkbox',
|
|
6
|
+
type: 'suggestion',
|
|
7
|
+
hasSuggestions: true,
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Discourage direct usage of HTML checkbox elements in favor of the Atlassian Design System checkbox component.',
|
|
10
|
+
recommended: true,
|
|
11
|
+
severity: 'warn'
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noHtmlCheckbox: "This <{{ name }}> should be replaced with a checkbox component from the Atlassian Design System. ADS components include event tracking, ensure accessible implementations, and provide access to ADS styling features like design tokens."
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
create: function create(context) {
|
|
18
|
+
return {
|
|
19
|
+
// transforms <input type="checkbox" css={...}> usages
|
|
20
|
+
JSXElement: function JSXElement(node) {
|
|
21
|
+
_JSXElement.lint(node, {
|
|
22
|
+
context: context
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export default rule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { JSXElement } from './jsx-element';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as ast from '../../../../ast-nodes';
|
|
2
|
+
import { isSupportedForLint } from '../supported';
|
|
3
|
+
export var JSXElement = {
|
|
4
|
+
lint: function lint(node, _ref) {
|
|
5
|
+
var context = _ref.context;
|
|
6
|
+
if (!isSupportedForLint(node)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
var nodeName = ast.JSXElement.getName(node);
|
|
10
|
+
context.report({
|
|
11
|
+
node: node.openingElement,
|
|
12
|
+
messageId: 'noHtmlCheckbox',
|
|
13
|
+
data: {
|
|
14
|
+
name: nodeName
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|