@atlaskit/eslint-plugin-platform 0.12.0 → 0.13.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 (91) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +3 -1
  3. package/afm-cc/tsconfig.json +1 -2
  4. package/afm-jira/tsconfig.json +19 -19
  5. package/dist/cjs/index.js +40 -22
  6. package/dist/cjs/rules/compiled/expand-border-shorthand/index.js +100 -0
  7. package/dist/cjs/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
  8. package/dist/cjs/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
  9. package/dist/cjs/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
  10. package/dist/cjs/rules/{utils.js → feature-gating/utils.js} +1 -1
  11. package/dist/es2019/index.js +41 -20
  12. package/dist/es2019/rules/compiled/expand-border-shorthand/index.js +92 -0
  13. package/dist/es2019/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
  14. package/dist/es2019/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
  15. package/dist/es2019/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
  16. package/dist/es2019/rules/{utils.js → feature-gating/utils.js} +1 -1
  17. package/dist/esm/index.js +40 -22
  18. package/dist/esm/rules/compiled/expand-border-shorthand/index.js +94 -0
  19. package/dist/esm/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
  20. package/dist/esm/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
  21. package/dist/esm/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
  22. package/dist/esm/rules/{utils.js → feature-gating/utils.js} +1 -1
  23. package/dist/types/index.d.ts +30 -6
  24. package/dist/types/rules/compiled/expand-border-shorthand/index.d.ts +3 -0
  25. package/dist/types-ts4.5/index.d.ts +30 -6
  26. package/dist/types-ts4.5/rules/compiled/expand-border-shorthand/index.d.ts +3 -0
  27. package/package.json +6 -2
  28. package/src/index.tsx +45 -20
  29. package/src/rules/compiled/README.md +3 -0
  30. package/src/rules/compiled/expand-border-shorthand/README.md +51 -0
  31. package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +186 -0
  32. package/src/rules/compiled/expand-border-shorthand/index.ts +109 -0
  33. package/src/rules/feature-gating/README.md +8 -0
  34. package/src/rules/{inline-usage → feature-gating/inline-usage}/__tests__/rule.test.tsx +1 -1
  35. package/src/rules/{no-alias → feature-gating/no-alias}/__tests__/rule.test.tsx +1 -1
  36. package/src/rules/{no-alias → feature-gating/no-alias}/index.tsx +1 -1
  37. package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/__tests__/test.tsx +1 -1
  38. package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/__tests__/test.tsx +1 -1
  39. package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/__tests__/rule.test.tsx +1 -1
  40. package/src/rules/{prefer-fg → feature-gating/prefer-fg}/__tests__/rule.test.tsx +1 -1
  41. package/src/rules/{prefer-fg → feature-gating/prefer-fg}/index.tsx +1 -1
  42. package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/__tests__/test.tsx +1 -1
  43. package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.tsx +1 -1
  44. package/src/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/__tests__/rule.test.tsx +1 -1
  45. package/src/rules/{utils.tsx → feature-gating/utils.tsx} +1 -1
  46. /package/dist/cjs/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
  47. /package/dist/cjs/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
  48. /package/dist/cjs/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
  49. /package/dist/cjs/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
  50. /package/dist/cjs/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
  51. /package/dist/es2019/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
  52. /package/dist/es2019/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
  53. /package/dist/es2019/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
  54. /package/dist/es2019/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
  55. /package/dist/es2019/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
  56. /package/dist/esm/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
  57. /package/dist/esm/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
  58. /package/dist/esm/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
  59. /package/dist/esm/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
  60. /package/dist/esm/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
  61. /package/dist/types/rules/{inline-usage → feature-gating/inline-usage}/index.d.ts +0 -0
  62. /package/dist/types/rules/{no-alias → feature-gating/no-alias}/index.d.ts +0 -0
  63. /package/dist/types/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.d.ts +0 -0
  64. /package/dist/types/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.d.ts +0 -0
  65. /package/dist/types/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts +0 -0
  66. /package/dist/types/rules/{prefer-fg → feature-gating/prefer-fg}/index.d.ts +0 -0
  67. /package/dist/types/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.d.ts +0 -0
  68. /package/dist/types/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.d.ts +0 -0
  69. /package/dist/types/rules/{utils.d.ts → feature-gating/utils.d.ts} +0 -0
  70. /package/dist/types-ts4.5/rules/{inline-usage → feature-gating/inline-usage}/index.d.ts +0 -0
  71. /package/dist/types-ts4.5/rules/{no-alias → feature-gating/no-alias}/index.d.ts +0 -0
  72. /package/dist/types-ts4.5/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.d.ts +0 -0
  73. /package/dist/types-ts4.5/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.d.ts +0 -0
  74. /package/dist/types-ts4.5/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts +0 -0
  75. /package/dist/types-ts4.5/rules/{prefer-fg → feature-gating/prefer-fg}/index.d.ts +0 -0
  76. /package/dist/types-ts4.5/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.d.ts +0 -0
  77. /package/dist/types-ts4.5/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.d.ts +0 -0
  78. /package/dist/types-ts4.5/rules/{utils.d.ts → feature-gating/utils.d.ts} +0 -0
  79. /package/src/rules/{inline-usage → feature-gating/inline-usage}/README.md +0 -0
  80. /package/src/rules/{inline-usage → feature-gating/inline-usage}/index.tsx +0 -0
  81. /package/src/rules/{no-alias → feature-gating/no-alias}/README.md +0 -0
  82. /package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/README.md +0 -0
  83. /package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.tsx +0 -0
  84. /package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/README.md +0 -0
  85. /package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.tsx +0 -0
  86. /package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/README.md +0 -0
  87. /package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.tsx +0 -0
  88. /package/src/rules/{prefer-fg → feature-gating/prefer-fg}/README.md +0 -0
  89. /package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/README.md +0 -0
  90. /package/src/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/README.md +0 -0
  91. /package/src/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.tsx +0 -0
