@atlaskit/eslint-plugin-ui-styling-standard 0.7.2 → 0.8.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -1
  3. package/constellation/index/overview.mdx +2 -1
  4. package/constellation/no-nested-selectors/usage.mdx +60 -0
  5. package/dist/cjs/presets/all.codegen.js +3 -4
  6. package/dist/cjs/presets/recommended.codegen.js +3 -4
  7. package/dist/cjs/rules/convert-props-syntax/index.js +5 -0
  8. package/dist/cjs/rules/external-rules.js +1 -27
  9. package/dist/cjs/rules/index.codegen.js +4 -2
  10. package/dist/cjs/rules/no-nested-selectors/index.js +82 -0
  11. package/dist/cjs/rules/utils/create-rule.js +4 -29
  12. package/dist/es2019/presets/all.codegen.js +3 -4
  13. package/dist/es2019/presets/recommended.codegen.js +3 -4
  14. package/dist/es2019/rules/convert-props-syntax/index.js +5 -0
  15. package/dist/es2019/rules/external-rules.js +1 -27
  16. package/dist/es2019/rules/index.codegen.js +4 -2
  17. package/dist/es2019/rules/no-nested-selectors/index.js +71 -0
  18. package/dist/es2019/rules/utils/create-rule.js +2 -23
  19. package/dist/esm/presets/all.codegen.js +3 -4
  20. package/dist/esm/presets/recommended.codegen.js +3 -4
  21. package/dist/esm/rules/convert-props-syntax/index.js +5 -0
  22. package/dist/esm/rules/external-rules.js +1 -27
  23. package/dist/esm/rules/index.codegen.js +4 -2
  24. package/dist/esm/rules/no-nested-selectors/index.js +76 -0
  25. package/dist/esm/rules/utils/create-rule.js +2 -25
  26. package/dist/types/index.codegen.d.ts +4 -6
  27. package/dist/types/presets/all.codegen.d.ts +3 -4
  28. package/dist/types/presets/recommended.codegen.d.ts +3 -4
  29. package/dist/types/rules/external-rules.d.ts +1 -1
  30. package/dist/types/rules/index.codegen.d.ts +1 -0
  31. package/dist/types/rules/no-nested-selectors/index.d.ts +2 -0
  32. package/dist/types/rules/utils/create-rule.d.ts +1 -58
  33. package/dist/types-ts4.5/index.codegen.d.ts +4 -6
  34. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -4
  35. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -4
  36. package/dist/types-ts4.5/rules/external-rules.d.ts +1 -1
  37. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  38. package/dist/types-ts4.5/rules/no-nested-selectors/index.d.ts +2 -0
  39. package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -58
  40. package/package.json +3 -3
  41. package/scripts/codegen.tsx +4 -1
  42. package/src/presets/all.codegen.tsx +3 -13
  43. package/src/presets/recommended.codegen.tsx +3 -13
  44. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +52 -0
  45. package/src/rules/convert-props-syntax/index.tsx +10 -0
  46. package/src/rules/external-rules.tsx +2 -31
  47. package/src/rules/index.codegen.tsx +3 -1
  48. package/src/rules/no-nested-selectors/README.md +58 -0
  49. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +236 -0
  50. package/src/rules/no-nested-selectors/index.tsx +115 -0
  51. package/src/rules/utils/create-rule.tsx +5 -69
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#88029](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88029) [`01d74d2899d5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01d74d2899d5) - Disabled ESlint rule convert-props-syntax on .attrs() calls
8
+ - [#87476](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87476) [`af296d200ad2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/af296d200ad2) - Internal refactoring to use `getCreateLintRule` from `@atlaskit/eslint-utils`
9
+ - Updated dependencies
10
+
11
+ ## 0.8.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#87972](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87972) [`1f420b2c4a9f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1f420b2c4a9f) - The `@atlaskit/design-system/no-styled-tagged-template-expression` rule will now lint against `styled-components` by default in the preset configurations.
16
+
17
+ ### Patch Changes
18
+
19
+ - [#86779](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/86779) [`4b4bbf195e39`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4b4bbf195e39) - Created no nested selectors eslint rule to prevent setting styles for child elements
20
+
3
21
  ## 0.7.2
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -16,8 +16,9 @@ Not intended for use outside the Atlassian frontend repository.
16
16
  | <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
17
17
  | <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | 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. | Yes | | |
18
18
  | <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
19
- | <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Disallows important style declarations | Yes | | |
19
+ | <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
20
20
  | <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
21
+ | <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
21
22
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
22
23
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
23
24
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
@@ -14,8 +14,9 @@ but more are planned to support the standard over time.
14
14
  | <a href="convert-props-syntax/usage">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
15
15
  | <a href="local-cx-xcss/usage">local-cx-xcss</a> | 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. | Yes | | |
16
16
  | <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
17
- | <a href="no-container-queries/usage">no-container-queries</a> | Disallows important style declarations | Yes | | |
17
+ | <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
18
18
  | <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
19
+ | <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
19
20
  | <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
20
21
  | <a href="no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
21
22
  | <a href="no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
@@ -0,0 +1,60 @@
1
+ # no-nested-selectors
2
+
3
+ This rule prevents the usage of the nested selectors in style declarations. Avoid setting styles for any child elements or elements that require context from other elements.
4
+
5
+ ## Examples
6
+
7
+ ### Incorrect
8
+
9
+ ```js
10
+ import { css } from '@compiled/react';
11
+ const styles = css({
12
+ h2: {
13
+ fontSize: '1.5rem',
14
+ },
15
+ });
16
+ ```
17
+
18
+ ```js
19
+ import { styled } from '@compiled/react';
20
+ const Component = styled.div({
21
+ '*': {
22
+ padding: 0,
23
+ },
24
+ });
25
+ ```
26
+
27
+ ```js
28
+ import { styled } from '@compiled/react';
29
+ const Component = styled.div({
30
+ '.myclass': {
31
+ padding: 0,
32
+ },
33
+ });
34
+ ```
35
+
36
+ ### Correct
37
+
38
+ ```js
39
+ import { css } from '@compiled/react';
40
+ const styles = css({
41
+ display: 'flex',
42
+ flexDirection: 'column',
43
+ });
44
+ ```
45
+
46
+ ## Options
47
+
48
+ ### importSources
49
+
50
+ By default, this rule will check `css` usages from:
51
+
52
+ - `@atlaskit/css`
53
+ - `@atlaskit/primitives`
54
+ - `@compiled/react`
55
+ - `@emotion/react`
56
+ - `@emotion/core`
57
+ - `@emotion/styled`
58
+ - `styled-components`
59
+
60
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
9
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -17,14 +17,13 @@ var _default = exports.default = {
17
17
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
18
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
20
21
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
21
22
  excludeReactComponents: true
22
23
  }],
23
24
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
24
25
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
25
- '@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
26
- importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
27
- }],
26
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
28
27
  '@compiled/no-suppress-xcss': 'warn',
