@atlaskit/eslint-plugin-platform 0.14.0 → 1.1.0
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 +22 -0
- package/afm-jira/tsconfig.json +5 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/rules/compiled/expand-background-shorthand/index.js +5 -5
- package/dist/cjs/rules/compiled/expand-border-shorthand/index.js +6 -13
- package/dist/cjs/rules/feature-gating/inline-usage/index.js +1 -1
- package/dist/cjs/rules/feature-gating/no-alias/index.js +1 -1
- package/dist/cjs/rules/feature-gating/no-module-level-eval/index.js +4 -3
- package/dist/cjs/rules/feature-gating/no-module-level-eval-nav4/index.js +4 -3
- package/dist/cjs/rules/feature-gating/no-preconditioning/index.js +1 -1
- package/dist/cjs/rules/feature-gating/prefer-fg/index.js +7 -6
- package/dist/cjs/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/cjs/rules/feature-gating/use-recommended-utils/index.js +2 -2
- package/dist/cjs/rules/feature-gating/utils.js +10 -9
- package/dist/cjs/rules/util/context-compat.js +33 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/rules/compiled/expand-background-shorthand/index.js +4 -4
- package/dist/es2019/rules/compiled/expand-border-shorthand/index.js +6 -13
- package/dist/es2019/rules/feature-gating/inline-usage/index.js +1 -1
- package/dist/es2019/rules/feature-gating/no-alias/index.js +1 -1
- package/dist/es2019/rules/feature-gating/no-module-level-eval/index.js +4 -3
- package/dist/es2019/rules/feature-gating/no-module-level-eval-nav4/index.js +4 -3
- package/dist/es2019/rules/feature-gating/no-preconditioning/index.js +1 -1
- package/dist/es2019/rules/feature-gating/prefer-fg/index.js +5 -4
- package/dist/es2019/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/es2019/rules/feature-gating/use-recommended-utils/index.js +2 -2
- package/dist/es2019/rules/feature-gating/utils.js +9 -8
- package/dist/es2019/rules/util/context-compat.js +27 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/rules/compiled/expand-background-shorthand/index.js +5 -5
- package/dist/esm/rules/compiled/expand-border-shorthand/index.js +6 -13
- package/dist/esm/rules/feature-gating/inline-usage/index.js +1 -1
- package/dist/esm/rules/feature-gating/no-alias/index.js +1 -1
- package/dist/esm/rules/feature-gating/no-module-level-eval/index.js +4 -3
- package/dist/esm/rules/feature-gating/no-module-level-eval-nav4/index.js +4 -3
- package/dist/esm/rules/feature-gating/no-preconditioning/index.js +1 -1
- package/dist/esm/rules/feature-gating/prefer-fg/index.js +7 -6
- package/dist/esm/rules/feature-gating/static-feature-flags/index.js +2 -2
- package/dist/esm/rules/feature-gating/use-recommended-utils/index.js +2 -2
- package/dist/esm/rules/feature-gating/utils.js +10 -9
- package/dist/esm/rules/util/context-compat.js +27 -0
- package/dist/types/rules/feature-gating/utils.d.ts +4 -3
- package/dist/types/rules/util/context-compat.d.ts +10 -0
- package/dist/types-ts4.5/rules/feature-gating/utils.d.ts +4 -3
- package/dist/types-ts4.5/rules/util/context-compat.d.ts +10 -0
- package/package.json +2 -5
- package/src/index.tsx +1 -1
- package/src/rules/compiled/expand-background-shorthand/__tests__/rule.test.ts +1 -1
- package/src/rules/compiled/expand-background-shorthand/index.tsx +4 -4
- package/src/rules/compiled/expand-border-shorthand/README.md +1 -1
- package/src/rules/compiled/expand-border-shorthand/__tests__/rule.test.ts +47 -22
- package/src/rules/compiled/expand-border-shorthand/index.ts +7 -13
- package/src/rules/feature-gating/inline-usage/index.tsx +1 -1
- package/src/rules/feature-gating/no-alias/index.tsx +6 -1
- package/src/rules/feature-gating/no-module-level-eval/index.tsx +8 -6
- package/src/rules/feature-gating/no-module-level-eval-nav4/index.tsx +6 -5
- package/src/rules/feature-gating/no-preconditioning/index.tsx +1 -1
- package/src/rules/feature-gating/prefer-fg/index.tsx +8 -6
- package/src/rules/feature-gating/static-feature-flags/index.tsx +2 -2
- package/src/rules/feature-gating/use-recommended-utils/index.tsx +2 -2
- package/src/rules/feature-gating/utils.tsx +8 -6
- package/src/rules/util/context-compat.ts +28 -0
- package/tsconfig.app.json +3 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: Consider whether this should be replaced by ESLint's compat library.
|
|
3
|
+
* Either way, this should be removed once we no longer need to support ESLint versions less than 8.40.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A compatibility layer to support older versions of ESLint.
|
|
8
|
+
* `context.sourceCode` is the preferred way to access SourceCode, as
|
|
9
|
+
* `context.getSourceCode()` is deprecated in v8 and removed in v9.
|
|
10
|
+
* @param context - The ESLint rule context
|
|
11
|
+
*/
|
|
12
|
+
const getSourceCode = context => {
|
|
13
|
+
var _context$sourceCode;
|
|
14
|
+
return (_context$sourceCode = context.sourceCode) !== null && _context$sourceCode !== void 0 ? _context$sourceCode : context.getSourceCode();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A compatibility layer to support older versions of ESLint.
|
|
19
|
+
* `context.sourceCode.getScope()` is the preferred way to access Scope, as
|
|
20
|
+
* `context.getScope()` was removed in v9.
|
|
21
|
+
* @param context - The ESLint rule context
|
|
22
|
+
* @param node - The node to get the scope for
|
|
23
|
+
*/
|
|
24
|
+
export const getScope = (context, node) => {
|
|
25
|
+
var _getSourceCode$getSco, _getSourceCode;
|
|
26
|
+
return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : _getSourceCode.getScope(node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
|
|
27
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -63,7 +63,7 @@ var commonConfig = {
|
|
|
63
63
|
'@atlaskit/platform/ensure-atlassian-team': 'error',
|
|
64
64
|
'@atlaskit/platform/no-module-level-eval-nav4': 'error',
|
|
65
65
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
66
|
-
'@atlaskit/platform/expand-border-shorthand': '
|
|
66
|
+
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
67
67
|
'@atlaskit/platform/expand-background-shorthand': 'warn',
|
|
68
68
|
'@compiled/jsx-pragma': ['error', {
|
|
69
69
|
importSources: ['@atlaskit/css'],
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getImportSources, isCompiled, isAtlasKitCSS } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { getScope } from '../../util/context-compat';
|
|
2
3
|
|
|
3
4
|
// Checks if the function that holds the border property is using an import package that this rule is targeting
|
|
4
|
-
var isCompiledAPI = function isCompiledAPI(context) {
|
|
5
|
+
var isCompiledAPI = function isCompiledAPI(context, node) {
|
|
5
6
|
var importSources = getImportSources(context);
|
|
6
|
-
var
|
|
7
|
-
references =
|
|
7
|
+
var _getScope = getScope(context, node),
|
|
8
|
+
references = _getScope.references;
|
|
8
9
|
var ancestors = context.getAncestors();
|
|
9
10
|
if (ancestors.some(function (ancestor) {
|
|
10
11
|
return ancestor.type === 'CallExpression' && ancestor.callee && (isCompiled(ancestor.callee, references, importSources) || isAtlasKitCSS(ancestor.callee, references, importSources));
|
|
@@ -37,7 +38,7 @@ export var expandBackgroundShorthand = {
|
|
|
37
38
|
create: function create(context) {
|
|
38
39
|
return {
|
|
39
40
|
'Property[key.name="background"]': function PropertyKeyNameBackground(node) {
|
|
40
|
-
if (isCompiledAPI(context) && isTokenCallExpression(node.value)) {
|
|
41
|
+
if (isCompiledAPI(context, node) && isTokenCallExpression(node.value)) {
|
|
41
42
|
context.report({
|
|
42
43
|
node: node,
|
|
43
44
|
messageId: 'expandBackgroundShorthand',
|
|
@@ -45,7 +46,6 @@ export var expandBackgroundShorthand = {
|
|
|
45
46
|
return fixer.replaceText(node.key, "backgroundColor");
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
|
-
return;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
};
|
|
@@ -13,6 +13,9 @@ var separateBorderProperties = function separateBorderProperties(borderString, p
|
|
|
13
13
|
if (EXCLUDED_VALUES.includes(borderString)) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
+
if (borderString.includes('var(--')) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
16
19
|
context.report({
|
|
17
20
|
node: property,
|
|
18
21
|
messageId: 'expandBorderShorthand'
|
|
@@ -33,7 +36,7 @@ var isCompiledAPI = function isCompiledAPI(importDeclaration, callExpression) {
|
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
38
|
return importDeclaration.specifiers.some(function (specifier) {
|
|
36
|
-
return specifier.type === 'ImportSpecifier' && specifier.
|
|
39
|
+
return specifier.type === 'ImportSpecifier' && specifier.local.name === functionName;
|
|
37
40
|
});
|
|
38
41
|
};
|
|
39
42
|
export var expandBorderShorthand = {
|
|
@@ -60,21 +63,11 @@ export var expandBorderShorthand = {
|
|
|
60
63
|
if (importDeclaration) {
|
|
61
64
|
if (isCompiledAPI(importDeclaration, callExpression)) {
|
|
62
65
|
if (node.value.type === 'Literal' && node.value.value !== null) {
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
var borderString = typeof node.value.value === 'string' ? node.value.value : node.value.raw;
|
|
67
|
+
if (borderString) {
|
|
65
68
|
separateBorderProperties(borderString, node, context);
|
|
66
|
-
} else if (node.value.raw) {
|
|
67
|
-
var _borderString = node.value.raw;
|
|
68
|
-
separateBorderProperties(_borderString, node, context);
|
|
69
69
|
}
|
|
70
70
|
} else if (node.value.type === 'TemplateLiteral') {
|
|
71
|
-
if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
|
|
72
|
-
context.report({
|
|
73
|
-
node: node,
|
|
74
|
-
messageId: 'expandBorderShorthand'
|
|
75
|
-
});
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
71
|
if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
|
|
79
72
|
var borderQuasis = node.value.quasis[0].value.cooked;
|
|
80
73
|
separateBorderProperties(borderQuasis, node, context);
|
|
@@ -8,7 +8,7 @@ var findDefinitionDeclaration = function findDefinitionDeclaration(node) {
|
|
|
8
8
|
var validateCallExpression = function validateCallExpression(node, context) {
|
|
9
9
|
var targetedFunctionsSwitch = context.options[0] === 'ssOnly' ? STATSIG_ONLY_FUNCTION_NAMES : FUNCTION_NAMES;
|
|
10
10
|
var callee = node.callee;
|
|
11
|
-
var shouldWarn = callee.type === 'Identifier' && targetedFunctionsSwitch.has(callee.name) && isAPIimport(callee.name, context);
|
|
11
|
+
var shouldWarn = callee.type === 'Identifier' && targetedFunctionsSwitch.has(callee.name) && isAPIimport(callee.name, context, node);
|
|
12
12
|
if (shouldWarn) {
|
|
13
13
|
var defDeclaration = findDefinitionDeclaration(node.parent);
|
|
14
14
|
context.report({
|
|
@@ -43,7 +43,7 @@ var rule = {
|
|
|
43
43
|
if (!node.init || node.init.type !== 'Identifier') {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
var isReassignment = isIdentifierImportedFrom(node.init.name, IMPORT_SOURCES, context);
|
|
46
|
+
var isReassignment = isIdentifierImportedFrom(node.init.name, IMPORT_SOURCES, context, node);
|
|
47
47
|
if (isReassignment) {
|
|
48
48
|
context.report({
|
|
49
49
|
messageId: 'noReassignment',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isAPIimport } from '../utils';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { getScope } from '../../util/context-compat';
|
|
3
|
+
var isInFunctionLevel = function isInFunctionLevel(context, node) {
|
|
4
|
+
var scope = getScope(context, node);
|
|
4
5
|
while (((_scope = scope) === null || _scope === void 0 ? void 0 : _scope.type) !== 'module' && ((_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2.type) !== 'global') {
|
|
5
6
|
var _scope, _scope2;
|
|
6
7
|
if (scope.type === 'function') {
|
|
@@ -26,7 +27,7 @@ var rule = {
|
|
|
26
27
|
create: function create(context) {
|
|
27
28
|
return {
|
|
28
29
|
'CallExpression[callee.type="Identifier"]': function CallExpressionCalleeTypeIdentifier(node) {
|
|
29
|
-
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && isAPIimport(node.callee.name, context) && !isInFunctionLevel(context)) {
|
|
30
|
+
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && isAPIimport(node.callee.name, context, node) && !isInFunctionLevel(context, node)) {
|
|
30
31
|
context.report({
|
|
31
32
|
messageId: 'noModuleLevelEval',
|
|
32
33
|
node: node
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getScope } from '../../util/context-compat';
|
|
1
2
|
var featureLibraryFunctions = new Set([
|
|
2
3
|
/*
|
|
3
4
|
* STOP!
|
|
@@ -10,8 +11,8 @@ var featureLibraryFunctions = new Set([
|
|
|
10
11
|
* Slack thread: https://atlassian.slack.com/archives/CFGLH1ZS8/p1726449739284819
|
|
11
12
|
*/
|
|
12
13
|
'isVisualRefreshEnabled', 'getMetaBoolean', 'getNav4Rollout', 'getWillShowNav3', 'getWillShowNav4', 'getWillShowNav4UserOptIn', 'getWillShowNav4UserOptOut']);
|
|
13
|
-
var isInFunctionLevel = function isInFunctionLevel(context) {
|
|
14
|
-
var scope =
|
|
14
|
+
var isInFunctionLevel = function isInFunctionLevel(context, node) {
|
|
15
|
+
var scope = getScope(context, node);
|
|
15
16
|
while (((_scope = scope) === null || _scope === void 0 ? void 0 : _scope.type) !== 'module' && ((_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2.type) !== 'global') {
|
|
16
17
|
var _scope, _scope2;
|
|
17
18
|
if (scope.type === 'function') {
|
|
@@ -37,7 +38,7 @@ var rule = {
|
|
|
37
38
|
create: function create(context) {
|
|
38
39
|
return {
|
|
39
40
|
'CallExpression[callee.type="Identifier"]': function CallExpressionCalleeTypeIdentifier(node) {
|
|
40
|
-
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && featureLibraryFunctions.has(node.callee.name) && !isInFunctionLevel(context)) {
|
|
41
|
+
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && featureLibraryFunctions.has(node.callee.name) && !isInFunctionLevel(context, node)) {
|
|
41
42
|
context.report({
|
|
42
43
|
messageId: 'noModuleLevelEval',
|
|
43
44
|
node: node
|
|
@@ -14,7 +14,7 @@ var getGateType = function getGateType(node, context) {
|
|
|
14
14
|
var callee = node.callee;
|
|
15
15
|
var isFeatureGate = type === 'CallExpression' && callee.type === 'Identifier' && (
|
|
16
16
|
// Experiments cannot have other experiments as preconditions, only gates
|
|
17
|
-
callee.name === 'fg' || isExpUsage(callee.name)) && isAPIimport(callee.name, context);
|
|
17
|
+
callee.name === 'fg' || isExpUsage(callee.name)) && isAPIimport(callee.name, context, node);
|
|
18
18
|
return isFeatureGate ? callee.name : '';
|
|
19
19
|
}
|
|
20
20
|
return '';
|
|
@@ -4,11 +4,12 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
6
|
import { FEATURE_API_IMPORT_SOURCES } from '../../constants';
|
|
7
|
+
import { getScope } from '../../util/context-compat';
|
|
7
8
|
var validateUsage = function validateUsage(node, utilName, context, changeMap) {
|
|
8
|
-
var
|
|
9
|
-
var resolved = (
|
|
9
|
+
var _getScope$references$;
|
|
10
|
+
var resolved = (_getScope$references$ = getScope(context, node).references.find(function (ref) {
|
|
10
11
|
return ref.identifier.name === utilName;
|
|
11
|
-
})) === null ||
|
|
12
|
+
})) === null || _getScope$references$ === void 0 ? void 0 : _getScope$references$.resolved;
|
|
12
13
|
var importSpecifierDefinition = resolved === null || resolved === void 0 ? void 0 : resolved.defs.find(function (def) {
|
|
13
14
|
var _def$node, _def$parent;
|
|
14
15
|
return ((_def$node = def.node) === null || _def$node === void 0 ? void 0 : _def$node.type) === 'ImportSpecifier' && FEATURE_API_IMPORT_SOURCES.has((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.source.value);
|
|
@@ -65,12 +66,12 @@ var rule = {
|
|
|
65
66
|
changeMap = changeMap || new Map();
|
|
66
67
|
validateUsage(node, 'getBooleanFF', context, changeMap);
|
|
67
68
|
},
|
|
68
|
-
'Program:exit': function ProgramExit() {
|
|
69
|
+
'Program:exit': function ProgramExit(node) {
|
|
69
70
|
var _changeMap;
|
|
70
71
|
if ((_changeMap = changeMap) !== null && _changeMap !== void 0 && _changeMap.size) {
|
|
71
72
|
changeMap.forEach(function (changeCounts, importDeclaration) {
|
|
72
|
-
var
|
|
73
|
-
moduleScope =
|
|
73
|
+
var _getScope$childScopes = _slicedToArray(getScope(context, node).childScopes, 1),
|
|
74
|
+
moduleScope = _getScope$childScopes[0];
|
|
74
75
|
var importSpecifiers = new Set(importDeclaration.specifiers.map(function (_ref) {
|
|
75
76
|
var imported = _ref.imported;
|
|
76
77
|
return imported.name;
|
|
@@ -26,12 +26,12 @@ var rule = {
|
|
|
26
26
|
if (node.type !== 'CallExpression') {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
if (node.callee.type === 'Identifier' && (!targetedFunctionsSwitch.has(node.callee.name) || !isIdentifierImportedFrom(node.callee.name, IMPORT_SOURCES, context))) {
|
|
29
|
+
if (node.callee.type === 'Identifier' && (!targetedFunctionsSwitch.has(node.callee.name) || !isIdentifierImportedFrom(node.callee.name, IMPORT_SOURCES, context, node))) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
var nameArgument = node.arguments[0];
|
|
33
33
|
if (nameArgument.type === 'Identifier') {
|
|
34
|
-
var def = getDef(nameArgument.name, context);
|
|
34
|
+
var def = getDef(nameArgument.name, context, node);
|
|
35
35
|
if (def != null && def.type === 'Variable') {
|
|
36
36
|
var _ref = def.node.init,
|
|
37
37
|
value = _ref.value;
|
|
@@ -15,7 +15,7 @@ var rule = {
|
|
|
15
15
|
create: function create(context) {
|
|
16
16
|
return {
|
|
17
17
|
'CallExpression > MemberExpression:matches([property.name="checkGate"])': function CallExpressionMemberExpressionMatchesPropertyNameCheckGate(node) {
|
|
18
|
-
if (node.object.type === 'Identifier' && isIdentifierImportedFrom(node.object.name, BANNED_IMPORTS_SET, context)) {
|
|
18
|
+
if (node.object.type === 'Identifier' && isIdentifierImportedFrom(node.object.name, BANNED_IMPORTS_SET, context, node)) {
|
|
19
19
|
context.report({
|
|
20
20
|
messageId: 'useRecommended',
|
|
21
21
|
node: node,
|
|
@@ -28,7 +28,7 @@ var rule = {
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
'CallExpression > MemberExpression:matches([property.name="getExperimentValue"])': function CallExpressionMemberExpressionMatchesPropertyNameGetExperimentValue(node) {
|
|
31
|
-
if (node.object.type === 'Identifier' && isIdentifierImportedFrom(node.object.name, BANNED_IMPORTS_SET, context)) {
|
|
31
|
+
if (node.object.type === 'Identifier' && isIdentifierImportedFrom(node.object.name, BANNED_IMPORTS_SET, context, node)) {
|
|
32
32
|
context.report({
|
|
33
33
|
messageId: 'notSupported',
|
|
34
34
|
node: node
|
|
@@ -2,25 +2,26 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
import { FEATURE_API_IMPORT_SOURCES } from '../constants';
|
|
5
|
-
|
|
5
|
+
import { getScope } from '../util/context-compat';
|
|
6
|
+
export function isIdentifierImportedFrom(identifierName, sources, context, node) {
|
|
6
7
|
if (sources.size > 0) {
|
|
7
|
-
var
|
|
8
|
-
return (
|
|
8
|
+
var _getScope$references$, _getScope$references$2;
|
|
9
|
+
return (_getScope$references$ = (_getScope$references$2 = getScope(context, node).references.find(function (ref) {
|
|
9
10
|
return ref.identifier.name === identifierName;
|
|
10
|
-
})) === null ||
|
|
11
|
+
})) === null || _getScope$references$2 === void 0 || (_getScope$references$2 = _getScope$references$2.resolved) === null || _getScope$references$2 === void 0 ? void 0 : _getScope$references$2.defs.some(function (def) {
|
|
11
12
|
var _def$parent;
|
|
12
13
|
return ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && sources.has(def.parent.source.value + '');
|
|
13
|
-
})) !== null &&
|
|
14
|
+
})) !== null && _getScope$references$ !== void 0 ? _getScope$references$ : false;
|
|
14
15
|
}
|
|
15
16
|
return false;
|
|
16
17
|
}
|
|
17
|
-
export function isAPIimport(functionName, context) {
|
|
18
|
-
return isIdentifierImportedFrom(functionName, FEATURE_API_IMPORT_SOURCES, context);
|
|
18
|
+
export function isAPIimport(functionName, context, node) {
|
|
19
|
+
return isIdentifierImportedFrom(functionName, FEATURE_API_IMPORT_SOURCES, context, node);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
// returns the definition node of a variable if it's declared within the scope of the file
|
|
22
|
-
export function getDef(name, context) {
|
|
23
|
-
var scope =
|
|
23
|
+
export function getDef(name, context, node) {
|
|
24
|
+
var scope = getScope(context, node);
|
|
24
25
|
while (scope && scope.type !== 'global') {
|
|
25
26
|
var _iterator = _createForOfIteratorHelper(scope.variables),
|
|
26
27
|
_step;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: Consider whether this should be replaced by ESLint's compat library.
|
|
3
|
+
* Either way, this should be removed once we no longer need to support ESLint versions less than 8.40.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A compatibility layer to support older versions of ESLint.
|
|
8
|
+
* `context.sourceCode` is the preferred way to access SourceCode, as
|
|
9
|
+
* `context.getSourceCode()` is deprecated in v8 and removed in v9.
|
|
10
|
+
* @param context - The ESLint rule context
|
|
11
|
+
*/
|
|
12
|
+
var getSourceCode = function getSourceCode(context) {
|
|
13
|
+
var _context$sourceCode;
|
|
14
|
+
return (_context$sourceCode = context.sourceCode) !== null && _context$sourceCode !== void 0 ? _context$sourceCode : context.getSourceCode();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A compatibility layer to support older versions of ESLint.
|
|
19
|
+
* `context.sourceCode.getScope()` is the preferred way to access Scope, as
|
|
20
|
+
* `context.getScope()` was removed in v9.
|
|
21
|
+
* @param context - The ESLint rule context
|
|
22
|
+
* @param node - The node to get the scope for
|
|
23
|
+
*/
|
|
24
|
+
export var getScope = function getScope(context, node) {
|
|
25
|
+
var _getSourceCode$getSco, _getSourceCode;
|
|
26
|
+
return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : _getSourceCode.getScope(node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
|
|
27
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Rule, Scope } from 'eslint';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
2
|
+
import type { Node as EstreeNode } from 'estree';
|
|
3
|
+
export declare function isIdentifierImportedFrom(identifierName: string, sources: Set<string>, context: Rule.RuleContext, node: EstreeNode): boolean;
|
|
4
|
+
export declare function isAPIimport(functionName: string, context: Rule.RuleContext, node: EstreeNode): boolean;
|
|
5
|
+
export declare function getDef(name: string, context: Rule.RuleContext, node: EstreeNode): Scope.Definition | null | undefined;
|
|
5
6
|
export type Node<T extends Rule.Node['type']> = Extract<Rule.Node, {
|
|
6
7
|
type: T;
|
|
7
8
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Rule, Scope } from 'eslint';
|
|
2
|
+
import type { Node } from 'estree';
|
|
3
|
+
/**
|
|
4
|
+
* A compatibility layer to support older versions of ESLint.
|
|
5
|
+
* `context.sourceCode.getScope()` is the preferred way to access Scope, as
|
|
6
|
+
* `context.getScope()` was removed in v9.
|
|
7
|
+
* @param context - The ESLint rule context
|
|
8
|
+
* @param node - The node to get the scope for
|
|
9
|
+
*/
|
|
10
|
+
export declare const getScope: (context: Rule.RuleContext, node: Node) => Scope.Scope;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Rule, Scope } from 'eslint';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
2
|
+
import type { Node as EstreeNode } from 'estree';
|
|
3
|
+
export declare function isIdentifierImportedFrom(identifierName: string, sources: Set<string>, context: Rule.RuleContext, node: EstreeNode): boolean;
|
|
4
|
+
export declare function isAPIimport(functionName: string, context: Rule.RuleContext, node: EstreeNode): boolean;
|
|
5
|
+
export declare function getDef(name: string, context: Rule.RuleContext, node: EstreeNode): Scope.Definition | null | undefined;
|
|
5
6
|
export type Node<T extends Rule.Node['type']> = Extract<Rule.Node, {
|
|
6
7
|
type: T;
|
|
7
8
|
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Rule, Scope } from 'eslint';
|
|
2
|
+
import type { Node } from 'estree';
|
|
3
|
+
/**
|
|
4
|
+
* A compatibility layer to support older versions of ESLint.
|
|
5
|
+
* `context.sourceCode.getScope()` is the preferred way to access Scope, as
|
|
6
|
+
* `context.getScope()` was removed in v9.
|
|
7
|
+
* @param context - The ESLint rule context
|
|
8
|
+
* @param node - The node to get the scope for
|
|
9
|
+
*/
|
|
10
|
+
export declare const getScope: (context: Rule.RuleContext, node: Node) => Scope.Scope;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-platform",
|
|
3
3
|
"description": "The essential plugin for use with Atlassian frontend platform tools",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "Build Infra",
|
|
@@ -33,18 +33,15 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/eslint-utils": "^1.7.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
|
+
"@compiled/eslint-plugin": "^0.17.0",
|
|
36
37
|
"@manypkg/find-root": "^1.1.0",
|
|
37
38
|
"fuse.js": "^6.6.2",
|
|
38
39
|
"read-pkg-up": "^7.0.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@atlassian/ts-loader": "*",
|
|
42
|
-
"@compiled/eslint-plugin": "^0.17.0",
|
|
43
43
|
"@types/eslint": "^8.56.6",
|
|
44
44
|
"eslint": "^8.57.0",
|
|
45
45
|
"outdent": "^0.5.0"
|
|
46
|
-
},
|
|
47
|
-
"peerDependencies": {
|
|
48
|
-
"@compiled/eslint-plugin": "^0.17.0"
|
|
49
46
|
}
|
|
50
47
|
}
|
package/src/index.tsx
CHANGED
|
@@ -62,7 +62,7 @@ const commonConfig = {
|
|
|
62
62
|
'@atlaskit/platform/ensure-atlassian-team': 'error',
|
|
63
63
|
'@atlaskit/platform/no-module-level-eval-nav4': 'error',
|
|
64
64
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
65
|
-
'@atlaskit/platform/expand-border-shorthand': '
|
|
65
|
+
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
66
66
|
'@atlaskit/platform/expand-background-shorthand': 'warn',
|
|
67
67
|
'@compiled/jsx-pragma': [
|
|
68
68
|
'error',
|
|
@@ -5,11 +5,12 @@ import {
|
|
|
5
5
|
isCompiled,
|
|
6
6
|
isAtlasKitCSS,
|
|
7
7
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
8
|
+
import { getScope } from '../../util/context-compat';
|
|
8
9
|
|
|
9
10
|
// Checks if the function that holds the border property is using an import package that this rule is targeting
|
|
10
|
-
const isCompiledAPI = (context: Rule.RuleContext): boolean => {
|
|
11
|
+
const isCompiledAPI = (context: Rule.RuleContext, node: Node): boolean => {
|
|
11
12
|
const importSources = getImportSources(context);
|
|
12
|
-
const { references } =
|
|
13
|
+
const { references } = getScope(context, node);
|
|
13
14
|
const ancestors = context.getAncestors();
|
|
14
15
|
if (
|
|
15
16
|
ancestors.some(
|
|
@@ -49,7 +50,7 @@ export const expandBackgroundShorthand: Rule.RuleModule = {
|
|
|
49
50
|
create(context) {
|
|
50
51
|
return {
|
|
51
52
|
'Property[key.name="background"]': function (node: Property) {
|
|
52
|
-
if (isCompiledAPI(context) && isTokenCallExpression(node.value)) {
|
|
53
|
+
if (isCompiledAPI(context, node) && isTokenCallExpression(node.value)) {
|
|
53
54
|
context.report({
|
|
54
55
|
node,
|
|
55
56
|
messageId: 'expandBackgroundShorthand',
|
|
@@ -57,7 +58,6 @@ export const expandBackgroundShorthand: Rule.RuleModule = {
|
|
|
57
58
|
return fixer.replaceText(node.key, `backgroundColor`);
|
|
58
59
|
},
|
|
59
60
|
});
|
|
60
|
-
return;
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `shorthand-property-sorting`
|
|
2
2
|
|
|
3
|
-
This ESLint rule enforces the expansion of CSS `border` shorthand property, into
|
|
3
|
+
This ESLint rule enforces the expansion of CSS `border` shorthand property, into its longhand
|
|
4
4
|
equivalents `borderStyle`, `borderWidth`, `borderColor`, for packages that originates from
|
|
5
5
|
`@compiled/react`, and `@atlaskit/css`.
|
|
6
6
|
|
|
@@ -3,15 +3,13 @@ import { outdent } from 'outdent';
|
|
|
3
3
|
import { tester } from '../../../../__tests__/utils/_tester';
|
|
4
4
|
import { expandBorderShorthand } from '../index';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const included_packages_calls_and_imports = [
|
|
7
7
|
['css', 'css', '@atlaskit/css'],
|
|
8
8
|
['css', 'css', '@compiled/react'],
|
|
9
9
|
['styled', 'styled.div', '@compiled/react'],
|
|
10
|
-
['cssMap', 'cssMap', '@atlaskit/css'],
|
|
11
|
-
['cssMap', 'cssMap', '@compiled/react'],
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
const
|
|
12
|
+
const exempt_packages_calls_and_imports = [
|
|
15
13
|
['css', '@atlaskit/primitives'],
|
|
16
14
|
['css', '@emotion'],
|
|
17
15
|
['css', 'styled-components'],
|
|
@@ -19,8 +17,8 @@ const invalid_packages_calls_and_imports = [
|
|
|
19
17
|
|
|
20
18
|
tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
21
19
|
valid: [
|
|
22
|
-
...
|
|
23
|
-
name: `
|
|
20
|
+
...exempt_packages_calls_and_imports.map(([pkg, imp]) => ({
|
|
21
|
+
name: `handle only Compiled APIs (${pkg}, ${imp})`,
|
|
24
22
|
code: outdent`
|
|
25
23
|
import {${pkg}} from '${imp}';
|
|
26
24
|
|
|
@@ -30,13 +28,18 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
30
28
|
`,
|
|
31
29
|
})),
|
|
32
30
|
{
|
|
33
|
-
name: '
|
|
31
|
+
name: 'CallExpression matches with imported API',
|
|
34
32
|
code: outdent`
|
|
35
|
-
import {
|
|
33
|
+
import { styled } from 'styled-components';
|
|
34
|
+
import { styled as styled2, css as compiledCSS, jsx } from '@compiled/react';
|
|
36
35
|
|
|
37
36
|
const styles = xcss({
|
|
38
37
|
border: '1px solid red',
|
|
39
38
|
});
|
|
39
|
+
|
|
40
|
+
const styles2 = styled.div({
|
|
41
|
+
border: '1px solid red',
|
|
42
|
+
});
|
|
40
43
|
`,
|
|
41
44
|
},
|
|
42
45
|
{
|
|
@@ -71,6 +74,17 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
71
74
|
const styles9 = css({
|
|
72
75
|
border: 0,
|
|
73
76
|
});
|
|
77
|
+
const styles10 = css({
|
|
78
|
+
border: 'var(--icon-border)',
|
|
79
|
+
});
|
|
80
|
+
const styles11 = css({
|
|
81
|
+
border: \`\${(props: { border?: boolean }) =>
|
|
82
|
+
props.border ? \`1px solid \${token('color.border.disabled', colors.N30)}\` : 'none'}\`,
|
|
83
|
+
});
|
|
84
|
+
const styles12 = css({
|
|
85
|
+
border: (props: { border?: boolean }) =>
|
|
86
|
+
props.border ? token('color.border.disabled', colors.N30) : 'none',
|
|
87
|
+
});
|
|
74
88
|
`,
|
|
75
89
|
},
|
|
76
90
|
{
|
|
@@ -91,9 +105,20 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
91
105
|
});
|
|
92
106
|
`,
|
|
93
107
|
},
|
|
108
|
+
{
|
|
109
|
+
name: 'cssMap case where border is assigned an ObjectExpression',
|
|
110
|
+
code: outdent`
|
|
111
|
+
import { cssMap } from '@compiled/react';
|
|
112
|
+
|
|
113
|
+
const borderStyleMap = cssMap({
|
|
114
|
+
none: { borderStyle: 'none' },
|
|
115
|
+
border: { borderStyle: 'solid' },
|
|
116
|
+
});
|
|
117
|
+
`,
|
|
118
|
+
},
|
|
94
119
|
],
|
|
95
120
|
invalid: [
|
|
96
|
-
...
|
|
121
|
+
...included_packages_calls_and_imports.map(([pkg, call, imp]) => ({
|
|
97
122
|
name: `simple case (${call}, ${imp})`,
|
|
98
123
|
code: outdent`
|
|
99
124
|
import {${pkg}} from '${imp}';
|
|
@@ -147,14 +172,6 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
147
172
|
border: \`1px solid red\`,
|
|
148
173
|
})
|
|
149
174
|
|
|
150
|
-
const styles2 = css({
|
|
151
|
-
border: \`1px solid \${token('red')}\`,
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
const styles3 = css({
|
|
155
|
-
border: \`1px \${solid} red\`,
|
|
156
|
-
})
|
|
157
|
-
|
|
158
175
|
const styles4 = css({
|
|
159
176
|
border: \`1px red\`,
|
|
160
177
|
})
|
|
@@ -162,12 +179,8 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
162
179
|
const styles5 = css({
|
|
163
180
|
border: \`1px\`,
|
|
164
181
|
})
|
|
165
|
-
|
|
166
|
-
const styles6 = css({
|
|
167
|
-
border: \` \${token('red')}\`,
|
|
168
|
-
})
|
|
169
182
|
`,
|
|
170
|
-
errors: Array.from(Array(
|
|
183
|
+
errors: Array.from(Array(3), () => ({ messageId: 'expandBorderShorthand' })),
|
|
171
184
|
},
|
|
172
185
|
{
|
|
173
186
|
name: 'tokens',
|
|
@@ -182,5 +195,17 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
|
|
|
182
195
|
`,
|
|
183
196
|
errors: Array.from(Array(2), () => ({ messageId: 'expandBorderShorthand' })),
|
|
184
197
|
},
|
|
198
|
+
{
|
|
199
|
+
name: 'cssMap case where border is assigned an a Literal',
|
|
200
|
+
code: outdent`
|
|
201
|
+
import { cssMap } from '@compiled/react';
|
|
202
|
+
|
|
203
|
+
const borderStyleMap = cssMap({
|
|
204
|
+
none: { border: 'none' },
|
|
205
|
+
solid: { border: '1px solid blue' },
|
|
206
|
+
});
|
|
207
|
+
`,
|
|
208
|
+
errors: [{ messageId: 'expandBorderShorthand' }],
|
|
209
|
+
},
|
|
185
210
|
],
|
|
186
211
|
});
|