@atlaskit/eslint-plugin-ui-styling-standard 0.15.1 → 0.16.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/constellation/index/migration-guide.mdx +309 -0
  3. package/constellation/index/overview.mdx +4 -0
  4. package/constellation/index/props.mdx +9 -5
  5. package/dist/cjs/rules/no-nested-selectors/index.js +68 -49
  6. package/dist/es2019/rules/no-nested-selectors/index.js +63 -45
  7. package/dist/esm/rules/no-nested-selectors/index.js +64 -49
  8. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
  9. package/index.js +9 -9
  10. package/package.json +3 -3
  11. package/scripts/codegen.tsx +223 -284
  12. package/src/rules/__tests__/utils/_tester.tsx +24 -24
  13. package/src/rules/atlaskit-theme/README.md +21 -19
  14. package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
  15. package/src/rules/atlaskit-theme/index.ts +107 -115
  16. package/src/rules/convert-props-syntax/README.md +32 -22
  17. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
  18. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
  19. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
  20. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
  21. package/src/rules/convert-props-syntax/index.tsx +356 -386
  22. package/src/rules/enforce-style-prop/README.md +21 -18
  23. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
  24. package/src/rules/enforce-style-prop/index.tsx +144 -160
  25. package/src/rules/external-rules.tsx +163 -164
  26. package/src/rules/local-cx-xcss/README.md +10 -6
  27. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
  28. package/src/rules/local-cx-xcss/index.tsx +46 -56
  29. package/src/rules/no-array-arguments/README.md +2 -1
  30. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
  31. package/src/rules/no-array-arguments/index.tsx +68 -69
  32. package/src/rules/no-classname-prop/README.md +7 -4
  33. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
  34. package/src/rules/no-classname-prop/index.tsx +25 -25
  35. package/src/rules/no-container-queries/README.md +11 -9
  36. package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
  37. package/src/rules/no-container-queries/index.tsx +75 -81
  38. package/src/rules/no-dynamic-styles/README.md +16 -19
  39. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
  40. package/src/rules/no-dynamic-styles/index.tsx +45 -48
  41. package/src/rules/no-exported-styles/README.md +17 -12
  42. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
  43. package/src/rules/no-exported-styles/index.tsx +36 -36
  44. package/src/rules/no-global-styles/README.md +15 -14
  45. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
  46. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
  47. package/src/rules/no-global-styles/index.tsx +59 -62
  48. package/src/rules/no-important-styles/README.md +5 -3
  49. package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
  50. package/src/rules/no-important-styles/index.tsx +49 -49
  51. package/src/rules/no-imported-style-values/README.md +23 -15
  52. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
  53. package/src/rules/no-imported-style-values/index.tsx +116 -120
  54. package/src/rules/no-nested-selectors/README.md +15 -13
  55. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +186 -149
  56. package/src/rules/no-nested-selectors/index.tsx +92 -105
  57. package/src/rules/no-styled/README.md +14 -9
  58. package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
  59. package/src/rules/no-styled/index.tsx +34 -41
  60. package/src/rules/no-unsafe-selectors/README.md +103 -93
  61. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
  62. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
  63. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
  64. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
  65. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
  66. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
  67. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
  68. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
  69. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
  70. package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
  71. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
  72. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
  73. package/src/rules/no-unsafe-values/README.md +34 -40
  74. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
  75. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
  76. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
  77. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
  78. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
  79. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
  80. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
  81. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
  82. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
  83. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
  84. package/src/rules/no-unsafe-values/index.tsx +76 -78
  85. package/src/rules/no-unsafe-values/messages.tsx +12 -12
  86. package/src/rules/no-unsafe-values/utils.tsx +370 -382
  87. package/src/rules/use-compiled/README.md +11 -8
  88. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
  89. package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
  90. package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
  91. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
  92. package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
  93. package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
  94. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
  95. package/src/rules/use-compiled/index.tsx +203 -226
  96. package/src/rules/use-compiled/is-safe.tsx +113 -117
  97. package/src/rules/use-compiled/utils.tsx +14 -18
  98. package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
  99. package/src/rules/utils/create-rule.tsx +3 -6
