@atlaskit/eslint-plugin-ui-styling-standard 0.7.2 → 0.8.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 (51) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -1
  3. package/constellation/index/overview.mdx +2 -1
  4. package/constellation/no-nested-selectors/usage.mdx +60 -0
  5. package/dist/cjs/presets/all.codegen.js +3 -4
  6. package/dist/cjs/presets/recommended.codegen.js +3 -4
  7. package/dist/cjs/rules/convert-props-syntax/index.js +5 -0
  8. package/dist/cjs/rules/external-rules.js +1 -27
  9. package/dist/cjs/rules/index.codegen.js +4 -2
  10. package/dist/cjs/rules/no-nested-selectors/index.js +82 -0
  11. package/dist/cjs/rules/utils/create-rule.js +4 -29
  12. package/dist/es2019/presets/all.codegen.js +3 -4
  13. package/dist/es2019/presets/recommended.codegen.js +3 -4
  14. package/dist/es2019/rules/convert-props-syntax/index.js +5 -0
  15. package/dist/es2019/rules/external-rules.js +1 -27
  16. package/dist/es2019/rules/index.codegen.js +4 -2
  17. package/dist/es2019/rules/no-nested-selectors/index.js +71 -0
  18. package/dist/es2019/rules/utils/create-rule.js +2 -23
  19. package/dist/esm/presets/all.codegen.js +3 -4
  20. package/dist/esm/presets/recommended.codegen.js +3 -4
  21. package/dist/esm/rules/convert-props-syntax/index.js +5 -0
  22. package/dist/esm/rules/external-rules.js +1 -27
  23. package/dist/esm/rules/index.codegen.js +4 -2
  24. package/dist/esm/rules/no-nested-selectors/index.js +76 -0
  25. package/dist/esm/rules/utils/create-rule.js +2 -25
  26. package/dist/types/index.codegen.d.ts +4 -6
  27. package/dist/types/presets/all.codegen.d.ts +3 -4
  28. package/dist/types/presets/recommended.codegen.d.ts +3 -4
  29. package/dist/types/rules/external-rules.d.ts +1 -1
  30. package/dist/types/rules/index.codegen.d.ts +1 -0
  31. package/dist/types/rules/no-nested-selectors/index.d.ts +2 -0
  32. package/dist/types/rules/utils/create-rule.d.ts +1 -58
  33. package/dist/types-ts4.5/index.codegen.d.ts +4 -6
  34. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -4
  35. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -4
  36. package/dist/types-ts4.5/rules/external-rules.d.ts +1 -1
  37. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  38. package/dist/types-ts4.5/rules/no-nested-selectors/index.d.ts +2 -0
  39. package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -58
  40. package/package.json +3 -3
  41. package/scripts/codegen.tsx +4 -1
  42. package/src/presets/all.codegen.tsx +3 -13
  43. package/src/presets/recommended.codegen.tsx +3 -13
  44. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +52 -0
  45. package/src/rules/convert-props-syntax/index.tsx +10 -0
  46. package/src/rules/external-rules.tsx +2 -31
  47. package/src/rules/index.codegen.tsx +3 -1
  48. package/src/rules/no-nested-selectors/README.md +58 -0
  49. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +236 -0
  50. package/src/rules/no-nested-selectors/index.tsx +115 -0
  51. package/src/rules/utils/create-rule.tsx +5 -69
