@atlaskit/eslint-plugin-ui-styling-standard 0.8.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#88029](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88029) [`01d74d2899d5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01d74d2899d5) - Disabled ESlint rule convert-props-syntax on .attrs() calls
8
+ - [#87476](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87476) [`af296d200ad2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/af296d200ad2) - Internal refactoring to use `getCreateLintRule` from `@atlaskit/eslint-utils`
9
+ - Updated dependencies
10
+
3
11
  ## 0.8.0
4
12
 
5
13
  ### Minor Changes
@@ -382,6 +382,11 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
382
382
  return {
383
383
  'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
384
384
  var references = context.getScope().references;
385
+
386
+ // Rule should ignore .attrs() calls
387
+ if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
388
+ return;
389
+ }
385
390
  var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
386
391
  if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
387
392
  return;
@@ -3,41 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createRule = exports.createLintRule = void 0;
7
- exports.getPathSafeName = getPathSafeName;
6
+ exports.createLintRule = void 0;
8
7
  exports.getRuleUrl = getRuleUrl;
9
- var _utils = require("@typescript-eslint/utils");
10
- // eslint-disable-next-line import/no-extraneous-dependencies
11
-
12
- /**
13
- * We are moving to our own small abstraction to create a lint rule that we have the power
14
- * to change and mold to our own needs.
15
- *
16
- * @see createLintRule
17
- *
18
- * @private
19
- * @deprecated
20
- */
21
- var createRule = exports.createRule = _utils.ESLintUtils.RuleCreator(function (name) {
22
- return getRuleUrl(name);
23
- });
8
+ var _createRule = require("@atlaskit/eslint-utils/create-rule");
24
9
  /**
25
10
  * Tiny wrapped over the ESLint rule module type that ensures
26
11
  * there is a docs link to our ESLint plugin documentation page,
27
12
  * as well as improving type support.
28
13
  */
29
- var createLintRule = exports.createLintRule = function createLintRule(rule) {
30
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
31
- return rule;
32
- };
14
+ var createLintRule = exports.createLintRule = (0, _createRule.getCreateLintRule)(getRuleUrl);
33
15
  function getRuleUrl(ruleName) {
34
- var name = getPathSafeName(ruleName);
16
+ var name = (0, _createRule.getPathSafeName)(ruleName);
35
17
  return "https://atlassian.design/components/eslint-plugin-ui-styling-standard/".concat(name, "/usage");
36
- }
37
-
38
- /**
39
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
40
- */
41
- function getPathSafeName(ruleName) {
42
- return ruleName.replace('/', '-');
43
18
  }
@@ -278,6 +278,11 @@ export const rule = createLintRule({
278
278
  return {
279
279
  'CallExpression[callee.type="MemberExpression"]': node => {
280
280
  const references = context.getScope().references;
281
+
282
+ // Rule should ignore .attrs() calls
283
+ if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
284
+ return;
285
+ }
281
286
  const callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
282
287
  if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
283
288
  return;
@@ -1,33 +1,12 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies
1
+ import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
3
2
 
4
- /**
5
- * We are moving to our own small abstraction to create a lint rule that we have the power
6
- * to change and mold to our own needs.
7
- *
8
- * @see createLintRule
9
- *
10
- * @private
11
- * @deprecated
12
- */
13
- export const createRule = ESLintUtils.RuleCreator(name => getRuleUrl(name));
14
3
  /**
15
4
  * Tiny wrapped over the ESLint rule module type that ensures
16
5
  * there is a docs link to our ESLint plugin documentation page,
17
6
  * as well as improving type support.
18
7
  */
19
- export const createLintRule = rule => {
20
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
21
- return rule;
22
- };
8
+ export const createLintRule = getCreateLintRule(getRuleUrl);
23
9
  export function getRuleUrl(ruleName) {
24
10
  const name = getPathSafeName(ruleName);
25
11
  return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
26
- }
27
-
28
- /**
29
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
30
- */
31
- export function getPathSafeName(ruleName) {
32
- return ruleName.replace('/', '-');
33
12
  }
@@ -376,6 +376,11 @@ export var rule = createLintRule({
376
376
  return {
377
377
  'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
378
378
  var references = context.getScope().references;
379
+
380
+ // Rule should ignore .attrs() calls
381
+ if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
382
+ return;
383
+ }
379
384
  var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
380
385
  if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
381
386
  return;
@@ -1,35 +1,12 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies
1
+ import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
3
2
 
4
- /**
5
- * We are moving to our own small abstraction to create a lint rule that we have the power
6
- * to change and mold to our own needs.
7
- *
8
- * @see createLintRule
9
- *
10
- * @private
11
- * @deprecated
12
- */
13
- export var createRule = ESLintUtils.RuleCreator(function (name) {
14
- return getRuleUrl(name);
15
- });
16
3
  /**
17
4
  * Tiny wrapped over the ESLint rule module type that ensures
18
5
  * there is a docs link to our ESLint plugin documentation page,
19
6
  * as well as improving type support.
20
7
  */
21
- export var createLintRule = function createLintRule(rule) {
22
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
23
- return rule;
24
- };
8
+ export var createLintRule = getCreateLintRule(getRuleUrl);
25
9
  export function getRuleUrl(ruleName) {
26
10
  var name = getPathSafeName(ruleName);
27
11
  return "https://atlassian.design/components/eslint-plugin-ui-styling-standard/".concat(name, "/usage");
28
- }
29
-
30
- /**
31
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
32
- */
33
- export function getPathSafeName(ruleName) {
34
- return ruleName.replace('/', '-');
35
12
  }
@@ -1,4 +1,4 @@
1
- import { type LintRuleMeta } from './utils/create-rule';
1
+ import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
2
2
  /** External rules must be scoped, have a display name, and external urls. */
3
3
  export type ExternalRuleMeta = LintRuleMeta & {
4
4
  isExternal: true;
@@ -1,64 +1,7 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- import type { Rule } from 'eslint';
3
- /**
4
- * We are moving to our own small abstraction to create a lint rule that we have the power
5
- * to change and mold to our own needs.
6
- *
7
- * @see createLintRule
8
- *
9
- * @private
10
- * @deprecated
11
- */
12
- export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
13
- export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
14
- /**
15
- * Including this for backwards compat moving from the typescript-eslint util.
16
- */
17
- name?: never;
18
- meta: LintRuleMeta;
19
- }
20
- export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
21
- /**
22
- * Name of the rule.
23
- * Must match the folder it is in exactly else build will throw.
24
- * Add an exception in codegen.tsx for nested rules.
25
- */
26
- name: string;
27
- docs: {
28
- /**
29
- * Short description of what this rule does.
30
- */
31
- description: string;
32
- /**
33
- * Specifies the URL at which the full documentation can be accessed.
34
- */
35
- url?: string | undefined;
36
- /**
37
- * If this rule should be in the recommended preset or not.
38
- * Set to `false` to exclude it from the recommended preset.
39
- */
40
- recommended: boolean;
41
- /**
42
- * The severity level to be applied to this rule.
43
- * When setting to `"error"` it will mean releasing a breaking change.
44
- */
45
- severity: 'error' | 'warn';
46
- /**
47
- * This is configuration passed into the plugin to configure the rule.
48
- *
49
- * Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
50
- */
51
- pluginConfig?: Record<string, any>;
52
- };
53
- }
54
1
  /**
55
2
  * Tiny wrapped over the ESLint rule module type that ensures
56
3
  * there is a docs link to our ESLint plugin documentation page,
57
4
  * as well as improving type support.
58
5
  */
59
- export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
6
+ export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
60
7
  export declare function getRuleUrl(ruleName: string): string;
61
- /**
62
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
63
- */
64
- export declare function getPathSafeName(ruleName: string): string;
@@ -1,4 +1,4 @@
1
- import { type LintRuleMeta } from './utils/create-rule';
1
+ import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
2
2
  /** External rules must be scoped, have a display name, and external urls. */
3
3
  export type ExternalRuleMeta = LintRuleMeta & {
4
4
  isExternal: true;
@@ -1,64 +1,7 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- import type { Rule } from 'eslint';
3
- /**
4
- * We are moving to our own small abstraction to create a lint rule that we have the power
5
- * to change and mold to our own needs.
6
- *
7
- * @see createLintRule
8
- *
9
- * @private
10
- * @deprecated
11
- */
12
- export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
13
- export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
14
- /**
15
- * Including this for backwards compat moving from the typescript-eslint util.
16
- */
17
- name?: never;
18
- meta: LintRuleMeta;
19
- }
20
- export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
21
- /**
22
- * Name of the rule.
23
- * Must match the folder it is in exactly else build will throw.
24
- * Add an exception in codegen.tsx for nested rules.
25
- */
26
- name: string;
27
- docs: {
28
- /**
29
- * Short description of what this rule does.
30
- */
31
- description: string;
32
- /**
33
- * Specifies the URL at which the full documentation can be accessed.
34
- */
35
- url?: string | undefined;
36
- /**
37
- * If this rule should be in the recommended preset or not.
38
- * Set to `false` to exclude it from the recommended preset.
39
- */
40
- recommended: boolean;
41
- /**
42
- * The severity level to be applied to this rule.
43
- * When setting to `"error"` it will mean releasing a breaking change.
44
- */
45
- severity: 'error' | 'warn';
46
- /**
47
- * This is configuration passed into the plugin to configure the rule.
48
- *
49
- * Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
50
- */
51
- pluginConfig?: Record<string, any>;
52
- };
53
- }
54
1
  /**
55
2
  * Tiny wrapped over the ESLint rule module type that ensures
56
3
  * there is a docs link to our ESLint plugin documentation page,
57
4
  * as well as improving type support.
58
5
  */
59
- export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
6
+ export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
60
7
  export declare function getRuleUrl(ruleName: string): string;
61
- /**
62
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
63
- */
64
- export declare function getPathSafeName(ruleName: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  ".": "./src/index.tsx"
37
37
  },
38
38
  "dependencies": {
39
- "@atlaskit/eslint-utils": "^1.0.0",
39
+ "@atlaskit/eslint-utils": "^1.1.0",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "@typescript-eslint/utils": "^5.48.1",
42
42
  "eslint-codemod-utils": "^1.8.6",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@atlaskit/ds-lib": "^2.2.0",
48
- "@atlaskit/eslint-plugin-design-system": "^9.2.0",
48
+ "@atlaskit/eslint-plugin-design-system": "^9.3.0",
49
49
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
50
50
  "@atlassian/codegen": "*",
51
51
  "@compiled/eslint-plugin": "^0.13.6",
@@ -8,7 +8,10 @@ import { format, resolveConfig } from 'prettier';
8
8
 
9
9
  import { createSignedArtifact } from '@atlassian/codegen';
10
10
 
11
- import { type LintRule, getPathSafeName } from '../src/rules/utils/create-rule';
11
+ import {
12
+ type LintRule,
13
+ getPathSafeName,
14
+ } from '@atlaskit/eslint-utils/create-rule';
12
15
  import {
13
16
  externalRules,
14
17
  type ExternalRuleMeta,
@@ -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 & {
@@ -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
- }