@atlaskit/eslint-plugin-ui-styling-standard 0.2.1 → 0.4.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 +28 -0
- package/README.md +18 -5
- package/build/tsconfig.json +2 -4
- package/constellation/consistent-css-prop-usage/usage.mdx +5 -0
- package/constellation/index/overview.mdx +219 -0
- package/constellation/index/props.mdx +33 -0
- package/constellation/local-cx-xcss/usage.mdx +37 -0
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-empty-styled-expression/usage.mdx +5 -0
- package/constellation/no-exported-css/usage.mdx +5 -0
- package/constellation/no-exported-keyframes/usage.mdx +5 -0
- package/constellation/no-invalid-css-map/usage.mdx +5 -0
- package/constellation/no-js-xcss/usage.mdx +23 -0
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-suppress-xcss/usage.mdx +25 -0
- package/dist/cjs/index.codegen.js +26 -0
- package/dist/cjs/index.js +12 -12
- package/dist/cjs/presets/all.codegen.js +37 -0
- package/dist/cjs/presets/recommended.codegen.js +37 -0
- package/dist/cjs/rules/external-rules.js +143 -0
- package/dist/cjs/rules/index.codegen.js +16 -0
- package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
- package/dist/cjs/rules/utils/create-rule.js +43 -0
- package/dist/cjs/rules/utils/is-supported-import.js +98 -0
- package/dist/es2019/index.codegen.js +12 -0
- package/dist/es2019/index.js +1 -12
- package/dist/es2019/presets/all.codegen.js +31 -0
- package/dist/es2019/presets/recommended.codegen.js +31 -0
- package/dist/es2019/rules/external-rules.js +138 -0
- package/dist/es2019/rules/index.codegen.js +9 -0
- package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
- package/dist/es2019/rules/utils/create-rule.js +33 -0
- package/dist/es2019/rules/utils/is-supported-import.js +87 -0
- package/dist/esm/index.codegen.js +12 -0
- package/dist/esm/index.js +1 -12
- package/dist/esm/presets/all.codegen.js +31 -0
- package/dist/esm/presets/recommended.codegen.js +31 -0
- package/dist/esm/rules/external-rules.js +138 -0
- package/dist/esm/rules/index.codegen.js +9 -0
- package/dist/esm/rules/local-cx-xcss/index.js +45 -0
- package/dist/esm/rules/utils/create-rule.js +35 -0
- package/dist/esm/rules/utils/is-supported-import.js +90 -0
- package/dist/types/index.codegen.d.ts +55 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/presets/all.codegen.d.ts +32 -0
- package/dist/types/presets/recommended.codegen.d.ts +32 -0
- package/dist/types/rules/external-rules.d.ts +11 -0
- package/dist/types/rules/index.codegen.d.ts +4 -0
- package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types/rules/utils/create-rule.d.ts +64 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +34 -0
- package/dist/types-ts4.5/index.codegen.d.ts +55 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +32 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +32 -0
- package/dist/types-ts4.5/rules/external-rules.d.ts +11 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +64 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +34 -0
- package/package.json +21 -8
- package/scripts/codegen.tsx +439 -0
- package/src/index.codegen.tsx +14 -0
- package/src/index.tsx +1 -17
- package/src/presets/all.codegen.tsx +67 -0
- package/src/presets/recommended.codegen.tsx +67 -0
- package/src/rules/TEMPLATE.md +29 -0
- package/src/rules/__tests__/utils/_tester.tsx +40 -0
- package/src/rules/external-rules.tsx +175 -0
- package/src/rules/index.codegen.tsx +10 -0
- package/src/rules/local-cx-xcss/README.md +35 -0
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +102 -0
- package/src/rules/local-cx-xcss/index.tsx +69 -0
- package/src/rules/utils/create-rule.tsx +80 -0
- package/src/rules/utils/is-supported-import.tsx +130 -0
- package/tsconfig.app.json +5 -1
- package/tsconfig.dev.json +5 -1
- package/tsconfig.json +7 -6
- package/dist/types/src/index.d.ts +0 -12
- package/dist/types-ts4.5/src/index.d.ts +0 -12
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.externalRules = void 0;
|
|
7
|
+
var _createRule = require("./utils/create-rule");
|
|
8
|
+
/** External rules must be scoped, have a display name, and external urls. */
|
|
9
|
+
|
|
10
|
+
var importSources = ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components'];
|
|
11
|
+
var externalRules = exports.externalRules = [{
|
|
12
|
+
name: '@atlaskit/design-system/consistent-css-prop-usage',
|
|
13
|
+
displayName: 'consistent-css-prop-usage',
|
|
14
|
+
isExternal: true,
|
|
15
|
+
fixable: 'code',
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Ensures consistency with `css` and `xcss` prop usages',
|
|
18
|
+
url: (0, _createRule.getRuleUrl)('consistent-css-prop-usage'),
|
|
19
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/consistent-css-prop-usage/usage',
|
|
20
|
+
recommended: true,
|
|
21
|
+
severity: 'warn',
|
|
22
|
+
pluginConfig: {
|
|
23
|
+
// When passing a css prop to a React component, we don't know whether the component
|
|
24
|
+
// is Emotion or Compiled. Hence it is not safe to run autofixes like wrapping it in
|
|
25
|
+
// a `css` function call.
|
|
26
|
+
excludeReactComponents: true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
name: '@atlaskit/design-system/no-css-tagged-template-expression',
|
|
31
|
+
displayName: 'no-css-tagged-template-expression',
|
|
32
|
+
isExternal: true,
|
|
33
|
+
fixable: 'code',
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
36
|
+
url: (0, _createRule.getRuleUrl)('no-css-tagged-template-expression'),
|
|
37
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-css-tagged-template-expression/usage',
|
|
38
|
+
recommended: true,
|
|
39
|
+
severity: 'warn'
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
name: '@atlaskit/design-system/no-keyframes-tagged-template-expression',
|
|
43
|
+
displayName: 'no-keyframes-tagged-template-expression',
|
|
44
|
+
isExternal: true,
|
|
45
|
+
fixable: 'code',
|
|
46
|
+
docs: {
|
|
47
|
+
description: 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
48
|
+
url: (0, _createRule.getRuleUrl)('no-keyframes-tagged-template-expression'),
|
|
49
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-keyframes-tagged-template-expression/usage',
|
|
50
|
+
recommended: true,
|
|
51
|
+
severity: 'warn'
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
name: '@atlaskit/design-system/no-styled-tagged-template-expression',
|
|
55
|
+
displayName: 'no-styled-tagged-template-expression',
|
|
56
|
+
isExternal: true,
|
|
57
|
+
fixable: 'code',
|
|
58
|
+
docs: {
|
|
59
|
+
description: 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
60
|
+
url: (0, _createRule.getRuleUrl)('no-styled-tagged-template-expression'),
|
|
61
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
|
|
62
|
+
recommended: true,
|
|
63
|
+
severity: 'warn'
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
name: '@compiled/no-suppress-xcss',
|
|
67
|
+
displayName: 'no-suppress-xcss',
|
|
68
|
+
isExternal: true,
|
|
69
|
+
docs: {
|
|
70
|
+
description: 'Disallows supressing type violations when using the xcss prop.',
|
|
71
|
+
url: (0, _createRule.getRuleUrl)('no-suppress-xcss'),
|
|
72
|
+
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
|
|
73
|
+
recommended: true,
|
|
74
|
+
severity: 'warn'
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
name: '@compiled/no-js-xcss',
|
|
78
|
+
displayName: 'no-js-xcss',
|
|
79
|
+
isExternal: true,
|
|
80
|
+
docs: {
|
|
81
|
+
description: 'Disallows using xcss prop inside JavaScript files.',
|
|
82
|
+
url: (0, _createRule.getRuleUrl)('no-js-xcss'),
|
|
83
|
+
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
|
|
84
|
+
recommended: true,
|
|
85
|
+
severity: 'warn'
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
name: '@atlaskit/design-system/no-empty-styled-expression',
|
|
89
|
+
displayName: 'no-empty-styled-expression',
|
|
90
|
+
isExternal: true,
|
|
91
|
+
docs: {
|
|
92
|
+
description: 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
|
|
93
|
+
url: (0, _createRule.getRuleUrl)('no-empty-styled-expression'),
|
|
94
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-empty-styled-expression/usage',
|
|
95
|
+
recommended: true,
|
|
96
|
+
severity: 'warn',
|
|
97
|
+
pluginConfig: {
|
|
98
|
+
importSources: importSources
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
name: '@atlaskit/design-system/no-exported-css',
|
|
103
|
+
displayName: 'no-exported-css',
|
|
104
|
+
isExternal: true,
|
|
105
|
+
docs: {
|
|
106
|
+
description: 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
107
|
+
url: (0, _createRule.getRuleUrl)('no-exported-css'),
|
|
108
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-css/usage',
|
|
109
|
+
recommended: true,
|
|
110
|
+
severity: 'warn',
|
|
111
|
+
pluginConfig: {
|
|
112
|
+
importSources: importSources
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
name: '@atlaskit/design-system/no-exported-keyframes',
|
|
117
|
+
displayName: 'no-exported-keyframes',
|
|
118
|
+
isExternal: true,
|
|
119
|
+
docs: {
|
|
120
|
+
description: 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
121
|
+
url: (0, _createRule.getRuleUrl)('no-exported-keyframes'),
|
|
122
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-keyframes/usage',
|
|
123
|
+
recommended: true,
|
|
124
|
+
severity: 'warn',
|
|
125
|
+
pluginConfig: {
|
|
126
|
+
importSources: importSources
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}, {
|
|
130
|
+
name: '@atlaskit/design-system/no-invalid-css-map',
|
|
131
|
+
displayName: 'no-invalid-css-map',
|
|
132
|
+
isExternal: true,
|
|
133
|
+
docs: {
|
|
134
|
+
description: "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
|
|
135
|
+
url: (0, _createRule.getRuleUrl)('no-invalid-css-map'),
|
|
136
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-invalid-css-map/usage',
|
|
137
|
+
recommended: true,
|
|
138
|
+
severity: 'warn',
|
|
139
|
+
pluginConfig: {
|
|
140
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
9
|
+
/**
|
|
10
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
11
|
+
* @codegen <<SignedSource::f907e3f7ab0b7145dcb8318732ae1fec>>
|
|
12
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
13
|
+
*/
|
|
14
|
+
var _default = exports.default = {
|
|
15
|
+
'local-cx-xcss': _localCxXcss.default
|
|
16
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
9
|
+
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
10
|
+
function getParentJSXAttribute(node) {
|
|
11
|
+
var parent = node.parent;
|
|
12
|
+
while (parent && parent.type !== 'JSXAttribute') {
|
|
13
|
+
parent = parent.parent;
|
|
14
|
+
}
|
|
15
|
+
if (parent && parent.type === 'JSXAttribute') {
|
|
16
|
+
return parent;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
21
|
+
meta: {
|
|
22
|
+
name: 'local-cx-xcss',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element.',
|
|
25
|
+
recommended: true,
|
|
26
|
+
severity: 'warn'
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
|
|
30
|
+
},
|
|
31
|
+
type: 'problem'
|
|
32
|
+
},
|
|
33
|
+
create: function create(context) {
|
|
34
|
+
return {
|
|
35
|
+
'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
|
|
36
|
+
if (node.type === 'CallExpression' && (0, _isSupportedImport.isCxFunction)(node.callee, context.getScope().references, IMPORT_SOURCES)) {
|
|
37
|
+
var parentJSXAttribute = getParentJSXAttribute(node);
|
|
38
|
+
var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
39
|
+
if (propName && /[xX]css$/.test(propName)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
context.report({
|
|
43
|
+
node: node,
|
|
44
|
+
messageId: 'local-cx-xcss'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRule = exports.createLintRule = void 0;
|
|
7
|
+
exports.getPathSafeName = getPathSafeName;
|
|
8
|
+
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
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Tiny wrapped over the ESLint rule module type that ensures
|
|
26
|
+
* there is a docs link to our ESLint plugin documentation page,
|
|
27
|
+
* as well as improving type support.
|
|
28
|
+
*/
|
|
29
|
+
var createLintRule = exports.createLintRule = function createLintRule(rule) {
|
|
30
|
+
rule.meta.docs.url = getRuleUrl(rule.meta.name);
|
|
31
|
+
return rule;
|
|
32
|
+
};
|
|
33
|
+
function getRuleUrl(ruleName) {
|
|
34
|
+
var name = getPathSafeName(ruleName);
|
|
35
|
+
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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.isStyled = exports.isKeyframes = exports.isCxFunction = exports.isCssMap = exports.isCss = exports.getImportSources = exports.DEFAULT_IMPORT_SOURCES = exports.CSS_IN_JS_IMPORTS = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
|
+
|
|
11
|
+
var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
|
|
12
|
+
compiled: '@compiled/react',
|
|
13
|
+
emotionReact: '@emotion/react',
|
|
14
|
+
emotionCore: '@emotion/core',
|
|
15
|
+
styledComponents: 'styled-components',
|
|
16
|
+
atlaskitCss: '@atlaskit/css',
|
|
17
|
+
atlaskitPrimitives: '@atlaskit/primitives'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
|
|
21
|
+
// function might originate from, e.g. @compiled/react, @emotion/core.
|
|
22
|
+
|
|
23
|
+
// All ESLint rules originating from `@compiled/eslint-plugin` should apply to these libraries.
|
|
24
|
+
var DEFAULT_IMPORT_SOURCES = exports.DEFAULT_IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
28
|
+
* The importSources option is used to define additional libraries for which an ESLint rule
|
|
29
|
+
* should apply to.
|
|
30
|
+
*
|
|
31
|
+
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
32
|
+
* of what importSources is configured to by the user.
|
|
33
|
+
*
|
|
34
|
+
* @param context The rule context.
|
|
35
|
+
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
36
|
+
* on the rule options configuration.
|
|
37
|
+
*/
|
|
38
|
+
var getImportSources = exports.getImportSources = function getImportSources(context) {
|
|
39
|
+
var options = context.options;
|
|
40
|
+
if (!options.length) {
|
|
41
|
+
return DEFAULT_IMPORT_SOURCES;
|
|
42
|
+
}
|
|
43
|
+
if (options[0].importSources && Array.isArray(options[0].importSources)) {
|
|
44
|
+
return [].concat(DEFAULT_IMPORT_SOURCES, (0, _toConsumableArray2.default)(options[0].importSources));
|
|
45
|
+
}
|
|
46
|
+
return DEFAULT_IMPORT_SOURCES;
|
|
47
|
+
};
|
|
48
|
+
var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
|
|
49
|
+
var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
|
|
50
|
+
if (def.type !== 'ImportBinding') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (!def.parent || !importSources.includes(def.parent.source.value)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return (
|
|
57
|
+
// import { functionName } from 'import-source';
|
|
58
|
+
def.node.type === 'ImportSpecifier' && def.node.imported.name === functionName ||
|
|
59
|
+
// import functionName from 'import-source';
|
|
60
|
+
def.node.type === 'ImportDefaultSpecifier' && def.node.local.name === functionName
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Checks whether:
|
|
66
|
+
*
|
|
67
|
+
* 1. A function name `nodeToCheck` matches the name of the function we
|
|
68
|
+
* want to check for (e.g. `cx`, `css`, `cssMap`, or `keyframes`), and
|
|
69
|
+
* 2. Whether `nodeToCheck` originates from one of the libraries listed
|
|
70
|
+
* in `importSources`.
|
|
71
|
+
*
|
|
72
|
+
* @param nodeToCheck The function callee we are checking (e.g. The `css` in `css()`).
|
|
73
|
+
* @param referencesInScope List of references that are in scope. We'll use this
|
|
74
|
+
* to check where the function callee is imported from.
|
|
75
|
+
* @param importSources List of libraries that we want to ensure `nodeToCheck`
|
|
76
|
+
* comes from.
|
|
77
|
+
*
|
|
78
|
+
* @returns Whether the above conditions are true.
|
|
79
|
+
*/
|
|
80
|
+
var isSupportedImport = function isSupportedImport(nodeToCheck, referencesInScope, importSources) {
|
|
81
|
+
return nodeToCheck.type === 'Identifier' && referencesInScope.some(function (reference) {
|
|
82
|
+
var _reference$resolved;
|
|
83
|
+
return reference.identifier === nodeToCheck && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) {
|
|
84
|
+
return checkDefinitionHasImport(def, importSources);
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return isSupportedImport;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Unused functions have been commented out until we implement corresponding
|
|
92
|
+
// eslint rules which use them
|
|
93
|
+
//
|
|
94
|
+
var isCss = exports.isCss = isSupportedImportWrapper('css');
|
|
95
|
+
var isCxFunction = exports.isCxFunction = isSupportedImportWrapper('cx');
|
|
96
|
+
var isCssMap = exports.isCssMap = isSupportedImportWrapper('cssMap');
|
|
97
|
+
var isKeyframes = exports.isKeyframes = isSupportedImportWrapper('keyframes');
|
|
98
|
+
var isStyled = exports.isStyled = isSupportedImportWrapper('styled');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::3fd41935576c9346ca1f1e0c787a0a48>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
import all from './presets/all.codegen';
|
|
7
|
+
import recommended from './presets/recommended.codegen';
|
|
8
|
+
export { default as rules } from './rules/index.codegen';
|
|
9
|
+
export const configs = {
|
|
10
|
+
all,
|
|
11
|
+
recommended
|
|
12
|
+
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export const configs = {
|
|
3
|
-
recommended: {
|
|
4
|
-
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
5
|
-
rules: {
|
|
6
|
-
'@atlaskit/design-system/consistent-css-prop-usage': 'error',
|
|
7
|
-
'@atlaskit/design-system/local-cx-xcss': 'error',
|
|
8
|
-
'@compiled/no-suppress-xcss': 'error',
|
|
9
|
-
'@compiled/no-js-xcss': 'error'
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
1
|
+
export { configs, rules } from './index.codegen';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::6b1418e07df6af9ad4cae4baf66739c1>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
export default {
|
|
7
|
+
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
|
+
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
11
|
+
excludeReactComponents: true
|
|
12
|
+
}],
|
|
13
|
+
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
14
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
15
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
16
|
+
'@compiled/no-suppress-xcss': 'warn',
|
|
17
|
+
'@compiled/no-js-xcss': 'warn',
|
|
18
|
+
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|
|
19
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
20
|
+
}],
|
|
21
|
+
'@atlaskit/design-system/no-exported-css': ['warn', {
|
|
22
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
23
|
+
}],
|
|
24
|
+
'@atlaskit/design-system/no-exported-keyframes': ['warn', {
|
|
25
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
26
|
+
}],
|
|
27
|
+
'@atlaskit/design-system/no-invalid-css-map': ['warn', {
|
|
28
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::6b1418e07df6af9ad4cae4baf66739c1>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
export default {
|
|
7
|
+
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
|
+
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
11
|
+
excludeReactComponents: true
|
|
12
|
+
}],
|
|
13
|
+
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
14
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
15
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
16
|
+
'@compiled/no-suppress-xcss': 'warn',
|
|
17
|
+
'@compiled/no-js-xcss': 'warn',
|
|
18
|
+
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|
|
19
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
20
|
+
}],
|
|
21
|
+
'@atlaskit/design-system/no-exported-css': ['warn', {
|
|
22
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
23
|
+
}],
|
|
24
|
+
'@atlaskit/design-system/no-exported-keyframes': ['warn', {
|
|
25
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
|
|
26
|
+
}],
|
|
27
|
+
'@atlaskit/design-system/no-invalid-css-map': ['warn', {
|
|
28
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { getRuleUrl } from './utils/create-rule';
|
|
2
|
+
|
|
3
|
+
/** External rules must be scoped, have a display name, and external urls. */
|
|
4
|
+
|
|
5
|
+
const importSources = ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components'];
|
|
6
|
+
export const externalRules = [{
|
|
7
|
+
name: '@atlaskit/design-system/consistent-css-prop-usage',
|
|
8
|
+
displayName: 'consistent-css-prop-usage',
|
|
9
|
+
isExternal: true,
|
|
10
|
+
fixable: 'code',
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Ensures consistency with `css` and `xcss` prop usages',
|
|
13
|
+
url: getRuleUrl('consistent-css-prop-usage'),
|
|
14
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/consistent-css-prop-usage/usage',
|
|
15
|
+
recommended: true,
|
|
16
|
+
severity: 'warn',
|
|
17
|
+
pluginConfig: {
|
|
18
|
+
// When passing a css prop to a React component, we don't know whether the component
|
|
19
|
+
// is Emotion or Compiled. Hence it is not safe to run autofixes like wrapping it in
|
|
20
|
+
// a `css` function call.
|
|
21
|
+
excludeReactComponents: true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
name: '@atlaskit/design-system/no-css-tagged-template-expression',
|
|
26
|
+
displayName: 'no-css-tagged-template-expression',
|
|
27
|
+
isExternal: true,
|
|
28
|
+
fixable: 'code',
|
|
29
|
+
docs: {
|
|
30
|
+
description: 'Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
31
|
+
url: getRuleUrl('no-css-tagged-template-expression'),
|
|
32
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-css-tagged-template-expression/usage',
|
|
33
|
+
recommended: true,
|
|
34
|
+
severity: 'warn'
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
name: '@atlaskit/design-system/no-keyframes-tagged-template-expression',
|
|
38
|
+
displayName: 'no-keyframes-tagged-template-expression',
|
|
39
|
+
isExternal: true,
|
|
40
|
+
fixable: 'code',
|
|
41
|
+
docs: {
|
|
42
|
+
description: 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
43
|
+
url: getRuleUrl('no-keyframes-tagged-template-expression'),
|
|
44
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-keyframes-tagged-template-expression/usage',
|
|
45
|
+
recommended: true,
|
|
46
|
+
severity: 'warn'
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
name: '@atlaskit/design-system/no-styled-tagged-template-expression',
|
|
50
|
+
displayName: 'no-styled-tagged-template-expression',
|
|
51
|
+
isExternal: true,
|
|
52
|
+
fixable: 'code',
|
|
53
|
+
docs: {
|
|
54
|
+
description: 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
|
|
55
|
+
url: getRuleUrl('no-styled-tagged-template-expression'),
|
|
56
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
|
|
57
|
+
recommended: true,
|
|
58
|
+
severity: 'warn'
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
name: '@compiled/no-suppress-xcss',
|
|
62
|
+
displayName: 'no-suppress-xcss',
|
|
63
|
+
isExternal: true,
|
|
64
|
+
docs: {
|
|
65
|
+
description: 'Disallows supressing type violations when using the xcss prop.',
|
|
66
|
+
url: getRuleUrl('no-suppress-xcss'),
|
|
67
|
+
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
|
|
68
|
+
recommended: true,
|
|
69
|
+
severity: 'warn'
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
name: '@compiled/no-js-xcss',
|
|
73
|
+
displayName: 'no-js-xcss',
|
|
74
|
+
isExternal: true,
|
|
75
|
+
docs: {
|
|
76
|
+
description: 'Disallows using xcss prop inside JavaScript files.',
|
|
77
|
+
url: getRuleUrl('no-js-xcss'),
|
|
78
|
+
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
|
|
79
|
+
recommended: true,
|
|
80
|
+
severity: 'warn'
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
name: '@atlaskit/design-system/no-empty-styled-expression',
|
|
84
|
+
displayName: 'no-empty-styled-expression',
|
|
85
|
+
isExternal: true,
|
|
86
|
+
docs: {
|
|
87
|
+
description: 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
|
|
88
|
+
url: getRuleUrl('no-empty-styled-expression'),
|
|
89
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-empty-styled-expression/usage',
|
|
90
|
+
recommended: true,
|
|
91
|
+
severity: 'warn',
|
|
92
|
+
pluginConfig: {
|
|
93
|
+
importSources
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
name: '@atlaskit/design-system/no-exported-css',
|
|
98
|
+
displayName: 'no-exported-css',
|
|
99
|
+
isExternal: true,
|
|
100
|
+
docs: {
|
|
101
|
+
description: 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
102
|
+
url: getRuleUrl('no-exported-css'),
|
|
103
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-css/usage',
|
|
104
|
+
recommended: true,
|
|
105
|
+
severity: 'warn',
|
|
106
|
+
pluginConfig: {
|
|
107
|
+
importSources
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
name: '@atlaskit/design-system/no-exported-keyframes',
|
|
112
|
+
displayName: 'no-exported-keyframes',
|
|
113
|
+
isExternal: true,
|
|
114
|
+
docs: {
|
|
115
|
+
description: 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
116
|
+
url: getRuleUrl('no-exported-keyframes'),
|
|
117
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-keyframes/usage',
|
|
118
|
+
recommended: true,
|
|
119
|
+
severity: 'warn',
|
|
120
|
+
pluginConfig: {
|
|
121
|
+
importSources
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, {
|
|
125
|
+
name: '@atlaskit/design-system/no-invalid-css-map',
|
|
126
|
+
displayName: 'no-invalid-css-map',
|
|
127
|
+
isExternal: true,
|
|
128
|
+
docs: {
|
|
129
|
+
description: "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
|
|
130
|
+
url: getRuleUrl('no-invalid-css-map'),
|
|
131
|
+
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-invalid-css-map/usage',
|
|
132
|
+
recommended: true,
|
|
133
|
+
severity: 'warn',
|
|
134
|
+
pluginConfig: {
|
|
135
|
+
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::f907e3f7ab0b7145dcb8318732ae1fec>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
import localCxXcss from './local-cx-xcss';
|
|
7
|
+
export default {
|
|
8
|
+
'local-cx-xcss': localCxXcss
|
|
9
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { CSS_IN_JS_IMPORTS, isCxFunction } from '../utils/is-supported-import';
|
|
3
|
+
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
4
|
+
function getParentJSXAttribute(node) {
|
|
5
|
+
let parent = node.parent;
|
|
6
|
+
while (parent && parent.type !== 'JSXAttribute') {
|
|
7
|
+
parent = parent.parent;
|
|
8
|
+
}
|
|
9
|
+
if (parent && parent.type === 'JSXAttribute') {
|
|
10
|
+
return parent;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
export const rule = createLintRule({
|
|
15
|
+
meta: {
|
|
16
|
+
name: 'local-cx-xcss',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element.',
|
|
19
|
+
recommended: true,
|
|
20
|
+
severity: 'warn'
|
|
21
|
+
},
|
|
22
|
+
messages: {
|
|
23
|
+
'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
|
|
24
|
+
},
|
|
25
|
+
type: 'problem'
|
|
26
|
+
},
|
|
27
|
+
create(context) {
|
|
28
|
+
return {
|
|
29
|
+
'CallExpression[callee.name="cx"]': node => {
|
|
30
|
+
if (node.type === 'CallExpression' && isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)) {
|
|
31
|
+
const parentJSXAttribute = getParentJSXAttribute(node);
|
|
32
|
+
const propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
33
|
+
if (propName && /[xX]css$/.test(propName)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
context.report({
|
|
37
|
+
node,
|
|
38
|
+
messageId: 'local-cx-xcss'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export default rule;
|