29
28
  '@compiled/no-js-xcss': 'warn',
30
29
  '@atlaskit/design-system/no-empty-styled-expression': ['warn', {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
9
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -17,14 +17,13 @@ var _default = exports.default = {
17
17
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
18
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
20
21
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
21
22
  excludeReactComponents: true
22
23
  }],
23
24
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
24
25
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
25
- '@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
26
- importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
27
- }],
26
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
28
27
  '@compiled/no-suppress-xcss': 'warn',
29
28
  '@compiled/no-js-xcss': 'warn',
30
29
  '@atlaskit/design-system/no-empty-styled-expression': ['warn', {
@@ -382,6 +382,11 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
382
382
  return {
383
383
  'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
384
384
  var references = context.getScope().references;
385
+
386
+ // Rule should ignore .attrs() calls
387
+ if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
388
+ return;
389
+ }
385
390
  var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
386
391
  if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
387
392
  return;
@@ -8,29 +8,6 @@ var _createRule = require("./utils/create-rule");
8
8
  /** External rules must be scoped, have a display name, and external urls. */
9
9
 
10
10
  var importSources = ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components'];
11
-
12
- /**
13
- * Same as importSources, but excludes `styled-components` because the type-checking
14
- * for `styled-components` does not support the `no-styled-tagged-template-expression`
15
- * lint output for this:
16
- *
17
- * export const Container = styled(Section)`
18
- * max-height: ${gridSize * 46}px;
19
- * overflow: auto;
20
- * `;
21
- *
22
- * export const ErrorStateContainer = styled(Container)`
23
- * margin: ${
24
- * (props: any) =>
25
- * props.canManageAutomations // Use negative margin to reduce whitespace when the Footer component is shown
26
- * ? `${gridSize * -4}px ${gridSize * 2}px`
27
- * : `0 ${gridSize * 2}px`
28
- * };
29
- * `;
30
- */
31
- var noStyledTaggedTemplateExpressionImportSources = ['@compiled/react', '@atlaskit/css',
32
- // doesn't do anything because @atlaskit/css doesn't expose a styled API
33
- '@emotion/core', '@emotion/react', '@emotion/styled'];
34
11
  var externalRules = exports.externalRules = [{
35
12
  name: '@atlaskit/design-system/consistent-css-prop-usage',
36
13
  displayName: 'consistent-css-prop-usage',
@@ -83,10 +60,7 @@ var externalRules = exports.externalRules = [{
83
60
  url: (0, _createRule.getRuleUrl)('no-styled-tagged-template-expression'),
84
61
  externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
85
62
  recommended: true,
86
- severity: 'warn',
87
- pluginConfig: {
88
- importSources: noStyledTaggedTemplateExpressionImportSources
89
- }
63
+ severity: 'warn'
90
64
  }
91
65
  }, {
92
66
  name: '@compiled/no-suppress-xcss',
@@ -10,9 +10,10 @@ var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
10
10
  var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
11
11
  var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
12
12
  var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
13
+ var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
13
14
  /**
14
15
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
15
- * @codegen <<SignedSource::3504ce124f49b7eca8abafb5a0bd6884>>
16
+ * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
16
17
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
17
18
  */
18
19
  var _default = exports.default = {
@@ -20,5 +21,6 @@ var _default = exports.default = {
20
21
  'local-cx-xcss': _localCxXcss.default,
21
22
  'no-classname-prop': _noClassnameProp.default,
22
23
  'no-container-queries': _noContainerQueries.default,
23
- 'no-important-styles': _noImportantStyles.default
24
+ 'no-important-styles': _noImportantStyles.default,
25
+ 'no-nested-selectors': _noNestedSelectors.default
24
26
  };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.default = void 0;
7
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
8
+ var _createRule = require("../utils/create-rule");
9
+ var schema = [{
10
+ type: 'object',
11
+ properties: {
12
+ importSources: {
13
+ type: 'array',
14
+ items: {
15
+ type: 'string'
16
+ },
17
+ uniqueItems: true
18
+ }
19
+ }
20
+ }];
21
+ var getCssSelector = function getCssSelector(node) {
22
+ if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
23
+ return node.key.value;
24
+ }
25
+ if (node.key.type === 'Identifier' && typeof node.key.name === 'string') {
26
+ return node.key.name;
27
+ }
28
+ if (node.key.type === 'TemplateLiteral') {
29
+ return node.key.quasis.map(function (quasi) {
30
+ return quasi.value.raw;
31
+ }).join(' ');
32
+ }
33
+ return null;
34
+ };
35
+ var rule = exports.rule = (0, _createRule.createLintRule)({
36
+ meta: {
37
+ name: 'no-nested-selectors',
38
+ docs: {
39
+ description: 'Prevents usage of nested selectors within css styling',
40
+ recommended: true,
41
+ severity: 'warn'
42
+ },
43
+ messages: {
44
+ 'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
45
+ },
46
+ type: 'problem',
47
+ schema: schema
48
+ },
49
+ create: function create(context) {
50
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
51
+ return {
52
+ 'CallExpression Property': function CallExpressionProperty(node) {
53
+ var _context$getScope = context.getScope(),
54
+ references = _context$getScope.references;
55
+ var ancestors = context.getAncestors();
56
+ if (ancestors.every(function (ancestor) {
57
+ return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !((0, _isSupportedImport.isCss)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isStyled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isKeyframes)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isCssMap)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isXcss)(ancestor.callee, references, importSources));
58
+ })) {
59
+ return;
60
+ }
61
+ if (node.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 cssSelector = getCssSelector(node);
66
+ if (cssSelector === null) {
67
+ return;
68
+ }
69
+ var tokens = cssSelector.split(/[, ]+/);
70
+ if (!tokens.every(function (token) {
71
+ return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
72
+ })) {
73
+ context.report({
74
+ messageId: 'no-nested-selectors',
75
+ node: node.key
76
+ });
77
+ }
78
+ }
79
+ };
80
+ }
81
+ });
82
+ var _default = exports.default = rule;
@@ -3,41 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createRule = exports.createLintRule = void 0;
7
- exports.getPathSafeName = getPathSafeName;
6
+ exports.createLintRule = void 0;
8
7
  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
- });
8
+ var _createRule = require("@atlaskit/eslint-utils/create-rule");
24
9
  /**
25
10
  * Tiny wrapped over the ESLint rule module type that ensures
26
11
  * there is a docs link to our ESLint plugin documentation page,
27
12
  * as well as improving type support.
28
13
  */
29
- var createLintRule = exports.createLintRule = function createLintRule(rule) {
30
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
31
- return rule;
32
- };
14
+ var createLintRule = exports.createLintRule = (0, _createRule.getCreateLintRule)(getRuleUrl);
33
15
  function getRuleUrl(ruleName) {
34
- var name = getPathSafeName(ruleName);
16
+ var name = (0, _createRule.getPathSafeName)(ruleName);
35
17
  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
18
  }
@@ -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::2e134e292f949b29bfd0b29d128e684a>>
3
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -11,14 +11,13 @@ export default {
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
12
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
13
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
14
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
14
15
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
15
16
  excludeReactComponents: true
16
17
  }],