@@ -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::2e134e292f949b29bfd0b29d128e684a>>
3
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -15,24 +15,14 @@ export default {
15
15
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
16
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
17
17
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
18
19
  '@atlaskit/design-system/consistent-css-prop-usage': [
19
20
  'warn',
20
21
  { excludeReactComponents: true },
21
22
  ],
22
23
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
23
24
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
24
- '@atlaskit/design-system/no-styled-tagged-template-expression': [
25
- 'warn',
26
- {
27
- importSources: [
28
- '@compiled/react',
29
- '@atlaskit/css',
30
- '@emotion/core',
31
- '@emotion/react',
32
- '@emotion/styled',
33
- ],
34
- },
35
- ],
25
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
36
26
  '@compiled/no-suppress-xcss': 'warn',
37
27
  '@compiled/no-js-xcss': 'warn',
38
28
  '@atlaskit/design-system/no-empty-styled-expression': [
@@ -103,6 +103,58 @@ typescriptEslintTester.run(
103
103
  });
104
104
  `,
105
105
  },
106
+ {
107
+ name: 'ignores styled(...).attrs() call',
108
+ code: `
109
+ import { styled } from 'styled-components';
110
+
111
+ const StyledMinimized = styled(Minimized).attrs({
112
+ className: (props) => props.transitionClass,
113
+ })\`
114
+ color: blue;
115
+ \`;
116
+ `,
117
+ },
118
+ {
119
+ name: 'ignores styled.div.attrs<...>() call',
120
+ code: `
121
+ import { styled } from '@compiled/react';
122
+
123
+ export const ModalAnchorOld = styled.div.attrs<ModalAnchorProps>({
124
+ style: ({ left, top }: ModalAnchorProps) => ({
125
+ left,
126
+ top,
127
+ }),
128
+ })\`
129
+ position: fixed;
130
+ \`;
131
+ `,
132
+ },
133
+ {
134
+ name: 'ignores styled.div.attrs() call',
135
+ code: `
136
+ const BlanketControl = styled.div.attrs({
137
+ style: ({ scrollOffset, width }) => ({
138
+ top: scrollOffset,
139
+ bottom: -scrollOffset,
140
+ width,
141
+ }),
142
+ })\`
143
+ display: flex;
144
+ justify-content: center;
145
+ \`;
146
+ `,
147
+ },
148
+ {
149
+ name: 'ignores styled.img.attrs() call',
150
+ code: `
151
+ export const FieldsRestoredIllustration = styled.img.attrs({ src: fieldsRestoredImage })\`
152
+ display: block;
153
+ min-height: 190px;
154
+ max-width: 290px;
155
+ \`;
156
+ `,
157
+ },
106
158
  ],
