@atlaskit/eslint-plugin-ui-styling-standard 0.17.0 → 0.18.1

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/presets/all.codegen.js +3 -2
  3. package/dist/cjs/presets/recommended.codegen.js +3 -2
  4. package/dist/cjs/rules/external-rules.js +3 -1
  5. package/dist/es2019/presets/all.codegen.js +3 -2
  6. package/dist/es2019/presets/recommended.codegen.js +3 -2
  7. package/dist/es2019/rules/external-rules.js +3 -1
  8. package/dist/esm/presets/all.codegen.js +3 -2
  9. package/dist/esm/presets/recommended.codegen.js +3 -2
  10. package/dist/esm/rules/external-rules.js +3 -1
  11. package/dist/types/index.codegen.d.ts +2 -0
  12. package/dist/types/presets/all.codegen.d.ts +2 -1
  13. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  14. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  15. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  16. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  17. package/package.json +2 -2
  18. package/afm-cc/tsconfig.json +0 -28
  19. package/afm-jira/tsconfig.json +0 -28
  20. package/build/tsconfig.json +0 -18
  21. package/constellation/atlaskit-theme/usage.mdx +0 -132
  22. package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
  23. package/constellation/convert-props-syntax/usage.mdx +0 -130
  24. package/constellation/enforce-style-prop/usage.mdx +0 -47
  25. package/constellation/index/migration-guide.mdx +0 -309
  26. package/constellation/index/overview.mdx +0 -250
  27. package/constellation/index/props.mdx +0 -30
  28. package/constellation/local-cx-xcss/usage.mdx +0 -53
  29. package/constellation/no-array-arguments/usage.mdx +0 -49
  30. package/constellation/no-classname-prop/usage.mdx +0 -49
  31. package/constellation/no-container-queries/usage.mdx +0 -101
  32. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
  33. package/constellation/no-dynamic-styles/usage.mdx +0 -130
  34. package/constellation/no-empty-styled-expression/usage.mdx +0 -8
  35. package/constellation/no-exported-css/usage.mdx +0 -8
  36. package/constellation/no-exported-keyframes/usage.mdx +0 -8
  37. package/constellation/no-exported-styles/usage.mdx +0 -87
  38. package/constellation/no-global-styles/usage.mdx +0 -60
  39. package/constellation/no-important-styles/usage.mdx +0 -33
  40. package/constellation/no-imported-style-values/usage.mdx +0 -157
  41. package/constellation/no-invalid-css-map/usage.mdx +0 -8
  42. package/constellation/no-js-xcss/usage.mdx +0 -7
  43. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
  44. package/constellation/no-nested-selectors/usage.mdx +0 -95
  45. package/constellation/no-styled/usage.mdx +0 -92
  46. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
  47. package/constellation/no-suppress-xcss/usage.mdx +0 -28
  48. package/constellation/no-unsafe-selectors/usage.mdx +0 -370
  49. package/constellation/no-unsafe-values/usage.mdx +0 -318
  50. package/constellation/use-compiled/usage.mdx +0 -54
  51. package/index.js +0 -24
  52. package/scripts/codegen.tsx +0 -373
  53. package/src/index.codegen.tsx +0 -14
  54. package/src/index.tsx +0 -1
  55. package/src/presets/all.codegen.tsx +0 -79
  56. package/src/presets/recommended.codegen.tsx +0 -79
  57. package/src/rules/TEMPLATE.md +0 -29
  58. package/src/rules/__tests__/utils/_tester.tsx +0 -40
  59. package/src/rules/atlaskit-theme/README.md +0 -130
  60. package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
  61. package/src/rules/atlaskit-theme/index.ts +0 -134
  62. package/src/rules/convert-props-syntax/README.md +0 -128
  63. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
  64. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
  65. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
  66. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
  67. package/src/rules/convert-props-syntax/index.tsx +0 -414
  68. package/src/rules/enforce-style-prop/README.md +0 -45
  69. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
  70. package/src/rules/enforce-style-prop/index.tsx +0 -172
  71. package/src/rules/external-rules.tsx +0 -175
  72. package/src/rules/index.codegen.tsx +0 -42
  73. package/src/rules/local-cx-xcss/README.md +0 -51
  74. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
  75. package/src/rules/local-cx-xcss/index.tsx +0 -62
  76. package/src/rules/no-array-arguments/README.md +0 -47
  77. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
  78. package/src/rules/no-array-arguments/index.tsx +0 -86
  79. package/src/rules/no-classname-prop/README.md +0 -47
  80. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
  81. package/src/rules/no-classname-prop/index.tsx +0 -34
  82. package/src/rules/no-container-queries/README.md +0 -99
  83. package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
  84. package/src/rules/no-container-queries/index.tsx +0 -94
  85. package/src/rules/no-dynamic-styles/README.md +0 -128
  86. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
  87. package/src/rules/no-dynamic-styles/index.tsx +0 -60
  88. package/src/rules/no-exported-styles/README.md +0 -85
  89. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
  90. package/src/rules/no-exported-styles/index.tsx +0 -52
  91. package/src/rules/no-global-styles/README.md +0 -58
  92. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
  93. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
  94. package/src/rules/no-global-styles/index.tsx +0 -82
  95. package/src/rules/no-important-styles/README.md +0 -31
  96. package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
  97. package/src/rules/no-important-styles/index.tsx +0 -70
  98. package/src/rules/no-imported-style-values/README.md +0 -155
  99. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
  100. package/src/rules/no-imported-style-values/index.tsx +0 -188
  101. package/src/rules/no-nested-selectors/README.md +0 -93
  102. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
  103. package/src/rules/no-nested-selectors/index.tsx +0 -99
  104. package/src/rules/no-styled/README.md +0 -90
  105. package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
  106. package/src/rules/no-styled/index.tsx +0 -45
  107. package/src/rules/no-unsafe-selectors/README.md +0 -368
  108. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
  109. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
  110. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
  111. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
  112. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
  113. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
  114. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
  115. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
  116. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
  117. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
  118. package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
  119. package/src/rules/no-unsafe-selectors/index.tsx +0 -198
  120. package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
  121. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
  122. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
  123. package/src/rules/no-unsafe-values/README.md +0 -316
  124. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
  125. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
  126. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
  127. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
  128. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
  129. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
  130. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
  131. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
  132. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
  133. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
  134. package/src/rules/no-unsafe-values/index.tsx +0 -94
  135. package/src/rules/no-unsafe-values/messages.tsx +0 -86
  136. package/src/rules/no-unsafe-values/utils.tsx +0 -387
  137. package/src/rules/use-compiled/README.md +0 -52
  138. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
  139. package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
  140. package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
  141. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
  142. package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
  143. package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
  144. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
  145. package/src/rules/use-compiled/index.tsx +0 -252
  146. package/src/rules/use-compiled/is-safe.tsx +0 -159
  147. package/src/rules/use-compiled/utils.tsx +0 -33
  148. package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
  149. package/src/rules/utils/create-rule.tsx +0 -13
  150. package/tsconfig.app.json +0 -47
  151. package/tsconfig.dev.json +0 -45
  152. package/tsconfig.json +0 -25
