@atlaskit/eslint-plugin-ui-styling-standard 0.13.0 → 0.14.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 +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/no-styled/usage.mdx +89 -0
- package/constellation/use-compiled/usage.mdx +2 -2
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-important-styles/index.js +11 -17
- package/dist/cjs/rules/no-styled/index.js +67 -0
- package/dist/cjs/rules/utils/create-rule-with-typed-config.js +60 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-important-styles/index.js +13 -18
- package/dist/es2019/rules/no-styled/index.js +45 -0
- package/dist/es2019/rules/utils/create-rule-with-typed-config.js +53 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-important-styles/index.js +12 -18
- package/dist/esm/rules/no-styled/index.js +61 -0
- package/dist/esm/rules/utils/create-rule-with-typed-config.js +53 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-styled/index.d.ts +2 -0
- package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +18 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-styled/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/utils/create-rule-with-typed-config.d.ts +18 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +12 -0
- package/src/rules/no-important-styles/index.tsx +11 -24
- package/src/rules/no-styled/README.md +82 -0
- package/src/rules/no-styled/__tests__/rule.test.tsx +73 -0
- package/src/rules/no-styled/index.tsx +52 -0
- package/src/rules/utils/create-rule-with-typed-config.tsx +87 -0
|
@@ -2,21 +2,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
3
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
4
|
import esquery from 'esquery';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
properties: {
|
|
10
|
-
importSources: {
|
|
11
|
-
type: 'array',
|
|
12
|
-
items: {
|
|
13
|
-
type: 'string'
|
|
14
|
-
},
|
|
15
|
-
uniqueItems: true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}];
|
|
19
|
-
export var rule = createLintRule({
|
|
5
|
+
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
8
|
+
export var rule = createLintRuleWithTypedConfig({
|
|
20
9
|
meta: {
|
|
21
10
|
name: 'no-important-styles',
|
|
22
11
|
docs: {
|
|
@@ -28,10 +17,15 @@ export var rule = createLintRule({
|
|
|
28
17
|
'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
|
|
29
18
|
},
|
|
30
19
|
type: 'problem',
|
|
31
|
-
schema:
|
|
20
|
+
schema: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
importSources: importSources
|
|
24
|
+
}
|
|
25
|
+
}
|
|
32
26
|
},
|
|
33
|
-
create: function create(context) {
|
|
34
|
-
var importSources =
|
|
27
|
+
create: function create(context, _ref) {
|
|
28
|
+
var importSources = _ref.importSources;
|
|
35
29
|
return {
|
|
36
30
|
CallExpression: function CallExpression(node) {
|
|
37
31
|
var _context$getScope = context.getScope(),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
export var rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-styled',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallows usage of the `styled` imports',
|
|
8
|
+
recommended: true,
|
|
9
|
+
severity: 'warn'
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
|
|
13
|
+
},
|
|
14
|
+
type: 'problem'
|
|
15
|
+
},
|
|
16
|
+
create: function create(context) {
|
|
17
|
+
return {
|
|
18
|
+
CallExpression: function (_CallExpression) {
|
|
19
|
+
function CallExpression(_x) {
|
|
20
|
+
return _CallExpression.apply(this, arguments);
|
|
21
|
+
}
|
|
22
|
+
CallExpression.toString = function () {
|
|
23
|
+
return _CallExpression.toString();
|
|
24
|
+
};
|
|
25
|
+
return CallExpression;
|
|
26
|
+
}(function (node) {
|
|
27
|
+
var references = context.getScope().references;
|
|
28
|
+
var importSources = getImportSources(context);
|
|
29
|
+
if (isStyled(node, references, importSources)) {
|
|
30
|
+
context.report({
|
|
31
|
+
node: node,
|
|
32
|
+
messageId: 'no-styled'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
MemberExpression: function (_MemberExpression) {
|
|
37
|
+
function MemberExpression(_x2) {
|
|
38
|
+
return _MemberExpression.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
MemberExpression.toString = function () {
|
|
41
|
+
return _MemberExpression.toString();
|
|
42
|
+
};
|
|
43
|
+
return MemberExpression;
|
|
44
|
+
}(function (node) {
|
|
45
|
+
var references = context.getScope().references;
|
|
46
|
+
var importSources = getImportSources(context);
|
|
47
|
+
if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
|
|
48
|
+
var parent = context.getAncestors().at(-1);
|
|
49
|
+
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
context.report({
|
|
53
|
+
node: node,
|
|
54
|
+
messageId: 'no-styled'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export default rule;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
import Ajv from 'ajv';
|
|
5
|
+
import { getRuleUrl } from './create-rule';
|
|
6
|
+
export var createLintRuleWithTypedConfig = function createLintRuleWithTypedConfig(rule) {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the default config by running the same validator
|
|
9
|
+
* ESLint does against an empty config object with
|
|
10
|
+
* `useDefaults` option enabled.
|
|
11
|
+
*
|
|
12
|
+
* Any properties with a `default` property set in the schema
|
|
13
|
+
* will be populated with the specified default value.
|
|
14
|
+
*/
|
|
15
|
+
function getDefaultConfig() {
|
|
16
|
+
var ajv = new Ajv({
|
|
17
|
+
useDefaults: true
|
|
18
|
+
});
|
|
19
|
+
var validate = ajv.compile(rule.meta.schema);
|
|
20
|
+
var config = {};
|
|
21
|
+
/**
|
|
22
|
+
* The `validate()` function mutates the config object.
|
|
23
|
+
*/
|
|
24
|
+
validate(config);
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
return _objectSpread(_objectSpread({}, rule), {}, {
|
|
28
|
+
meta: _objectSpread(_objectSpread({}, rule.meta), {}, {
|
|
29
|
+
docs: _objectSpread(_objectSpread({}, rule.meta.docs), {}, {
|
|
30
|
+
url: getRuleUrl(rule.meta.name)
|
|
31
|
+
}),
|
|
32
|
+
schema: [rule.meta.schema]
|
|
33
|
+
}),
|
|
34
|
+
create: function create(context) {
|
|
35
|
+
/**
|
|
36
|
+
* The config the user has passed.
|
|
37
|
+
*
|
|
38
|
+
* If they passed a config object, even if it is missing properties,
|
|
39
|
+
* ESLint will have added any default values defined using the
|
|
40
|
+
* `default` property in the schema.
|
|
41
|
+
*
|
|
42
|
+
* https://github.com/eslint/eslint/pull/11288
|
|
43
|
+
*/
|
|
44
|
+
var userConfig = context.options[0];
|
|
45
|
+
/**
|
|
46
|
+
* If the user passed no config object at all we need to obtain
|
|
47
|
+
* the default ourselves.
|
|
48
|
+
*/
|
|
49
|
+
var config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
|
|
50
|
+
return rule.create(context, config);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -16,6 +16,7 @@ export declare const configs: {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
21
22
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -56,6 +57,7 @@ export declare const configs: {
|
|
|
56
57
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
57
58
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
59
61
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
60
62
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
61
63
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -12,6 +12,7 @@ declare const _default: {
|
|
|
12
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
|
+
'no-styled': import("eslint").Rule.RuleModule;
|
|
15
16
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
16
17
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
17
18
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
3
|
+
import type { LintRule as BaseLintRule, LintRuleMeta as BaseLintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
4
|
+
export interface LintRule<Schema extends JSONSchema, Config> extends Omit<BaseLintRule, 'meta' | 'create'> {
|
|
5
|
+
meta: LintRuleMeta<Schema>;
|
|
6
|
+
create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
|
|
7
|
+
/**
|
|
8
|
+
* Unsure why the eslint typings include this when the docs
|
|
9
|
+
* say the schema should be in meta.
|
|
10
|
+
*/
|
|
11
|
+
schema?: never;
|
|
12
|
+
}
|
|
13
|
+
export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRuleMeta, 'schema'> {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
}
|
|
16
|
+
export declare const createLintRuleWithTypedConfig: <Schema extends JSONSchema & {
|
|
17
|
+
type: 'object';
|
|
18
|
+
}, Config = FromSchema<Schema>>(rule: LintRule<Schema, Config>) => Rule.RuleModule;
|
|
@@ -16,6 +16,7 @@ export declare const configs: {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
21
22
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -56,6 +57,7 @@ export declare const configs: {
|
|
|
56
57
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
57
58
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
59
61
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
60
62
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
61
63
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -12,6 +12,7 @@ declare const _default: {
|
|
|
12
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
|
+
'no-styled': import("eslint").Rule.RuleModule;
|
|
15
16
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
16
17
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
17
18
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
3
|
+
import type { LintRule as BaseLintRule, LintRuleMeta as BaseLintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
4
|
+
export interface LintRule<Schema extends JSONSchema, Config> extends Omit<BaseLintRule, 'meta' | 'create'> {
|
|
5
|
+
meta: LintRuleMeta<Schema>;
|
|
6
|
+
create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
|
|
7
|
+
/**
|
|
8
|
+
* Unsure why the eslint typings include this when the docs
|
|
9
|
+
* say the schema should be in meta.
|
|
10
|
+
*/
|
|
11
|
+
schema?: never;
|
|
12
|
+
}
|
|
13
|
+
export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRuleMeta, 'schema'> {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
}
|
|
16
|
+
export declare const createLintRuleWithTypedConfig: <Schema extends JSONSchema & {
|
|
17
|
+
type: 'object';
|
|
18
|
+
}, Config = FromSchema<Schema>>(rule: LintRule<Schema, Config>) => Rule.RuleModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,9 +39,10 @@
|
|
|
39
39
|
".": "./src/index.tsx"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@atlaskit/eslint-utils": "^1.
|
|
42
|
+
"@atlaskit/eslint-utils": "^1.4.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@typescript-eslint/utils": "^5.48.1",
|
|
45
|
+
"ajv": "^6.12.6",
|
|
45
46
|
"eslint-codemod-utils": "^1.8.6",
|
|
46
47
|
"eslint-scope": "^8.0.0",
|
|
47
48
|
"esquery": "^1.5.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
|
|
|
16
16
|
import noImportantStyles from './no-important-styles';
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
|
+
import noStyled from './no-styled';
|
|
19
20
|
import noUnsafeValues from './no-unsafe-values';
|
|
20
21
|
import useCompiled from './use-compiled';
|
|
21
22
|
|
|
@@ -33,6 +34,7 @@ export default {
|
|
|
33
34
|
'no-important-styles': noImportantStyles,
|
|
34
35
|
'no-imported-style-values': noImportedStyleValues,
|
|
35
36
|
'no-nested-selectors': noNestedSelectors,
|
|
37
|
+
'no-styled': noStyled,
|
|
36
38
|
'no-unsafe-values': noUnsafeValues,
|
|
37
39
|
'use-compiled': useCompiled,
|
|
38
40
|
};
|
|
@@ -149,5 +149,17 @@ tester.run('no-important-styles', rule, {
|
|
|
149
149
|
`,
|
|
150
150
|
errors: [{ messageId: 'no-important-styles' }],
|
|
151
151
|
},
|
|
152
|
+
{
|
|
153
|
+
name: 'uses default when options object is provided without importSources',
|
|
154
|
+
code: `
|
|
155
|
+
import { css } from '@compiled/react';
|
|
156
|
+
|
|
157
|
+
const styles = css({
|
|
158
|
+
color: 'red !important'
|
|
159
|
+
});
|
|
160
|
+
`,
|
|
161
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
162
|
+
options: [{}],
|
|
163
|
+
},
|
|
152
164
|
],
|
|
153
165
|
});
|
|
@@ -2,27 +2,11 @@ import esquery from 'esquery';
|
|
|
2
2
|
|
|
3
3
|
import type { Property } from 'estree';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
hasStyleObjectArguments,
|
|
9
|
-
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
10
|
-
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
5
|
+
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
11
8
|
|
|
12
|
-
const
|
|
13
|
-
{
|
|
14
|
-
type: 'object',
|
|
15
|
-
properties: {
|
|
16
|
-
importSources: {
|
|
17
|
-
type: 'array',
|
|
18
|
-
items: { type: 'string' },
|
|
19
|
-
uniqueItems: true,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
export const rule = createLintRule({
|
|
9
|
+
export const rule = createLintRuleWithTypedConfig({
|
|
26
10
|
meta: {
|
|
27
11
|
name: 'no-important-styles',
|
|
28
12
|
docs: {
|
|
@@ -35,11 +19,14 @@ export const rule = createLintRule({
|
|
|
35
19
|
'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.',
|
|
36
20
|
},
|
|
37
21
|
type: 'problem',
|
|
38
|
-
schema
|
|
22
|
+
schema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
importSources,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
39
28
|
},
|
|
40
|
-
create(context) {
|
|
41
|
-
const importSources = getImportSources(context);
|
|
42
|
-
|
|
29
|
+
create(context, { importSources }) {
|
|
43
30
|
return {
|
|
44
31
|
CallExpression(node) {
|
|
45
32
|
const { references } = context.getScope();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
This rule prevents usage of `styled` imports'.
|
|
2
|
+
|
|
3
|
+
Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`, etc.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
|
|
12
|
+
const Component = styled.div`
|
|
13
|
+
color: red;
|
|
14
|
+
`;
|
|
15
|
+
export default styled.div({ color: 'red' });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import styled2 from '@emotion/styled';
|
|
20
|
+
|
|
21
|
+
export const Component = styled2('div')`…`;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import styled from 'styled-components';
|
|
26
|
+
import { styled as styled3 } from '@compiled/react';
|
|
27
|
+
|
|
28
|
+
const Component = styled.div`color: red;`
|
|
29
|
+
export const ComponentTwo = styled3(Component)({ … });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import styled from 'styled-components';
|
|
34
|
+
|
|
35
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
36
|
+
color: 'red',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import styled from 'styled-components';
|
|
42
|
+
|
|
43
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
|
|
44
|
+
color: red;
|
|
45
|
+
`;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Correct
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { css, jsx } from '@emotion/react';
|
|
52
|
+
|
|
53
|
+
const styles = css({ color: 'red' });
|
|
54
|
+
|
|
55
|
+
const Component = ({ children }) => {
|
|
56
|
+
return <div css={styles}>{children}</div>;
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// Using Primitives
|
|
62
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
63
|
+
|
|
64
|
+
const styles = xcss({
|
|
65
|
+
color: 'color.text.subtlest',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const Component = ({ children }) => {
|
|
69
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## FAQ
|
|
74
|
+
|
|
75
|
+
### Why avoid using `styled` imports?
|
|
76
|
+
|
|
77
|
+
Using `styled` imports impacts file readability, has TypeScript implications, adds linting complexity, promotes exported styles, and potential refactoring efforts. Using `css()` with the `<div css={…}>` syntax is more performant and clear.
|
|
78
|
+
|
|
79
|
+
### How will I extend like `styled(Button)`?
|
|
80
|
+
|
|
81
|
+
Primarily, we would suggest you don't extend styles of a component you don't own unless they have an explicit bounded interface for you to customize against. The Atlassian Design System for example has removed `styled(Button)` interactivity in our latest variants because they are unsafe for us to evolve the system with.
|
|
82
|
+
Instead, make use of reusable component patterns to pass props around which impact the styles of that component.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-styled', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
code: `
|
|
8
|
+
import { css, jsx } from '@emotion/react';
|
|
9
|
+
|
|
10
|
+
const styles = css({ color: 'red' });
|
|
11
|
+
|
|
12
|
+
const Component = ({ children }) => {
|
|
13
|
+
return <div css={styles}>{children}</div>;
|
|
14
|
+
};
|
|
15
|
+
`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
code: `
|
|
19
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
20
|
+
|
|
21
|
+
const styles = xcss({
|
|
22
|
+
color: 'color.text.subtlest',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const Component = ({ children }) => {
|
|
26
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
27
|
+
};
|
|
28
|
+
`
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
invalid: [
|
|
32
|
+
{
|
|
33
|
+
code: `
|
|
34
|
+
import styled from 'styled-components';
|
|
35
|
+
|
|
36
|
+
const Component = styled.div\`color: red;\`
|
|
37
|
+
`,
|
|
38
|
+
errors: [{ messageId: 'no-styled' }],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
|
+
import styled from 'styled-components';
|
|
43
|
+
|
|
44
|
+
export default styled.div({ color: 'red' });
|
|
45
|
+
`,
|
|
46
|
+
errors: [{ messageId: 'no-styled' }],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: `
|
|
50
|
+
import { styled as styled3 } from '@compiled/react';
|
|
51
|
+
|
|
52
|
+
export const ComponentTwo = styled3(Component)({ color: 'blue' });
|
|
53
|
+
`,
|
|
54
|
+
errors: [{ messageId: 'no-styled' }],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: `
|
|
58
|
+
import styled from 'styled-components';
|
|
59
|
+
|
|
60
|
+
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))({ color: 'red' });
|
|
61
|
+
`,
|
|
62
|
+
errors: [{ messageId: 'no-styled' }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: `
|
|
66
|
+
import styled from 'styled-components';
|
|
67
|
+
|
|
68
|
+
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))\`color: red\`;
|
|
69
|
+
`,
|
|
70
|
+
errors: [{ messageId: 'no-styled' }],
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
});
|