@@ -1,32 +1,36 @@
1
- import { isStyled, isCss, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
2
- import { createLintRule } from '../utils/create-rule';
3
- var schema = [{
4
- type: 'object',
5
- properties: {
6
- importSources: {
7
- type: 'array',
8
- items: {
9
- type: 'string'
10
- },
11
- uniqueItems: true
12
- }
13
- }
14
- }];
15
- var getCssSelector = function getCssSelector(node) {
16
- if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
17
- return node.key.value;
1
+ import _toArray from "@babel/runtime/helpers/toArray";
2
+ import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
3
+ import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
4
+ import { importSources } from '@atlaskit/eslint-utils/schema';
5
+ import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
6
+ var getCssSelector = function getCssSelector(key) {
7
+ if (key.type === 'Literal' && typeof key.value === 'string') {
8
+ return key.value;
18
9
  }
19
- if (node.key.type === 'Identifier' && typeof node.key.name === 'string') {
20
- return node.key.name;
10
+ if (key.type === 'Identifier' && typeof key.name === 'string') {
11
+ return key.name;
21
12
  }
22
- if (node.key.type === 'TemplateLiteral') {
23
- return node.key.quasis.map(function (quasi) {
13
+ if (key.type === 'TemplateLiteral') {
14
+ return key.quasis.map(function (quasi) {
24
15
  return quasi.value.raw;
25
16
  }).join(' ');
26
17
  }
27
18
  return null;
28
19
  };
29
- export var rule = createLintRule({
20
+ function isAllowedSelector(selector) {
21
+ var _selector$nodes = _toArray(selector.nodes),
22
+ head = _selector$nodes[0],
23
+ tail = _selector$nodes.slice(1);
24
+
25
+ // The first node must be a nesting selector (`&`) or pseudo-selector.
26
+ var isHeadAllowed = isNesting(head) || isPseudo(head);
27
+
28
+ // All remaining nodes must be pseudo selectors.
29
+ var isTailAllowed = tail.every(isPseudo);
30
+ return isHeadAllowed && isTailAllowed;
31
+ }
32
+ var cssSelectorProcessor = cssSelectorParser();
33
+ export var rule = createLintRuleWithTypedConfig({
30
34
  meta: {
31
35
  name: 'no-nested-selectors',
32
36
  docs: {
@@ -38,37 +42,48 @@ export var rule = createLintRule({
38
42
  'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
39
43
  },
40
44
  type: 'problem',
41
- schema: schema
45
+ schema: {
46
+ type: 'object',
47
+ properties: {
48
+ importSources: importSources
49
+ }
50
+ }
42
51
  },
43
- create: function create(context) {
44
- var importSources = getImportSources(context);
52
+ create: function create(context, _ref) {
53
+ var importSources = _ref.importSources;
45
54
  return {
46
- 'CallExpression Property': function CallExpressionProperty(node) {
55
+ CallExpression: function CallExpression(node) {
47
56
  var _context$getScope = context.getScope(),
48
57
  references = _context$getScope.references;
49
- var ancestors = context.getAncestors();
50
- if (ancestors.every(function (ancestor) {
51
- return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources));
52
- })) {
53
- return;
54
- }
55
- if (node.value.type !== 'ObjectExpression') {
56
- // If the value is a CSS object, safe to assume we're at a CSS selector
57
- return;
58
- }
59
- var cssSelector = getCssSelector(node);
60
- if (cssSelector === null) {
61
- return;
62
- }
63
- var tokens = cssSelector.split(/[, ]+/);
64
- if (!cssSelector.includes('@') && !tokens.every(function (token) {
65
- return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
66
- })) {
67
- context.report({
68
- messageId: 'no-nested-selectors',
69
- node: node.key
70
- });
71
- }
58
+ walkStyleProperties(node, references, importSources, function (_ref2) {
59
+ var key = _ref2.key,
60
+ value = _ref2.value;
61
+ if (value.type !== 'ObjectExpression') {
62
+ // If the value is a CSS object, safe to assume we're at a CSS selector
63
+ return;
64
+ }
65
+ var selectorText = getCssSelector(key);
66
+ if (selectorText === null) {
67
+ return;
68
+ }
69
+
70
+ // Ignore at-rules
71
+ if (selectorText.includes('@')) {
72
+ return;
73
+ }
74
+ try {
75
+ var selectorList = cssSelectorProcessor.astSync(selectorText);
76
+ if (!selectorList.nodes.every(isAllowedSelector)) {
77
+ context.report({
78
+ messageId: 'no-nested-selectors',
79
+ node: key
80
+ });
81
+ }
82
+ } catch (_) {
83
+ // If it is not parsable then `no-unsafe-selectors` will give it an error,
84
+ // we can ignore it here.
85
+ }
86
+ });
72
87
  }
73
88
  };
74
89
  }
@@ -4,10 +4,7 @@ import type { CSSPseudos } from '@compiled/react';
4
4
  * https://stackoverflow.com/a/71236280
5
5
  */
6
6
  type Validate<T extends true> = T;
7
- type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
8
- infer Head,
9
- ...infer Tail
10
- ] ? Head extends Seen ? {
7
+ type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [infer Head, ...infer Tail] ? Head extends Seen ? {
11
8
  ERROR: ['The following key appears more than once in the tuple:', Head];
12
9
  } : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen> : [Union] extends [never] ? true : {
13
10
  ERROR: ['Some keys are missing from the tuple:', Union];
package/index.js CHANGED
@@ -6,19 +6,19 @@ const path = require('path');
6
6
  const paths = require('tsconfig-paths');
7
7
 
8
8
  if (!require.extensions['.ts']) {
9
- // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
10
- require('ts-node').register({
11
- project: path.join(__dirname, 'tsconfig.json'),
12
- });
9
+ // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
10
+ require('ts-node').register({
11
+ project: path.join(__dirname, 'tsconfig.json'),
12
+ });
13
13
  }
14
14
 
15
15
  try {
16
- // We programatically register tsconfig paths here so it picks up the tsconfig here
17
- // instead of in root CWD.
18
- paths.register(paths.loadConfig(__dirname));
16
+ // We programatically register tsconfig paths here so it picks up the tsconfig here
17
+ // instead of in root CWD.
18
+ paths.register(paths.loadConfig(__dirname));
19
19
  } catch (e) {
20
- // eslint-disable-next-line no-console
21
- console.log(e);
20
+ // eslint-disable-next-line no-console
21
+ console.log(e);
22
22
  }
23
23
 
24
24
  module.exports = require('./src/index');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
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,7 +39,7 @@
39
39
  ".": "./src/index.tsx"
40
40
  },
41
41
  "dependencies": {
42
- "@atlaskit/eslint-utils": "^1.5.0",
42
+ "@atlaskit/eslint-utils": "^1.6.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@typescript-eslint/utils": "^5.48.1",
45
45
  "ajv": "^6.12.6",
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@af/formatting": "*",
56
56
  "@atlaskit/ds-lib": "^2.3.0",
57
- "@atlaskit/eslint-plugin-design-system": "^10.4.0",
57
+ "@atlaskit/eslint-plugin-design-system": "^10.6.0",
58
58
  "@atlassian/codegen": "*",
59
59
  "@compiled/eslint-plugin": "^0.13.6",
60
60
  "@types/eslint": "^8.56.6",