@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.
- package/CHANGELOG.md +17 -0
- package/README.md +3 -1
- package/afm-cc/tsconfig.json +1 -2
- package/afm-jira/tsconfig.json +19 -19
- package/dist/cjs/index.js +40 -22
- package/dist/cjs/rules/compiled/expand-border-shorthand/index.js +100 -0
- package/dist/cjs/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
- package/dist/cjs/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
- package/dist/cjs/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
- package/dist/cjs/rules/{utils.js → feature-gating/utils.js} +1 -1
- package/dist/es2019/index.js +41 -20
- package/dist/es2019/rules/compiled/expand-border-shorthand/index.js +92 -0
- package/dist/es2019/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
- package/dist/es2019/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
- package/dist/es2019/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
- package/dist/es2019/rules/{utils.js → feature-gating/utils.js} +1 -1
- package/dist/esm/index.js +40 -22
- package/dist/esm/rules/compiled/expand-border-shorthand/index.js +94 -0
- package/dist/esm/rules/{no-alias → feature-gating/no-alias}/index.js +1 -1
- package/dist/esm/rules/{prefer-fg → feature-gating/prefer-fg}/index.js +1 -1
- package/dist/esm/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.js +1 -1
- package/dist/esm/rules/{utils.js → feature-gating/utils.js} +1 -1
- package/dist/types/index.d.ts +30 -6
- package/dist/types/rules/compiled/expand-border-shorthand/index.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +30 -6
- package/dist/types-ts4.5/rules/compiled/expand-border-shorthand/index.d.ts +3 -0
- package/package.json +6 -2
- package/src/index.tsx +45 -20
- package/src/rules/compiled/README.md +3 -0
- package/src/rules/compiled/expand-border-shorthand/README.md +51 -0
- package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +186 -0
- package/src/rules/compiled/expand-border-shorthand/index.ts +109 -0
- package/src/rules/feature-gating/README.md +8 -0
- package/src/rules/{inline-usage → feature-gating/inline-usage}/__tests__/rule.test.tsx +1 -1
- package/src/rules/{no-alias → feature-gating/no-alias}/__tests__/rule.test.tsx +1 -1
- package/src/rules/{no-alias → feature-gating/no-alias}/index.tsx +1 -1
- package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/__tests__/test.tsx +1 -1
- package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/__tests__/test.tsx +1 -1
- package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/__tests__/rule.test.tsx +1 -1
- package/src/rules/{prefer-fg → feature-gating/prefer-fg}/__tests__/rule.test.tsx +1 -1
- package/src/rules/{prefer-fg → feature-gating/prefer-fg}/index.tsx +1 -1
- package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/__tests__/test.tsx +1 -1
- package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.tsx +1 -1
- package/src/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/__tests__/rule.test.tsx +1 -1
- package/src/rules/{utils.tsx → feature-gating/utils.tsx} +1 -1
- /package/dist/cjs/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
- /package/dist/cjs/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
- /package/dist/cjs/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
- /package/dist/cjs/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
- /package/dist/cjs/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
- /package/dist/es2019/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
- /package/dist/es2019/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
- /package/dist/es2019/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
- /package/dist/es2019/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
- /package/dist/es2019/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
- /package/dist/esm/rules/{inline-usage → feature-gating/inline-usage}/index.js +0 -0
- /package/dist/esm/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js +0 -0
- /package/dist/esm/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.js +0 -0
- /package/dist/esm/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js +0 -0
- /package/dist/esm/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js +0 -0
- /package/dist/types/rules/{inline-usage → feature-gating/inline-usage}/index.d.ts +0 -0
- /package/dist/types/rules/{no-alias → feature-gating/no-alias}/index.d.ts +0 -0
- /package/dist/types/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.d.ts +0 -0
- /package/dist/types/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.d.ts +0 -0
- /package/dist/types/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts +0 -0
- /package/dist/types/rules/{prefer-fg → feature-gating/prefer-fg}/index.d.ts +0 -0
- /package/dist/types/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.d.ts +0 -0
- /package/dist/types/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.d.ts +0 -0
- /package/dist/types/rules/{utils.d.ts → feature-gating/utils.d.ts} +0 -0
- /package/dist/types-ts4.5/rules/{inline-usage → feature-gating/inline-usage}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-alias → feature-gating/no-alias}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{prefer-fg → feature-gating/prefer-fg}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{utils.d.ts → feature-gating/utils.d.ts} +0 -0
- /package/src/rules/{inline-usage → feature-gating/inline-usage}/README.md +0 -0
- /package/src/rules/{inline-usage → feature-gating/inline-usage}/index.tsx +0 -0
- /package/src/rules/{no-alias → feature-gating/no-alias}/README.md +0 -0
- /package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/README.md +0 -0
- /package/src/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.tsx +0 -0
- /package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/README.md +0 -0
- /package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.tsx +0 -0
- /package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/README.md +0 -0
- /package/src/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.tsx +0 -0
- /package/src/rules/{prefer-fg → feature-gating/prefer-fg}/README.md +0 -0
- /package/src/rules/{static-feature-flags → feature-gating/static-feature-flags}/README.md +0 -0
- /package/src/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/README.md +0 -0
- /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 type { Rule } from 'eslint';
|
|
2
|
-
import { FEATURE_API_IMPORT_SOURCES } from '
|
|
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([
|
|
File without changes
|
/package/dist/cjs/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/cjs/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/es2019/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/es2019/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.js
RENAMED
|
File without changes
|
/package/dist/es2019/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/esm/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/esm/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/types/rules/{no-module-level-eval → feature-gating/no-module-level-eval}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/types/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/types/rules/{static-feature-flags → feature-gating/static-feature-flags}/index.d.ts
RENAMED
|
File without changes
|
/package/dist/types/rules/{use-recommended-utils → feature-gating/use-recommended-utils}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/types-ts4.5/rules/{no-preconditioning → feature-gating/no-preconditioning}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/README.md
RENAMED
|
File without changes
|
/package/src/rules/{no-module-level-eval-nav4 → feature-gating/no-module-level-eval-nav4}/index.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|