@atlaskit/eslint-plugin-ui-styling-standard 0.11.5 → 0.11.6
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 +8 -0
- package/README.md +10 -7
- package/constellation/atlaskit-theme/usage.mdx +113 -0
- package/constellation/convert-props-syntax/usage.mdx +32 -22
- package/constellation/enforce-style-prop/usage.mdx +21 -18
- package/constellation/index/overview.mdx +91 -76
- package/constellation/local-cx-xcss/usage.mdx +10 -6
- package/constellation/no-array-arguments/usage.mdx +10 -9
- package/constellation/no-classname-prop/usage.mdx +7 -4
- package/constellation/no-container-queries/usage.mdx +17 -15
- package/constellation/no-dynamic-styles/usage.mdx +26 -29
- package/constellation/no-exported-styles/usage.mdx +23 -18
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -22
- package/constellation/no-nested-selectors/usage.mdx +22 -20
- package/constellation/no-unsafe-values/usage.mdx +45 -51
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/atlaskit-theme/index.js +89 -0
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +66 -69
- package/src/presets/recommended.codegen.tsx +66 -69
- package/src/rules/atlaskit-theme/README.md +109 -0
- package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
- package/src/rules/atlaskit-theme/index.ts +136 -0
- package/src/rules/index.codegen.tsx +15 -13
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import outdent from 'outdent';
|
|
2
|
+
import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
3
|
+
import rule from '../index';
|
|
4
|
+
|
|
5
|
+
const valid = [
|
|
6
|
+
{
|
|
7
|
+
name: 'Valid typography use in styled-components',
|
|
8
|
+
code: outdent`
|
|
9
|
+
import styled from 'styled-components';
|
|
10
|
+
import { typography } from '@atlaskit/theme';
|
|
11
|
+
export const HeadingComponent = styled.h2\`
|
|
12
|
+
\${typography.h200()};
|
|
13
|
+
\`;
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'Valid elevation use in styled-components',
|
|
18
|
+
code: outdent`
|
|
19
|
+
import styled from 'styled-components';
|
|
20
|
+
import { elevation } from '@atlaskit/theme';
|
|
21
|
+
export const HeadingComponent = styled.h2\`
|
|
22
|
+
\${elevation.e100};
|
|
23
|
+
\`;
|
|
24
|
+
`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Valid skeleton shimmer use in styled-components',
|
|
28
|
+
code: outdent`
|
|
29
|
+
import styled from 'styled-components';
|
|
30
|
+
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
31
|
+
|
|
32
|
+
export const SkeletonShimmerComponent = styled.div\`
|
|
33
|
+
\${skeletonShimmer};
|
|
34
|
+
\`
|
|
35
|
+
`,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const typography = [
|
|
40
|
+
{
|
|
41
|
+
name: 'Invalid typography use in compiled with template expression',
|
|
42
|
+
code: outdent`
|
|
43
|
+
import { styled } from '@compiled/react';
|
|
44
|
+
import { typography } from '@atlaskit/theme';
|
|
45
|
+
|
|
46
|
+
export const HeadingComponent = styled.h2\`
|
|
47
|
+
\${typography.h200()};
|
|
48
|
+
\`;
|
|
49
|
+
`,
|
|
50
|
+
errors: [{ messageId: 'usingTypography' }],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Invalid typography use in compiled with function call',
|
|
54
|
+
code: outdent`
|
|
55
|
+
import { styled } from '@compiled/react';
|
|
56
|
+
import { typography } from '@atlaskit/theme';
|
|
57
|
+
|
|
58
|
+
export const HeadingComponent = styled.h2(typography.h200());
|
|
59
|
+
`,
|
|
60
|
+
errors: [{ messageId: 'usingTypography' }],
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const elevation = [
|
|
65
|
+
{
|
|
66
|
+
name: 'Invalid elevation use in compiled with template expression',
|
|
67
|
+
code: outdent`
|
|
68
|
+
import { styled } from '@compiled/react';
|
|
69
|
+
import { elevation } from '@atlaskit/theme';
|
|
70
|
+
|
|
71
|
+
export const ElevationComponent = styled.div\`
|
|
72
|
+
\${elevation.e100()};
|
|
73
|
+
\`;
|
|
74
|
+
`,
|
|
75
|
+
errors: [{ messageId: 'usingElevation' }],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'Invalid elevation use in compiled with function call',
|
|
79
|
+
code: outdent`
|
|
80
|
+
import { styled } from '@compiled/react';
|
|
81
|
+
import { elevation } from '@atlaskit/theme';
|
|
82
|
+
|
|
83
|
+
export const ElevationComponent = styled.div(elevation.e100());
|
|
84
|
+
`,
|
|
85
|
+
errors: [{ messageId: 'usingElevation' }],
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const skeletonShimmer = [
|
|
90
|
+
{
|
|
91
|
+
name: 'Invalid skeleton shimmer use in compiled with template expression',
|
|
92
|
+
code: outdent`
|
|
93
|
+
import { styled } from '@compiled/react';
|
|
94
|
+
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
95
|
+
|
|
96
|
+
export const SkeletonShimmerComponent = styled.div\`
|
|
97
|
+
\${skeletonShimmer};
|
|
98
|
+
\`;
|
|
99
|
+
`,
|
|
100
|
+
errors: [{ messageId: 'usingSkeletonShimmer' }],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'Invalid skeleton shimmer use in compiled with function call',
|
|
104
|
+
code: outdent`
|
|
105
|
+
import { styled } from '@compiled/react';
|
|
106
|
+
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
107
|
+
|
|
108
|
+
export const SkeletonShimmerComponent = styled.div(skeletonShimmer);
|
|
109
|
+
`,
|
|
110
|
+
errors: [{ messageId: 'usingSkeletonShimmer' }],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
typescriptEslintTester.run(
|
|
115
|
+
'atlaskit-theme',
|
|
116
|
+
// @ts-expect-error
|
|
117
|
+
rule,
|
|
118
|
+
{
|
|
119
|
+
valid,
|
|
120
|
+
invalid: [...typography, ...elevation, ...skeletonShimmer],
|
|
121
|
+
},
|
|
122
|
+
);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Rule, Scope } from 'eslint';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getImportSources,
|
|
5
|
+
isCompiled,
|
|
6
|
+
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
|
+
import { createLintRule } from '../utils/create-rule';
|
|
8
|
+
|
|
9
|
+
const isIdentifierReferenced = (
|
|
10
|
+
hasImportSpecifier: (def: Scope.Definition) => boolean,
|
|
11
|
+
node: Rule.Node,
|
|
12
|
+
references: Scope.Reference[],
|
|
13
|
+
): boolean =>
|
|
14
|
+
references.some(
|
|
15
|
+
(reference) =>
|
|
16
|
+
reference.identifier === node &&
|
|
17
|
+
reference.resolved?.defs.some(hasImportSpecifier),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const isTypographyImportSpecifier = (def: Scope.Definition): boolean =>
|
|
21
|
+
def.node.type === 'ImportSpecifier' &&
|
|
22
|
+
def.node.imported.type === 'Identifier' &&
|
|
23
|
+
def.parent?.type === 'ImportDeclaration' &&
|
|
24
|
+
((def.node.imported.name === 'typography' &&
|
|
25
|
+
def.parent?.source.value === '@atlaskit/theme') ||
|
|
26
|
+
def.parent?.source.value === '@atlaskit/theme/typography');
|
|
27
|
+
|
|
28
|
+
const isElevationImportSpecifier = (def: Scope.Definition): boolean =>
|
|
29
|
+
def.node.type === 'ImportSpecifier' &&
|
|
30
|
+
def.node.imported.type === 'Identifier' &&
|
|
31
|
+
def.parent?.type === 'ImportDeclaration' &&
|
|
32
|
+
((def.node.imported.name === 'elevation' &&
|
|
33
|
+
def.parent?.source.value === '@atlaskit/theme') ||
|
|
34
|
+
def.parent?.source.value === '@atlaskit/theme/elevation');
|
|
35
|
+
|
|
36
|
+
const isSkeletonShimmerImportSpecifier = (def: Scope.Definition): boolean =>
|
|
37
|
+
def.node.type === 'ImportSpecifier' &&
|
|
38
|
+
def.node.imported.type === 'Identifier' &&
|
|
39
|
+
def.parent?.type === 'ImportDeclaration' &&
|
|
40
|
+
def.node.imported.name === 'skeletonShimmer' &&
|
|
41
|
+
typeof def.parent?.source.value === 'string' &&
|
|
42
|
+
def.parent?.source.value?.startsWith('@atlaskit/theme');
|
|
43
|
+
|
|
44
|
+
const checkIdentifier = (
|
|
45
|
+
node: Rule.Node,
|
|
46
|
+
context: Rule.RuleContext,
|
|
47
|
+
references: Scope.Reference[],
|
|
48
|
+
) => {
|
|
49
|
+
if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
|
|
50
|
+
context.report({
|
|
51
|
+
messageId: 'usingTypography',
|
|
52
|
+
node,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
|
|
57
|
+
context.report({
|
|
58
|
+
messageId: 'usingElevation',
|
|
59
|
+
node,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)
|
|
65
|
+
) {
|
|
66
|
+
context.report({
|
|
67
|
+
messageId: 'usingSkeletonShimmer',
|
|
68
|
+
node,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const rule = createLintRule({
|
|
74
|
+
meta: {
|
|
75
|
+
name: 'atlaskit-theme',
|
|
76
|
+
docs: {
|
|
77
|
+
description:
|
|
78
|
+
'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
|
|
79
|
+
recommended: true,
|
|
80
|
+
severity: 'error',
|
|
81
|
+
},
|
|
82
|
+
messages: {
|
|
83
|
+
usingTypography:
|
|
84
|
+
'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
85
|
+
usingElevation:
|
|
86
|
+
'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
87
|
+
usingSkeletonShimmer:
|
|
88
|
+
'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
89
|
+
},
|
|
90
|
+
schema: [],
|
|
91
|
+
type: 'problem',
|
|
92
|
+
},
|
|
93
|
+
create(context) {
|
|
94
|
+
const importSources = getImportSources(context);
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
'CallExpression Identifier': (node: Rule.Node): void => {
|
|
98
|
+
const { references } = context.getScope();
|
|
99
|
+
const ancestors = context.getAncestors();
|
|
100
|
+
|
|
101
|
+
// Check if ancestor node is a call expression to Compiled
|
|
102
|
+
if (
|
|
103
|
+
ancestors.some(
|
|
104
|
+
(ancestor) =>
|
|
105
|
+
ancestor.type === 'CallExpression' &&
|
|
106
|
+
ancestor.callee &&
|
|
107
|
+
isCompiled(ancestor.callee, references, importSources),
|
|
108
|
+
)
|
|
109
|
+
) {
|
|
110
|
+
// Check identifier for violations
|
|
111
|
+
checkIdentifier(node, context, references);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
'TaggedTemplateExpression Identifier': (node: Rule.Node): void => {
|
|
116
|
+
const { references } = context.getScope();
|
|
117
|
+
const ancestors = context.getAncestors();
|
|
118
|
+
|
|
119
|
+
// Check if ancestor node is a tagged template expression to Compiled
|
|
120
|
+
if (
|
|
121
|
+
ancestors.some(
|
|
122
|
+
(ancestor) =>
|
|
123
|
+
ancestor.type === 'TaggedTemplateExpression' &&
|
|
124
|
+
ancestor.tag &&
|
|
125
|
+
isCompiled(ancestor.tag, references, importSources),
|
|
126
|
+
)
|
|
127
|
+
) {
|
|
128
|
+
// Check identifier for violations
|
|
129
|
+
checkIdentifier(node, context, references);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export default rule;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::78ffc29d20fd2fe3727a620cb4ddf192>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
|
+
import atlaskitTheme from './atlaskit-theme';
|
|
6
7
|
import convertPropsSyntax from './convert-props-syntax';
|
|
7
8
|
import enforceStyleProp from './enforce-style-prop';
|
|
8
9
|
import localCxXcss from './local-cx-xcss';
|
|
@@ -17,16 +18,17 @@ import noNestedSelectors from './no-nested-selectors';
|
|
|
17
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
18
19
|
|
|
19
20
|
export default {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
'atlaskit-theme': atlaskitTheme,
|
|
22
|
+
'convert-props-syntax': convertPropsSyntax,
|
|
23
|
+
'enforce-style-prop': enforceStyleProp,
|
|
24
|
+
'local-cx-xcss': localCxXcss,
|
|
25
|
+
'no-array-arguments': noArrayArguments,
|
|
26
|
+
'no-classname-prop': noClassnameProp,
|
|
27
|
+
'no-container-queries': noContainerQueries,
|
|
28
|
+
'no-dynamic-styles': noDynamicStyles,
|
|
29
|
+
'no-exported-styles': noExportedStyles,
|
|
30
|
+
'no-important-styles': noImportantStyles,
|
|
31
|
+
'no-imported-style-values': noImportedStyleValues,
|
|
32
|
+
'no-nested-selectors': noNestedSelectors,
|
|
33
|
+
'no-unsafe-values': noUnsafeValues,
|
|
32
34
|
};
|