107
159
  invalid: [
108
160
  {
@@ -394,6 +394,16 @@ export const rule = createLintRule({
394
394
  node: CallExpression,
395
395
  ) => {
396
396
  const references = context.getScope().references;
397
+
398
+ // Rule should ignore .attrs() calls
399
+ if (
400
+ node.callee.type === 'MemberExpression' &&
401
+ node.callee.property.type === 'Identifier' &&
402
+ node.callee.property.name === 'attrs'
403
+ ) {
404
+ return;
405
+ }
406
+
397
407
  const callee =
398
408
  node.callee.type === 'MemberExpression'
399
409
  ? node.callee.object
@@ -1,4 +1,5 @@
1
- import { getRuleUrl, type LintRuleMeta } from './utils/create-rule';
1
+ import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
2
+ import { getRuleUrl } from './utils/create-rule';
2
3
 
3
4
  /** External rules must be scoped, have a display name, and external urls. */
4
5
  export type ExternalRuleMeta = LintRuleMeta & {
@@ -17,33 +18,6 @@ const importSources: readonly string[] = [
17
18
  'styled-components',
18
19
  ];
19
20
 
20
- /**
21
- * Same as importSources, but excludes `styled-components` because the type-checking
22
- * for `styled-components` does not support the `no-styled-tagged-template-expression`
23
- * lint output for this:
24
- *
25
- * export const Container = styled(Section)`
26
- * max-height: ${gridSize * 46}px;
27
- * overflow: auto;
28
- * `;
29
- *
30
- * export const ErrorStateContainer = styled(Container)`
31
- * margin: ${
32
- * (props: any) =>
33
- * props.canManageAutomations // Use negative margin to reduce whitespace when the Footer component is shown
34
- * ? `${gridSize * -4}px ${gridSize * 2}px`
35
- * : `0 ${gridSize * 2}px`
36
- * };
37
- * `;
38
- */
39
- const noStyledTaggedTemplateExpressionImportSources: readonly string[] = [
40
- '@compiled/react',
41
- '@atlaskit/css', // doesn't do anything because @atlaskit/css doesn't expose a styled API
42
- '@emotion/core',
43
- '@emotion/react',
44
- '@emotion/styled',
45
- ];
46
-
47
21
  export const externalRules: ExternalRuleMeta[] = [
48
22
  {
49
23
  name: '@atlaskit/design-system/consistent-css-prop-usage',
@@ -108,9 +82,6 @@ export const externalRules: ExternalRuleMeta[] = [
108
82
  'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
109
83
  recommended: true,
110
84
  severity: 'warn',
111
- pluginConfig: {
112
- importSources: noStyledTaggedTemplateExpressionImportSources,
113
- },
114
85
  },
115
86
  },
116
87
  {
@@ -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::3504ce124f49b7eca8abafb5a0bd6884>>
3
+ * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
@@ -8,6 +8,7 @@ import localCxXcss from './local-cx-xcss';
8
8
  import noClassnameProp from './no-classname-prop';
9
9
  import noContainerQueries from './no-container-queries';
10
10
  import noImportantStyles from './no-important-styles';
11
+ import noNestedSelectors from './no-nested-selectors';
11
12
 
12
13
  export default {
13
14
  'convert-props-syntax': convertPropsSyntax,
@@ -15,4 +16,5 @@ export default {
15
16
  'no-classname-prop': noClassnameProp,
16
17
  'no-container-queries': noContainerQueries,
17
18
  'no-important-styles': noImportantStyles,
19
+ 'no-nested-selectors': noNestedSelectors,
18
20
  };
@@ -0,0 +1,58 @@
1
+ This rule prevents the usage of the nested selectors in style declarations. Avoid setting styles for any child elements or elements that require context from other elements.
2
+
3
+ ## Examples
4
+
5
+ ### Incorrect
6
+
7
+ ```js
8
+ import { css } from '@compiled/react';
9
+ const styles = css({
10
+ h2: {
11
+ fontSize: '1.5rem',
12
+ },
13
+ });
14
+ ```
15
+
16
+ ```js
17
+ import { styled } from '@compiled/react';
18
+ const Component = styled.div({
19
+ '*': {
20
+ padding: 0,
21
+ },
22
+ });
23
+ ```
24
+
25
+ ```js
26
+ import { styled } from '@compiled/react';
27
+ const Component = styled.div({
28
+ '.myclass': {
29
+ padding: 0,
30
+ },
31
+ });
32
+ ```
33
+
34
+ ### Correct
35
+
36
+ ```js
37
+ import { css } from '@compiled/react';
38
+ const styles = css({
39
+ display: 'flex',
40
+ flexDirection: 'column',
41
+ });
42
+ ```
43
+
44
+ ## Options
45
+
46
+ ### importSources
47
+
48
+ By default, this rule will check `css` usages from:
49
+
50
+ - `@atlaskit/css`
51
+ - `@atlaskit/primitives`
52
+ - `@compiled/react`
53
+ - `@emotion/react`
54
+ - `@emotion/core`
55
+ - `@emotion/styled`
56
+ - `styled-components`
57
+
58
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
@@ -0,0 +1,236 @@
1
+ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ typescriptEslintTester.run(
5
+ 'no-nested-selectors',
6
+ // @ts-expect-error
7
+ rule,
8
+ {
9
+ valid: [
10
+ {
11
+ name: 'Basic valid test',
12
+ code: `
13
+ import { css } from '@compiled/react';
14
+ const styles = css({
15
+ display: 'flex',
16
+ flexDirection: 'column',
17
+ });
18
+ `,
19
+ },
20
+ {
21
+ name: 'Basic valid test using emotion',
22
+ code: `
23
+ import styled from '@emotion/styled';
24
+ const Container = styled.div({
25
+ display: 'flex',
26
+ flexDirection: 'column'
27
+ })
28
+ `,
29
+ },
30
+ {
31
+ name: 'Custom import sources (subtractive)',
32
+ code: `
33
+ import { css } from '@compiled/react';
34
+ const styles = css({
35
+ h2: {
36
+ fontSize: '1.5rem',
37
+ }
38
+ });
39
+ `,
40
+ options: [
41
+ {
42
+ importSources: [],
43
+ },
44
+ ],
45
+ },
46
+ {
47
+ name: 'Styled div with no selectors',
48
+ code: `
49
+ import { styled } from '@compiled/react';
50
+ const Component = styled.div({
51
+ padding: 0,
52
+ display: 'flex',
53
+ flexDirection: 'column',
54
+ boxSizing: 'border-box',
55
+ });
56
+ `,
57
+ },
58
+ {
59
+ name: 'Pseudo element selectors',
60
+ code: `
61
+ import { styled } from '@compiled/react';
62
+ const Component = styled.div({
63
+ '&:hover': {
64
+ color: 'red'
65
+ },
66
+ '&:focus, :last-child': {
67
+ color: 'yellow'
68
+ },
69
+ '&:first-of-type:last-child': {
70
+ color: 'green'
71
+ },
72
+ });
73
+ `,
74
+ },
75
+ {
76
+ name: 'Next sibling selector on non-HTML element',
77
+ code: `
78
+ import { styled } from '@compiled/react';
79
+ styled.div({
80
+ '& + &': {
81
+ color: 'orange'
82
+ }
83
+ });
84
+ `,
85
+ },
86
+ {
87
+ name: 'Subsequent sibling selector on non-HTML element',
88
+ code: `
89
+ import { styled } from '@compiled/react';
90
+ styled.div({
91
+ '& ~ &': {
92
+ color: 'orange'
93
+ }
94
+ });
95
+ `,
96
+ },
97
+ ],
98
+ invalid: [
99
+ {
100
+ name: 'Universal selector',
101
+ code: `
102
+ import { styled } from '@compiled/react';
103
+ const Component = styled.div({
104
+ '*': {
105
+ padding: 0,
106
+ }
107
+ });
108
+ `,
109
+ errors: [{ messageId: 'no-nested-selectors' }],
110
+ },
111
+ {
112
+ name: 'Class selector',
113
+ code: `
114
+ import { styled } from '@compiled/react';
115
+ const Component = styled.div({
116
+ '.myclass': {
117
+ padding: 0,
118
+ }
119
+ });
120
+ `,
121
+ errors: [{ messageId: 'no-nested-selectors' }],
122
+ },
123
+ {
124
+ name: 'ID selector',
125
+ code: `
126
+ import { styled } from '@compiled/react';
127
+ const Component = styled.div({
128
+ '#myid': {
129
+ padding: 0,
130
+ }
131
+ });
132
+ `,
133
+ errors: [{ messageId: 'no-nested-selectors' }],
134
+ },
135
+ {
136
+ name: 'HTML element selector',
137
+ code: `
138
+ import { styled } from '@compiled/react';
139
+ const Component = styled.div({
140
+ h2: {
141
+ fontSize: '1.5rem',
142
+ }
143
+ });
144
+ `,
145
+ errors: [{ messageId: 'no-nested-selectors' }],
146
+ },
147
+ {
148
+ name: 'Data-component-selector',
149
+ code: `
150
+ import { styled } from '@compiled/react';
151
+ const Component = styled.div({
152
+ '[data-component-selector="my.button"]': {
153
+ color: 'blue',
154
+ },
155
+ });
156
+ `,
157
+ errors: [{ messageId: 'no-nested-selectors' }],
158
+ },
159
+ {
160
+ name: 'Grouping selector',
161
+ code: `
162
+ import { styled } from '@compiled/react';
163
+ const Component = styled.div({
164
+ 'div, p, span': {
165
+ fontSize: '1.5rem',
166
+ },
167
+ color: 'blue',
168
+ backgroundColor: 'red',
169
+ });
170
+ `,
171
+ errors: [{ messageId: 'no-nested-selectors' }],
172
+ },
173
+ {
174
+ name: 'Selector including a variable',
175
+ code: `
176
+ import { styled } from '@compiled/react';
177
+ styled.div({
178
+ [\`\${SOME_VAR} > *\`]: {
179
+ color: 'red'
180
+ },
181
+ });
182
+ `,
183
+ errors: [{ messageId: 'no-nested-selectors' }],
184
+ },
185
+ {
186
+ name: 'Current element selector',
187
+ code: `
188
+ import { styled } from '@compiled/react';
189
+ styled.div({
190
+ color: 'darkorchid',
191
+ '.name &': {
192
+ color: 'orange'
193
+ }
194
+ });
195
+ `,
196
+ errors: [{ messageId: 'no-nested-selectors' }],
197
+ },
198
+ {
199
+ name: 'Child combinator',
200
+ code: `
201
+ import { styled } from '@compiled/react';
202
+ styled.div({
203
+ '& > &': {
204
+ color: 'orange'
205
+ }
206
+ });
207
+ `,
208
+ errors: [{ messageId: 'no-nested-selectors' }],
209
+ },
210
+ {
211
+ name: 'Column combinator',
212
+ code: `
213
+ import { styled } from '@compiled/react';
214
+ styled.div({
215
+ 'col.selected||td': {
216
+ color: 'orange'
217
+ }
218
+ });
219
+ `,
220
+ errors: [{ messageId: 'no-nested-selectors' }],
221
+ },
222
+ {
223
+ name: 'Namespace selector',
224
+ code: `
225
+ import { styled } from '@compiled/react';
226
+ styled.div({
227
+ 'myNameSpace|a': {
228
+ color: 'orange'
229
+ }
230
+ });
231
+ `,
232
+ errors: [{ messageId: 'no-nested-selectors' }],
233
+ },
234
+ ],
235
+ },
236
+ );
@@ -0,0 +1,115 @@
1
+ import type { Property } from 'estree';
2
+
3
+ import {
4
+ isStyled,
5
+ isCss,
6
+ isKeyframes,
7
+ isCssMap,
8
+ isXcss,
9
+ getImportSources,
10
+ } from '@atlaskit/eslint-utils/is-supported-import';
11
+ import { createLintRule } from '../utils/create-rule';
12
+ import { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
13
+
14
+ const schema: JSONSchema4 = [
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ importSources: {
19
+ type: 'array',
20
+ items: { type: 'string' },
21
+ uniqueItems: true,
22
+ },
23
+ },
24
+ },
25
+ ];
26
+
27
+ const getCssSelector = (node: Property): string | null => {
28
+ if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
29
+ return node.key.value;
30
+ }
31
+
32
+ if (node.key.type === 'Identifier' && typeof node.key.name === 'string') {
33
+ return node.key.name;
34
+ }
35
+
36
+ if (node.key.type === 'TemplateLiteral') {
37
+ return node.key.quasis.map((quasi) => quasi.value.raw).join(' ');
38
+ }
39
+
40
+ return null;
41
+ };
42
+
43
+ export const rule = createLintRule({
44
+ meta: {
45
+ name: 'no-nested-selectors',
46
+ docs: {
47
+ description: 'Prevents usage of nested selectors within css styling',
48
+ recommended: true,
49
+ severity: 'warn',
50
+ },
51
+ messages: {
52
+ 'no-nested-selectors':
53
+ 'Please avoid setting styles for child elements or elements that require context from other elements.',
54
+ },
55
+ type: 'problem',
56
+ schema,
57
+ },
58
+ create(context) {
59
+ const importSources = getImportSources(context);
60
+ return {
61
+ 'CallExpression Property': (node: Property): void => {
62
+ const { references } = context.getScope();
63
+ const ancestors = context.getAncestors();
64
+
65
+ if (
66
+ ancestors.every(
67
+ (ancestor) =>
68
+ ancestor.type !== 'CallExpression' ||
69
+ !ancestor?.callee ||
70
+ !(
71
+ isCss(ancestor.callee, references, importSources) ||
72
+ isStyled(ancestor.callee, references, importSources) ||
73
+ isKeyframes(ancestor.callee, references, importSources) ||
74
+ isCssMap(ancestor.callee, references, importSources) ||
75
+ isXcss(ancestor.callee, references, importSources)
76
+ ),
77
+ )
78
+ ) {
79
+ return;
80
+ }
81
+
82
+ if (node.value.type !== 'ObjectExpression') {
83
+ // If the value is a CSS object, safe to assume we're at a CSS selector
84
+ return;
85
+ }
86
+
87
+ const cssSelector = getCssSelector(node);
88
+ if (cssSelector === null) {
89
+ return;
90
+ }
91
+
92
+ const tokens = cssSelector.split(/[, ]+/);
93
+
94
+ if (
95
+ !tokens.every(
96
+ (token) =>
97
+ token.length === 0 ||
98
+ token.startsWith('&') ||
99
+ token.startsWith(':') ||
100
+ token.includes('+') ||
101
+ token.includes('~') ||
102
+ token.endsWith('&'),
103
+ )
104
+ ) {
105
+ context.report({
106
+ messageId: 'no-nested-selectors',
107
+ node: node.key,
108
+ });
109
+ }
110
+ },
111
+ };
112
+ },
113
+ });
114
+
115
+ export default rule;
@@ -1,80 +1,16 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
- import type { Rule } from 'eslint';
4
-
5
- /**
6
- * We are moving to our own small abstraction to create a lint rule that we have the power
7
- * to change and mold to our own needs.
8
- *
9
- * @see createLintRule
10
- *
11
- * @private
12
- * @deprecated
13
- */
14
- export const createRule = ESLintUtils.RuleCreator((name) => getRuleUrl(name));
15
-
16
- export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
17
- /**
18
- * Including this for backwards compat moving from the typescript-eslint util.
19
- */
20
- name?: never;
21
- meta: LintRuleMeta;
22
- }
23
-
24
- export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
25
- /**
26
- * Name of the rule.
27
- * Must match the folder it is in exactly else build will throw.
28
- * Add an exception in codegen.tsx for nested rules.
29
- */
30
- name: string;
31
- docs: {
32
- /**
33
- * Short description of what this rule does.
34
- */
35
- description: string;
36
- /**
37
- * Specifies the URL at which the full documentation can be accessed.
38
- */
39
- url?: string | undefined;
40
- /**
41
- * If this rule should be in the recommended preset or not.
42
- * Set to `false` to exclude it from the recommended preset.
43
- */
44
- recommended: boolean;
45
- /**
46
- * The severity level to be applied to this rule.
47
- * When setting to `"error"` it will mean releasing a breaking change.
48
- */
49
- severity: 'error' | 'warn';
50
- /**
51
- * This is configuration passed into the plugin to configure the rule.
52
- *
53
- * Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
54
- */
55
- pluginConfig?: Record<string, any>;
56
- };
57
- }
1
+ import {
2
+ getCreateLintRule,
3
+ getPathSafeName,
4
+ } from '@atlaskit/eslint-utils/create-rule';
58
5
 
59
6
  /**
60
7
  * Tiny wrapped over the ESLint rule module type that ensures
61
8
  * there is a docs link to our ESLint plugin documentation page,
62
9
  * as well as improving type support.
63
10
  */
64
- export const createLintRule = (rule: LintRule) => {
65
- (rule.meta.docs as Record<string, unknown>).url = getRuleUrl(rule.meta.name);
66
-
67
- return rule as Rule.RuleModule;
68
- };
11
+ export const createLintRule = getCreateLintRule(getRuleUrl);
69
12
 
70
13
  export function getRuleUrl(ruleName: string) {
71
14
  const name = getPathSafeName(ruleName);
72
15
  return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
73
16
  }
74
-
75
- /**
76
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
77
- */
78
- export function getPathSafeName(ruleName: string) {
79
- return ruleName.replace('/', '-');
80
- }