17
18
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
18
19
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
19
- '@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
20
- importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
21
- }],
20
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
22
21
  '@compiled/no-suppress-xcss': 'warn',
23
22
  '@compiled/no-js-xcss': 'warn',
24
23
  '@atlaskit/design-system/no-empty-styled-expression': ['warn', {
@@ -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::2e134e292f949b29bfd0b29d128e684a>>
3
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -11,14 +11,13 @@ export default {
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
12
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
13
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
14
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
14
15
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
15
16
  excludeReactComponents: true
16
17
  }],
17
18
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
18
19
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
19
- '@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
20
- importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
21
- }],
20
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
22
21
  '@compiled/no-suppress-xcss': 'warn',
23
22
  '@compiled/no-js-xcss': 'warn',
24
23
  '@atlaskit/design-system/no-empty-styled-expression': ['warn', {
@@ -278,6 +278,11 @@ export const rule = createLintRule({
278
278
  return {
279
279
  'CallExpression[callee.type="MemberExpression"]': node => {
280
280
  const references = context.getScope().references;
281
+
282
+ // Rule should ignore .attrs() calls
283
+ if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
284
+ return;
285
+ }
281
286
  const callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
282
287
  if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
283
288
  return;
@@ -3,29 +3,6 @@ import { getRuleUrl } from './utils/create-rule';
3
3
  /** External rules must be scoped, have a display name, and external urls. */
4
4
 
5
5
  const importSources = ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components'];
6
-
7
- /**
8
- * Same as importSources, but excludes `styled-components` because the type-checking
9
- * for `styled-components` does not support the `no-styled-tagged-template-expression`
10
- * lint output for this:
11
- *
12
- * export const Container = styled(Section)`
13
- * max-height: ${gridSize * 46}px;
14
- * overflow: auto;
15
- * `;
16
- *
17
- * export const ErrorStateContainer = styled(Container)`
18
- * margin: ${
19
- * (props: any) =>
20
- * props.canManageAutomations // Use negative margin to reduce whitespace when the Footer component is shown
21
- * ? `${gridSize * -4}px ${gridSize * 2}px`
22
- * : `0 ${gridSize * 2}px`
23
- * };
24
- * `;
25
- */
26
- const noStyledTaggedTemplateExpressionImportSources = ['@compiled/react', '@atlaskit/css',
27
- // doesn't do anything because @atlaskit/css doesn't expose a styled API
28
- '@emotion/core', '@emotion/react', '@emotion/styled'];
29
6
  export const externalRules = [{
30
7
  name: '@atlaskit/design-system/consistent-css-prop-usage',
31
8
  displayName: 'consistent-css-prop-usage',
@@ -78,10 +55,7 @@ export const externalRules = [{
78
55
  url: getRuleUrl('no-styled-tagged-template-expression'),
79
56
  externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
80
57
  recommended: true,
81
- severity: 'warn',
82
- pluginConfig: {
83
- importSources: noStyledTaggedTemplateExpressionImportSources
84
- }
58
+ severity: 'warn'
85
59
  }
86
60
  }, {
87
61
  name: '@compiled/no-suppress-xcss',
@@ -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::3504ce124f49b7eca8abafb5a0bd6884>>
3
+ * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
@@ -8,10 +8,12 @@ import localCxXcss from './local-cx-xcss';
8
8
  import noClassnameProp from './no-classname-prop';
9
9
  import noContainerQueries from './no-container-queries';
10
10
  import noImportantStyles from './no-important-styles';
11
+ import noNestedSelectors from './no-nested-selectors';
11
12
  export default {
12
13
  'convert-props-syntax': convertPropsSyntax,
13
14
  'local-cx-xcss': localCxXcss,
14
15
  'no-classname-prop': noClassnameProp,
15
16
  'no-container-queries': noContainerQueries,
16
- 'no-important-styles': noImportantStyles
17
+ 'no-important-styles': noImportantStyles,
18
+ 'no-nested-selectors': noNestedSelectors
17
19
  };
@@ -0,0 +1,71 @@
1
+ import { isStyled, isCss, isKeyframes, isCssMap, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const schema = [{
4
+ type: 'object',
5
+ properties: {
6
+ importSources: {
7
+ type: 'array',
8
+ items: {
9
+ type: 'string'
10
+ },
11
+ uniqueItems: true
12
+ }
13
+ }
14
+ }];
15
+ const getCssSelector = node => {
16
+ if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
17
+ return node.key.value;
18
+ }
19
+ if (node.key.type === 'Identifier' && typeof node.key.name === 'string') {
20
+ return node.key.name;
21
+ }
22
+ if (node.key.type === 'TemplateLiteral') {
23
+ return node.key.quasis.map(quasi => quasi.value.raw).join(' ');
24
+ }
25
+ return null;
26
+ };
27
+ export const rule = createLintRule({
28
+ meta: {
29
+ name: 'no-nested-selectors',
30
+ docs: {
31
+ description: 'Prevents usage of nested selectors within css styling',
32
+ recommended: true,
33
+ severity: 'warn'
34
+ },
35
+ messages: {
36
+ 'no-nested-selectors': 'Please avoid setting styles for child elements or elements that require context from other elements.'
37
+ },
38
+ type: 'problem',
39
+ schema
40
+ },
41
+ create(context) {
42
+ const importSources = getImportSources(context);
43
+ return {
44
+ 'CallExpression Property': node => {
45
+ const {
46
+ references
47
+ } = context.getScope();
48
+ const ancestors = context.getAncestors();
49
+ if (ancestors.every(ancestor => ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isKeyframes(ancestor.callee, references, importSources) || isCssMap(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources)))) {
50
+ return;
51
+ }
52
+ if (node.value.type !== 'ObjectExpression') {
53
+ // If the value is a CSS object, safe to assume we're at a CSS selector
54
+ return;
55
+ }
56
+ const cssSelector = getCssSelector(node);
57
+ if (cssSelector === null) {
58
+ return;
59
+ }
60
+ const tokens = cssSelector.split(/[, ]+/);
61
+ if (!tokens.every(token => token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&'))) {
62
+ context.report({
63
+ messageId: 'no-nested-selectors',
64
+ node: node.key
65
+ });
66
+ }
67
+ }
68
+ };
69
+ }
70
+ });
71
+ export default rule;
@@ -1,33 +1,12 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies
1
+ import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
3
2
 
4
- /**
5
- * We are moving to our own small abstraction to create a lint rule that we have the power
6
- * to change and mold to our own needs.
7
- *
8
- * @see createLintRule
9
- *
10
- * @private
11
- * @deprecated
12
- */
13
- export const createRule = ESLintUtils.RuleCreator(name => getRuleUrl(name));
14
3
  /**
15
4
  * Tiny wrapped over the ESLint rule module type that ensures
16
5
  * there is a docs link to our ESLint plugin documentation page,
17
6
  * as well as improving type support.
18
7
  */
19
- export const createLintRule = rule => {
20
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
21
- return rule;
22
- };
8
+ export const createLintRule = getCreateLintRule(getRuleUrl);
23
9
  export function getRuleUrl(ruleName) {
24
10
  const name = getPathSafeName(ruleName);
25
11
  return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
26
- }
27
-
28
- /**
29
- * If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
30
- */
31
- export function getPathSafeName(ruleName) {
32
- return ruleName.replace('/', '-');
33
12
  }
@@ -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::2e134e292f949b29bfd0b29d128e684a>>
3
+ * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -11,14 +11,13 @@ export default {
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
12
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
13
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
14
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
14
15
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
15
16
  excludeReactComponents: true
16
17
  }],
17
18
  '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
18
19
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
19
- '@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
20
- importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
21
- }],
20
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
22
21
  '@compiled/no-suppress-xcss': 'warn',
23
22
  '@compiled/no-js-xcss': 'warn',
24
23
  '@atlaskit/design-system/no-empty-styled-expression': ['warn', {