@@ -1,252 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-codemod-utils';
3
- import type * as ESTree from 'eslint-codemod-utils';
4
- import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
5
-
6
- import { findVariable } from '@atlaskit/eslint-utils/find-variable';
7
-
8
- import { createLintRule } from '../utils/create-rule';
9
- import {
10
- getFirstImportFromSource,
11
- isImportDefaultSpecifier,
12
- isImportNamespaceSpecifier,
13
- isImportSpecifier,
14
- } from './utils';
15
- import { isSafeStyled, isSafeUsage } from './is-safe';
16
-
17
- const SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
18
-
19
- const SUPPORTED_IMPORT_MAP = {
20
- '@emotion/core': SUPPORTED_EMOTION_IMPORTS,
21
- '@emotion/react': SUPPORTED_EMOTION_IMPORTS,
22
- '@emotion/styled': new Set(['default']),
23
- 'styled-components': new Set(['default', 'css', 'keyframes']),
24
- };
25
-
26
- type SupportedImportSource = keyof typeof SUPPORTED_IMPORT_MAP;
27
-
28
- function isSupportedImportSource(importSource: string): importSource is SupportedImportSource {
29
- return importSource in SUPPORTED_IMPORT_MAP;
30
- }
31
-
32
- const schema = {
33
- type: 'array',
34
- items: [
35
- {
36
- type: 'object',
37
- properties: {
38
- canAutoFix: {
39
- type: 'boolean',
40
- },
41
- },
42
- additionalProperties: false,
43
- },
44
- ],
45
- } as const satisfies JSONSchema;
46
-
47
- type Config = {
48
- canAutoFix: boolean;
49
- };
50
-
51
- const defaultConfig: Config = {
52
- canAutoFix: false,
53
- };
54
-
55
- function readConfig(context: Rule.RuleContext): Config {
56
- const [config] = context.options as FromSchema<typeof schema>;
57
- return Object.assign({}, defaultConfig, config);
58
- }
59
-
60
- export const rule: Rule.RuleModule = createLintRule({
61
- meta: {
62
- name: 'use-compiled',
63
- type: 'problem',
64
- fixable: 'code',
65
- docs: {
66
- description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
67
- recommended: true,
68
- severity: 'error',
69
- },
70
- messages: {
71
- 'use-compiled': `Use '@compiled/react' instead of '{{importSource}}'`,
72
- },
73
- schema,
74
- },
75
- create(context) {
76
- const config = readConfig(context);
77
-
78
- return {
79
- Program() {
80
- const pragma = context
81
- .getSourceCode()
82
- .getAllComments()
83
- .find((n) => n.value.includes('@jsxImportSource @emotion/react'));
84
-
85
- if (!pragma) {
86
- return;
87
- }
88
-
89
- context.report({
90
- messageId: 'use-compiled',
91
- data: {
92
- importSource: '@emotion/react',
93
- },
94
- loc: pragma.loc!,
95
- *fix(fixer) {
96
- if (!config.canAutoFix) {
97
- return;
98
- }
99
-
100
- const importDeclarations = context
101
- .getSourceCode()
102
- .ast.body.filter(
103
- (node): node is ESTree.ImportDeclaration => node.type === 'ImportDeclaration',
104
- );
105
-
106
- const hasEmotionImport = importDeclarations.some((importDeclaration) => {
107
- const importSource = importDeclaration.source.value as string;
108
- return importSource.startsWith('@emotion/');
109
- });
110
- const hasCompiledImport = importDeclarations.some(
111
- (importDeclaration) => importDeclaration.source.value === '@compiled/react',
112
- );
113
-
114
- if (hasEmotionImport || !hasCompiledImport) {
115
- // Considering this unsafe to auto-fix
116
- return;
117
- }
118
-
119
- yield fixer.replaceText(
120
- // @ts-expect-error - types don't accept comment nodes
121
- pragma,
122
- `/** @jsxImportSource @compiled/react */`,
123
- );
124
- },
125
- });
126
- },
127
- ImportDeclaration(node: ESTree.ImportDeclaration) {
128
- const importSource = node.source.value as string;
129
- if (!isSupportedImportSource(importSource)) {
130
- return;
131
- }
132
-
133
- context.report({
134
- node: node.source,
135
- messageId: 'use-compiled',
136
- data: {
137
- importSource,
138
- },
139
- *fix(fixer) {
140
- if (!config.canAutoFix) {
141
- return;
142
- }
143
-
144
- const specifiers = getSpecifiers({ context, node, importSource });
145
-
146
- if (!specifiers) {
147
- // Cannot safely auto-fix
148
- return;
149
- }
150
-
151
- yield* fixImport({
152
- context,
153
- fixer,
154
- node,
155
- specifiers,
156
- });
157
- },
158
- });
159
- },
160
- };
161
- },
162
- });
163
-
164
- export default rule;
165
-
166
- function getSpecifiers({
167
- context,
168
- node,
169
- importSource,
170
- }: {
171
- context: Rule.RuleContext;
172
- node: ESTree.ImportDeclaration;
173
- importSource: SupportedImportSource;
174
- }) {
175
- const supportedImports = SUPPORTED_IMPORT_MAP[importSource];
176
-
177
- // We aren't supporting namespace imports
178
- if (node.specifiers.some(isImportNamespaceSpecifier)) {
179
- return;
180
- }
181
-
182
- const defaultSpecifier = node.specifiers.find(isImportDefaultSpecifier);
183
- if (defaultSpecifier) {
184
- if (!supportedImports.has('default')) {
185
- return;
186
- }
187
- const styled = findVariable({
188
- identifier: defaultSpecifier.local,
189
- sourceCode: context.getSourceCode(),
190
- });
191
- if (!styled || !isSafeStyled(styled)) {
192
- return;
193
- }
194
- }
195
-
196
- const namedSpecifiers = node.specifiers.filter(isImportSpecifier);
197
- if (
198
- !namedSpecifiers.every((specifier) =>
199
- isSafeUsage({
200
- context,
201
- specifier,
202
- supportedImports,
203
- }),
204
- )
205
- ) {
206
- return;
207
- }
208
-
209
- if (defaultSpecifier) {
210
- return [
211
- ...namedSpecifiers,
212
- // ASSUMPTION: the default import, if allowed, is for `styled`
213
- importSpecifier({
214
- imported: identifier('styled'),
215
- local: node.specifiers[0].local,
216
- }),
217
- ];
218
- }
219
-
220
- return namedSpecifiers;
221
- }
222
-
223
- function* fixImport({
224
- context,
225
- fixer,
226
- node,
227
- specifiers,
228
- }: {
229
- context: Rule.RuleContext;
230
- fixer: Rule.RuleFixer;
231
- node: ESTree.ImportDeclaration;
232
- specifiers: ESTree.ImportSpecifier[];
233
- }): Generator<Rule.Fix> {
234
- const compiledImport = getFirstImportFromSource(context, '@compiled/react');
235
-
236
- if (compiledImport) {
237
- yield fixer.remove(node);
238
- yield fixer.replaceText(
239
- compiledImport,
240
- buildImportDeclaration(compiledImport.specifiers.concat(specifiers), '@compiled/react'),
241
- );
242
- } else {
243
- yield fixer.replaceText(node, buildImportDeclaration(specifiers, '@compiled/react'));
244
- }
245
- }
246
-
247
- function buildImportDeclaration(
248
- specifiers: ESTree.ImportDeclaration['specifiers'],
249
- source: string,
250
- ) {
251
- return `${importDeclaration({ specifiers, source: literal(source) })};`;
252
- }
@@ -1,159 +0,0 @@
1
- import type { Rule, Scope } from 'eslint';
2
- import { closestOfType } from 'eslint-codemod-utils';
3
- import type * as ESTree from 'eslint-codemod-utils';
4
-
5
- import { findVariable } from '@atlaskit/eslint-utils/find-variable';
6
-
7
- export function isSafeUsage({
8
- context,
9
- specifier,
10
- supportedImports,
11
- }: {
12
- context: Rule.RuleContext;
13
- specifier: ESTree.ImportSpecifier;
14
- supportedImports: Set<string>;
15
- }): boolean {
16
- const importName = specifier.imported.name;
17
-
18
- if (!supportedImports.has(importName)) {
19
- return false;
20
- }
21
-
22
- if (importName === 'css') {
23
- const css = findVariable({
24
- identifier: specifier.local,
25
- sourceCode: context.getSourceCode(),
26
- });
27
- return css !== null && isSafeCss(css);
28
- }
29
-
30
- if (importName === 'keyframes') {
31
- const keyframes = findVariable({
32
- identifier: specifier.local,
33
- sourceCode: context.getSourceCode(),
34
- });
35
- return keyframes !== null && isSafeKeyframes(keyframes);
36
- }
37
-
38
- return true;
39
- }
40
-
41
- export function isSafeKeyframes(keyframes: Scope.Variable): boolean {
42
- return keyframes.references.every((ref) => {
43
- const callExpression = closestOfType(ref.identifier, 'CallExpression');
44
- if (!callExpression) {
45
- return false;
46
- }
47
-
48
- if (callExpression.callee !== ref.identifier) {
49
- return false;
50
- }
51
-
52
- if (callExpression.arguments.length !== 1) {
53
- return false;
54
- }
55
-
56
- const argument = callExpression.arguments[0];
57
- if (argument.type !== 'ObjectExpression') {
58
- return false;
59
- }
60
-
61
- return argument.properties.every((property) =>
62
- isSafeProperty(property, isSafeKeyframePropertyValue),
63
- );
64
- });
65
- }
66
-
67
- function isSafeKeyframePropertyValue(value: ESTree.Property['value']): boolean {
68
- if (value.type !== 'ObjectExpression') {
69
- return false;
70
- }
71
- return isSafeStyleObject(value);
72
- }
73
-
74
- export function isSafeCss(css: Scope.Variable): boolean {
75
- return css.references.every((ref) => {
76
- const callExpression = closestOfType(ref.identifier, 'CallExpression');
77
- if (!callExpression) {
78
- return false;
79
- }
80
-
81
- if (callExpression.callee !== ref.identifier) {
82
- return false;
83
- }
84
-
85
- return callExpression.arguments.every(isSafeStyleArgument);
86
- });
87
- }
88
-
89
- export function isSafeStyled(styled: Scope.Variable): boolean {
90
- return styled.references.every((ref) => {
91
- const callExpression = closestOfType(ref.identifier, 'CallExpression');
92
- if (!callExpression) {
93
- return false;
94
- }
95
-
96
- /**
97
- * If it's not in the form `styled.tagName()`
98
- * then we consider it unsafe to auto-fix.
99
- */
100
- if (
101
- callExpression.callee.type !== 'MemberExpression' ||
102
- callExpression.callee.object !== ref.identifier
103
- ) {
104
- return false;
105
- }
106
-
107
- return callExpression.arguments.every(isSafeStyleArgument);
108
- });
109
- }
110
-
111
- /**
112
- * Determines if a style argument is safe for auto-fix conversion.
113
- */
114
- function isSafeStyleArgument(arg: ESTree.Expression | ESTree.SpreadElement): boolean {
115
- if (arg.type === 'ObjectExpression') {
116
- return isSafeStyleObject(arg);
117
- }
118
-
119
- return false;
120
- }
121
-
122
- function isSafeStyleObject(object: ESTree.ObjectExpression): boolean {
123
- return object.properties.every((property) => isSafeProperty(property, isSafeStyleValue));
124
- }
125
-
126
- function isSafeStyleValue(value: ESTree.Expression | ESTree.Pattern): boolean {
127
- if (value.type === 'Literal') {
128
- return true;
129
- }
130
-
131
- return false;
132
- }
133
-
134
- function isSafeProperty(
135
- property: ESTree.Property | ESTree.SpreadElement,
136
- isSafePropertyValue: (value: ESTree.Property['value']) => boolean,
137
- ): boolean {
138
- if (property.type === 'SpreadElement') {
139
- return false;
140
- }
141
-
142
- if (property.method || property.shorthand || property.kind !== 'init') {
143
- return false;
144
- }
145
-
146
- if (!hasSafeKey(property)) {
147
- return false;
148
- }
149
-
150
- return isSafePropertyValue(property.value);
151
- }
152
-
153
- function hasSafeKey(property: ESTree.Property): boolean {
154
- if (property.computed) {
155
- return property.key.type === 'Literal';
156
- }
157
-
158
- return true;
159
- }
@@ -1,33 +0,0 @@
1
- import type { Rule } from 'eslint';
2
-
3
- import type * as ESTree from 'eslint-codemod-utils';
4
-
5
- export function getFirstImportFromSource(
6
- context: Rule.RuleContext,
7
- source: string,
8
- ): ESTree.ImportDeclaration | undefined {
9
- return context
10
- .getSourceCode()
11
- .ast.body.filter(isImportDeclaration)
12
- .find((node) => node.source.value === source);
13
- }
14
-
15
- function isImportDeclaration(node: ESTree.Node): node is ESTree.ImportDeclaration {
16
- return node.type === 'ImportDeclaration';
17
- }
18
-
19
- export function isImportSpecifier(specifier: ESTree.Node): specifier is ESTree.ImportSpecifier {
20
- return specifier.type === 'ImportSpecifier';
21
- }
22
-
23
- export function isImportDefaultSpecifier(
24
- specifier: ESTree.Node,
25
- ): specifier is ESTree.ImportDefaultSpecifier {
26
- return specifier.type === 'ImportDefaultSpecifier';
27
- }
28
-
29
- export function isImportNamespaceSpecifier(
30
- specifier: ESTree.Node,
31
- ): specifier is ESTree.ImportNamespaceSpecifier {
32
- return specifier.type === 'ImportNamespaceSpecifier';
33
- }
@@ -1,86 +0,0 @@
1
- import Ajv from 'ajv';
2
- import type { Rule } from 'eslint';
3
- import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
4
-
5
- import type {
6
- LintRule as BaseLintRule,
7
- LintRuleMeta as BaseLintRuleMeta,
8
- } from '@atlaskit/eslint-utils/create-rule';
9
-
10
- import { getRuleUrl } from './create-rule';
11
-
12
- export interface LintRule<Schema extends JSONSchema, Config>
13
- extends Omit<BaseLintRule, 'meta' | 'create'> {
14
- meta: LintRuleMeta<Schema>;
15
-
16
- create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
17
-
18
- /**
19
- * Unsure why the eslint typings include this when the docs
20
- * say the schema should be in meta.
21
- */
22
- schema?: never;
23
- }
24
-
25
- export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRuleMeta, 'schema'> {
26
- schema: Schema;
27
- }
28
-
29
- export const createLintRuleWithTypedConfig = <
30
- Schema extends JSONSchema & { type: 'object' },
31
- Config = FromSchema<Schema>,
32
- >(
33
- rule: LintRule<Schema, Config>,
34
- ) => {
35
- /**
36
- * Gets the default config by running the same validator
37
- * ESLint does against an empty config object with
38
- * `useDefaults` option enabled.
39
- *
40
- * Any properties with a `default` property set in the schema
41
- * will be populated with the specified default value.
42
- */
43
- function getDefaultConfig(): Config {
44
- const ajv = new Ajv({ useDefaults: true });
45
- const validate = ajv.compile(rule.meta.schema);
46
-
47
- const config = {};
48
- /**
49
- * The `validate()` function mutates the config object.
50
- */
51
- validate(config);
52
-
53
- return config as Config;
54
- }
55
-
56
- return {
57
- ...rule,
58
- meta: {
59
- ...rule.meta,
60
- docs: {
61
- ...rule.meta.docs,
62
- url: getRuleUrl(rule.meta.name),
63
- },
64
- schema: [rule.meta.schema],
65
- },
66
- create(context) {
67
- /**
68
- * The config the user has passed.
69
- *
70
- * If they passed a config object, even if it is missing properties,
71
- * ESLint will have added any default values defined using the
72
- * `default` property in the schema.
73
- *
74
- * https://github.com/eslint/eslint/pull/11288
75
- */
76
- const userConfig = context.options[0] as Config | undefined;
77
- /**
78
- * If the user passed no config object at all we need to obtain
79
- * the default ourselves.
80
- */
81
- const config = userConfig ?? getDefaultConfig();
82
-
83
- return rule.create(context, config);
84
- },
85
- } as Rule.RuleModule;
86
- };
@@ -1,13 +0,0 @@
1
- import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
2
-
3
- /**
4
- * Tiny wrapped over the ESLint rule module type that ensures
5
- * there is a docs link to our ESLint plugin documentation page,
6
- * as well as improving type support.
7
- */
8
- export const createLintRule = getCreateLintRule(getRuleUrl);
9
-
10
- export function getRuleUrl(ruleName: string) {
11
- const name = getPathSafeName(ruleName);
12
- return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
13
- }
package/tsconfig.app.json DELETED
@@ -1,47 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.node.json",
3
- "include": ["./src/**/*.ts", "./src/**/*.tsx"],
4
- "exclude": [
5
- "**/docs/**/*",
6
- "**/__tests__/**/*",
7
- "**/vr-tests/**/*",
8
- "**/__perf__/**/*",
9
- "**/*.test.*",
10
- "**/test.*",
11
- "**/test-*",
12
- "**/examples.ts",
13
- "**/examples.tsx",
14
- "**/examples/*.ts",
15
- "**/examples/*.tsx",
16
- "**/examples/**/*.ts",
17
- "**/examples/**/*.tsx",
18
- "**/storybook/**/*",
19
- "**/constellation/**/*",
20
- ".storybook/*",
21
- "./__fixtures__/**/*",
22
- "./__generated__/**/*",
23
- "./mocks/**/*",
24
- "./__mocks__/**/*",
25
- "**/mock.*",
26
- "**/codemods/**/*.ts",
27
- "**/codemods/**/*.tsx"
28
- ],
29
- "compilerOptions": {
30
- "baseUrl": "./",
31
- "lib": ["ES2021.String"],
32
- "composite": true,
33
- "outDir": "../../../tsDist/@atlaskit__eslint-plugin-ui-styling-standard/app"
34
- },
35
- "references": [
36
- {
37
- "path": "../../../build/formatting/tsconfig.app.json"
38
- },
39
- {
40
- "path": "../eslint-utils/tsconfig.app.json"
41
- },
42
- {
43
- "path": "../codegen/tsconfig.app.json"
44
- }
45
- ],
46
- "files": []
47
- }
package/tsconfig.dev.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.node.json",
3
- "include": [
4
- "**/docs/**/*",
5
- "**/__tests__/**/*",
6
- "**/vr-tests/**/*",
7
- "**/__perf__/**/*",
8
- "**/*.test.*",
9
- "**/test.*",
10
- "**/test-*",
11
- "**/examples.ts",
12
- "**/examples.tsx",
13
- "**/examples/*.ts",
14
- "**/examples/*.tsx",
15
- "**/examples/**/*.ts",
16
- "**/examples/**/*.tsx",
17
- "**/storybook/**/*",
18
- "**/constellation/**/*",
19
- ".storybook/*",
20
- "./__fixtures__/**/*",
21
- "./__generated__/**/*",
22
- "./mocks/**/*",
23
- "./__mocks__/**/*",
24
- "**/mock.*",
25
- "**/codemods/**/*.ts",
26
- "**/codemods/**/*.tsx",
27
- "./**/__fixtures__/**/*.json"
28
- ],
29
- "exclude": ["./dist/**/*", "./build/**/*", "./node_modules/**/*"],
30
- "compilerOptions": {
31
- "baseUrl": "./",
32
- "lib": ["ES2021.String"],
33
- "composite": true,
34
- "outDir": "../../../tsDist/@atlaskit__eslint-plugin-ui-styling-standard/dev"
35
- },
36
- "references": [
37
- {
38
- "path": "tsconfig.app.json"
39
- },
40
- {
41
- "path": "../ds-lib/tsconfig.app.json"
42
- }
43
- ],
44
- "files": []
45
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.node.json",
3
- "include": [
4
- "__tests__/**/*.ts",
5
- "__tests__/**/*.tsx",
6
- "docs/**/*.ts",
7
- "docs/**/*.tsx",
8
- "examples/**/*.ts",
9
- "examples/**/*.tsx",
10
- "src/**/*.ts",
11
- "src/**/*.tsx",
12
- "scripts"
13
- ],
14
- "exclude": [],
15
- "compilerOptions": {
16
- "baseUrl": "./",
17
- "lib": ["ES2021.String"]
18
- },
19
- "ts-node": {
20
- // It is faster to skip typechecking.
21
- "transpileOnly": true,
22
- // We must load files for third party defs - https://typestrong.org/ts-node/docs/types
23
- "files": true
24
- }
25
- }