@@ -0,0 +1,109 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { Property, Node, ImportDeclaration, CallExpression } from 'estree';
3
+
4
+ const EXCLUDED_VALUES = ['0', 'none', 'unset', 'none !important'];
5
+
6
+ const findCallExpression = (node: Node & { parent?: Node }): CallExpression | null => {
7
+ const parent = node.parent;
8
+ if (!parent) {
9
+ return null;
10
+ }
11
+ if (parent.type === 'CallExpression') {
12
+ return parent;
13
+ }
14
+ return findCallExpression(parent);
15
+ };
16
+
17
+ const separateBorderProperties = (
18
+ borderString: string,
19
+ property: Property,
20
+ context: Rule.RuleContext,
21
+ ) => {
22
+ if (EXCLUDED_VALUES.includes(borderString)) {
23
+ return;
24
+ }
25
+
26
+ context.report({
27
+ node: property,
28
+ messageId: 'expandBorderShorthand',
29
+ });
30
+ };
31
+
32
+ // checks if the function that holds the border property is using an import package that this rule is targeting
33
+ const isCompiledAPI = (importDeclaration: ImportDeclaration, callExpression: CallExpression) => {
34
+ let functionName;
35
+ if (callExpression.callee.type === 'Identifier') {
36
+ functionName = callExpression.callee.name;
37
+ } else if (callExpression.callee.type === 'MemberExpression') {
38
+ if (callExpression.callee.object.type === 'Identifier') {
39
+ functionName = callExpression.callee.object.name;
40
+ }
41
+ }
42
+ if (!functionName) {
43
+ return;
44
+ }
45
+
46
+ return importDeclaration.specifiers.some(
47
+ (specifier) => specifier.type === 'ImportSpecifier' && specifier.imported.name === functionName,
48
+ );
49
+ };
50
+
51
+ export const expandBorderShorthand: Rule.RuleModule = {
52
+ meta: {
53
+ docs: {
54
+ url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-border-shorthand',
55
+ },
56
+ messages: {
57
+ expandBorderShorthand:
58
+ 'Use borderColor, borderStyle, and borderWidth instead of border shorthand',
59
+ },
60
+ type: 'problem',
61
+ },
62
+ create(context) {
63
+ let importDeclaration: ImportDeclaration;
64
+ return {
65
+ 'ImportDeclaration[source.value="@compiled/react"], ImportDeclaration[source.value="@atlaskit/css"]':
66
+ function (node: ImportDeclaration) {
67
+ importDeclaration = node;
68
+ },
69
+ 'Property[key.name="border"]': function (node: Property) {
70
+ const callExpression = findCallExpression(node);
71
+ if (!callExpression) {
72
+ return;
73
+ }
74
+ if (importDeclaration) {
75
+ if (isCompiledAPI(importDeclaration, callExpression)) {
76
+ if (node.value.type === 'Literal' && node.value.value !== null) {
77
+ if (typeof node.value.value === 'string') {
78
+ const borderString = node.value.value;
79
+ separateBorderProperties(borderString, node, context);
80
+ } else if (node.value.raw) {
81
+ const borderString = node.value.raw;
82
+ separateBorderProperties(borderString, node, context);
83
+ }
84
+ } else if (node.value.type === 'TemplateLiteral') {
85
+ if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
86
+ context.report({
87
+ node,
88
+ messageId: 'expandBorderShorthand',
89
+ });
90
+ return;
91
+ }
92
+ if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
93
+ const borderQuasis: string = node.value.quasis[0].value.cooked;
94
+ separateBorderProperties(borderQuasis, node, context);
95
+ }
96
+ } else if (node.value.type === 'CallExpression') {
97
+ context.report({
98
+ node,
99
+ messageId: 'expandBorderShorthand',
100
+ });
101
+ }
102
+ }
103
+ }
104
+ },
105
+ };
106
+ },
107
+ };
108
+
109
+ export default expandBorderShorthand;
@@ -0,0 +1,8 @@
1
+ ### Notes
2
+
3
+ - feature-gating/\* rules are copied from
4
+ [eslint-plugin-jira/rules/ff](https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/jira/build-tools/eslint-plugin-jira/rules/ff)
5
+ with small variations as mentioned in this
6
+ [PR](https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/115546/overview)
7
+ - these rules could be a WIP since they are still targeting JFE libraries- see
8
+ [discussion](https://atlassian.slack.com/archives/C026LTWFZ47/p1730776455371799?thread_ts=1730715221.742919&cid=C026LTWFZ47)
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  const options = ['ssOnly'];
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('feature-flags/no-alias', rule, {
@@ -3,7 +3,7 @@ import {
3
3
  FEATURE_API_IMPORT_SOURCES,
4
4
  FEATURE_MOCKS_IMPORT_SOURCES,
5
5
  FEATURE_UTILS_IMPORT_SOURCES,
6
- } from '../constants';
6
+ } from '../../constants';
7
7
  import { isIdentifierImportedFrom, type Node } from '../utils';
8
8
 
9
9
  const IMPORT_SOURCES = new Set([
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('feature-flags/no-module-level-eval', rule, {
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('feature-flags/no-module-level-eval', rule, {
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('feature-flags/no-preconditioning', rule, {
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  const errors = [{ messageId: 'autoFixImports' }, { messageId: 'preferFG' }];
@@ -1,6 +1,6 @@
1
1
  import type { Rule } from 'eslint';
2
2
 
3
- import { FEATURE_API_IMPORT_SOURCES } from '../constants';
3
+ import { FEATURE_API_IMPORT_SOURCES } from '../../constants';
4
4
  import { type Node } from '../utils';
5
5
 
6
6
  const validateUsage = (
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  const errors = [{ messageId: 'FFLiteral' }];
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import { FEATURE_API_IMPORT_SOURCES } from '../constants';
2
+ import { FEATURE_API_IMPORT_SOURCES } from '../../constants';
3
3
  import { getDef, isIdentifierImportedFrom, type Node } from '../utils';
4
4
 
5
5
  const IMPORT_SOURCES = new Set([
@@ -1,5 +1,5 @@
1
1
  import outdent from 'outdent';
2
- import { tester } from '../../../__tests__/utils/_tester';
2
+ import { tester } from '../../../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('feature-flags/use-recommended-utils', rule, {
@@ -1,4 +1,4 @@
1
- import { FEATURE_API_IMPORT_SOURCES } from './constants';
1
+ import { FEATURE_API_IMPORT_SOURCES } from '../constants';
2
2
  import type { Rule, Scope } from 'eslint';
3
3
 
4
4
  export function isIdentifierImportedFrom(