@atlaskit/eslint-plugin-design-system 10.17.2 → 10.17.3

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 10.17.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#134533](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/134533)
8
+ [`729d2ac5a7b41`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/729d2ac5a7b41) -
9
+ Disallow letter spacing and disallow font weight only when heading font token is used for
10
+ `use-latest-xcss-syntax-typography` rule.
11
+
3
12
  ## 10.17.2
4
13
 
5
14
  ### Patch Changes
@@ -3,12 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.error = exports.default = void 0;
6
+ exports.default = void 0;
7
7
  var _createRule = require("../utils/create-rule");
8
8
  var _errorBoundary = require("../utils/error-boundary");
9
9
  var _config = require("./config");
10
10
  var _linters = require("./linters");
11
- var error = exports.error = "Don't set fontSize, lineHeight, fontWeight properties on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.";
12
11
  var rule = (0, _createRule.createLintRule)({
13
12
  meta: {
14
13
  name: 'use-latest-xcss-syntax-typography',
@@ -21,18 +20,18 @@ var rule = (0, _createRule.createLintRule)({
21
20
  severity: 'warn'
22
21
  },
23
22
  messages: {
24
- noUnsafeTypographyProperties: error
23
+ noUnsafeTypographyProperties: "Don't set '{{ property }}' on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway."
25
24
  }
26
25
  },
27
26
  create: function create(context) {
28
27
  var config = (0, _config.getConfig)(context.options[0]);
29
28
  return (0, _errorBoundary.errorBoundary)({
30
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeight(node) {
29
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeightLetterSpacing(node) {
31
30
  return _linters.BannedProperty.lint(node, {
32
31
  context: context
33
32
  });
34
33
  },
35
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeight(node) {
34
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeightLetterSpacing(node) {
36
35
  return _linters.BannedProperty.lint(node, {
37
36
  context: context
38
37
  });
@@ -4,15 +4,52 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.BannedProperty = void 0;
7
- /* eslint-disable @repo/internal/react/require-jsdoc */
8
-
9
- var messageId = 'noUnsafeTypographyProperties';
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
+ 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); }
10
+ 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; } /* eslint-disable @repo/internal/react/require-jsdoc */
10
11
  var BannedProperty = exports.BannedProperty = {
11
12
  lint: function lint(node, _ref) {
12
13
  var context = _ref.context;
13
- context.report({
14
- node: node,
15
- messageId: messageId
16
- });
14
+ if (BannedProperty._check(node)) {
15
+ var property = 'fontSize, lineHeight, fontWeight or letterSpacing';
16
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
17
+ property = node.name;
18
+ } else if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Literal')) {
19
+ property = String(node.value);
20
+ }
21
+ context.report({
22
+ node: node,
23
+ messageId: 'noUnsafeTypographyProperties',
24
+ data: {
25
+ property: property
26
+ }
27
+ });
28
+ }
29
+ },
30
+ _check: function _check(node) {
31
+ // Prevent font weight being used in combination with heading tokens
32
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && node.name === 'fontWeight' || (0, _eslintCodemodUtils.isNodeOfType)(node, 'Literal') && node.value === 'fontWeight') {
33
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'ObjectExpression')) {
34
+ var _iterator = _createForOfIteratorHelper(node.parent.parent.properties),
35
+ _step;
36
+ try {
37
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
38
+ var property = _step.value;
39
+ if ((0, _eslintCodemodUtils.isNodeOfType)(property, 'Property') && (0, _eslintCodemodUtils.isNodeOfType)(property.value, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(property.value.callee, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(property.value.arguments[0], 'Literal')) {
40
+ if (property.value.callee.name === 'token' && typeof property.value.arguments[0].value === 'string' && property.value.arguments[0].value.includes('font.heading')) {
41
+ return true;
42
+ }
43
+ }
44
+ }
45
+ } catch (err) {
46
+ _iterator.e(err);
47
+ } finally {
48
+ _iterator.f();
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+ return true;
17
54
  }
18
55
  };
@@ -2,7 +2,6 @@ import { createLintRule } from '../utils/create-rule';
2
2
  import { errorBoundary } from '../utils/error-boundary';
3
3
  import { getConfig } from './config';
4
4
  import { BannedProperty } from './linters';
5
- export const error = `Don't set fontSize, lineHeight, fontWeight properties on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.`;
6
5
  const rule = createLintRule({
7
6
  meta: {
8
7
  name: 'use-latest-xcss-syntax-typography',
@@ -15,16 +14,16 @@ const rule = createLintRule({
15
14
  severity: 'warn'
16
15
  },
17
16
  messages: {
18
- noUnsafeTypographyProperties: error
17
+ noUnsafeTypographyProperties: `Don't set '{{ property }}' on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.`
19
18
  }
20
19
  },
21
20
  create(context) {
22
21
  const config = getConfig(context.options[0]);
23
22
  return errorBoundary({
24
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight)/]': node => BannedProperty.lint(node, {
23
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': node => BannedProperty.lint(node, {
25
24
  context
26
25
  }),
27
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight)/]': node => BannedProperty.lint(node, {
26
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': node => BannedProperty.lint(node, {
28
27
  context
29
28
  })
30
29
  }, config);
@@ -1,13 +1,40 @@
1
1
  /* eslint-disable @repo/internal/react/require-jsdoc */
2
2
 
3
- const messageId = 'noUnsafeTypographyProperties';
3
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
4
  export const BannedProperty = {
5
5
  lint(node, {
6
6
  context
7
7
  }) {
8
- context.report({
9
- node,
10
- messageId
11
- });
8
+ if (BannedProperty._check(node)) {
9
+ let property = 'fontSize, lineHeight, fontWeight or letterSpacing';
10
+ if (isNodeOfType(node, 'Identifier')) {
11
+ property = node.name;
12
+ } else if (isNodeOfType(node, 'Literal')) {
13
+ property = String(node.value);
14
+ }
15
+ context.report({
16
+ node,
17
+ messageId: 'noUnsafeTypographyProperties',
18
+ data: {
19
+ property
20
+ }
21
+ });
22
+ }
23
+ },
24
+ _check(node) {
25
+ // Prevent font weight being used in combination with heading tokens
26
+ if (isNodeOfType(node, 'Identifier') && node.name === 'fontWeight' || isNodeOfType(node, 'Literal') && node.value === 'fontWeight') {
27
+ if (isNodeOfType(node.parent.parent, 'ObjectExpression')) {
28
+ for (const property of node.parent.parent.properties) {
29
+ if (isNodeOfType(property, 'Property') && isNodeOfType(property.value, 'CallExpression') && isNodeOfType(property.value.callee, 'Identifier') && isNodeOfType(property.value.arguments[0], 'Literal')) {
30
+ if (property.value.callee.name === 'token' && typeof property.value.arguments[0].value === 'string' && property.value.arguments[0].value.includes('font.heading')) {
31
+ return true;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return false;
37
+ }
38
+ return true;
12
39
  }
13
40
  };
@@ -2,7 +2,6 @@ import { createLintRule } from '../utils/create-rule';
2
2
  import { errorBoundary } from '../utils/error-boundary';
3
3
  import { getConfig } from './config';
4
4
  import { BannedProperty } from './linters';
5
- export var error = "Don't set fontSize, lineHeight, fontWeight properties on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.";
6
5
  var rule = createLintRule({
7
6
  meta: {
8
7
  name: 'use-latest-xcss-syntax-typography',
@@ -15,18 +14,18 @@ var rule = createLintRule({
15
14
  severity: 'warn'
16
15
  },
17
16
  messages: {
18
- noUnsafeTypographyProperties: error
17
+ noUnsafeTypographyProperties: "Don't set '{{ property }}' on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway."
19
18
  }
20
19
  },
21
20
  create: function create(context) {
22
21
  var config = getConfig(context.options[0]);
23
22
  return errorBoundary({
24
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeight(node) {
23
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeightLetterSpacing(node) {
25
24
  return BannedProperty.lint(node, {
26
25
  context: context
27
26
  });
28
27
  },
29
- 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeight(node) {
28
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeightLetterSpacing(node) {
30
29
  return BannedProperty.lint(node, {
31
30
  context: context
32
31
  });
@@ -1,12 +1,51 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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
+ 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; }
1
4
  /* eslint-disable @repo/internal/react/require-jsdoc */
2
5
 
3
- var messageId = 'noUnsafeTypographyProperties';
6
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
7
  export var BannedProperty = {
5
8
  lint: function lint(node, _ref) {
6
9
  var context = _ref.context;
7
- context.report({
8
- node: node,
9
- messageId: messageId
10
- });
10
+ if (BannedProperty._check(node)) {
11
+ var property = 'fontSize, lineHeight, fontWeight or letterSpacing';
12
+ if (isNodeOfType(node, 'Identifier')) {
13
+ property = node.name;
14
+ } else if (isNodeOfType(node, 'Literal')) {
15
+ property = String(node.value);
16
+ }
17
+ context.report({
18
+ node: node,
19
+ messageId: 'noUnsafeTypographyProperties',
20
+ data: {
21
+ property: property
22
+ }
23
+ });
24
+ }
25
+ },
26
+ _check: function _check(node) {
27
+ // Prevent font weight being used in combination with heading tokens
28
+ if (isNodeOfType(node, 'Identifier') && node.name === 'fontWeight' || isNodeOfType(node, 'Literal') && node.value === 'fontWeight') {
29
+ if (isNodeOfType(node.parent.parent, 'ObjectExpression')) {
30
+ var _iterator = _createForOfIteratorHelper(node.parent.parent.properties),
31
+ _step;
32
+ try {
33
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
34
+ var property = _step.value;
35
+ if (isNodeOfType(property, 'Property') && isNodeOfType(property.value, 'CallExpression') && isNodeOfType(property.value.callee, 'Identifier') && isNodeOfType(property.value.arguments[0], 'Literal')) {
36
+ if (property.value.callee.name === 'token' && typeof property.value.arguments[0].value === 'string' && property.value.arguments[0].value.includes('font.heading')) {
37
+ return true;
38
+ }
39
+ }
40
+ }
41
+ } catch (err) {
42
+ _iterator.e(err);
43
+ } finally {
44
+ _iterator.f();
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ return true;
11
50
  }
12
51
  };
@@ -1,4 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
- export declare const error = "Don't set fontSize, lineHeight, fontWeight properties on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.";
3
2
  declare const rule: Rule.RuleModule;
4
3
  export default rule;
@@ -3,4 +3,5 @@ export declare const BannedProperty: {
3
3
  lint(node: Rule.Node, { context }: {
4
4
  context: Rule.RuleContext;
5
5
  }): void;
6
+ _check(node: Rule.Node): boolean;
6
7
  };
@@ -1,4 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
- export declare const error = "Don't set fontSize, lineHeight, fontWeight properties on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.";
3
2
  declare const rule: Rule.RuleModule;
4
3
  export default rule;
@@ -3,4 +3,5 @@ export declare const BannedProperty: {
3
3
  lint(node: Rule.Node, { context }: {
4
4
  context: Rule.RuleContext;
5
5
  }): void;
6
+ _check(node: Rule.Node): boolean;
6
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "10.17.2",
4
+ "version": "10.17.3",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -17,7 +17,10 @@
17
17
  "name": "ESLint plugin",
18
18
  "category": "Tooling"
19
19
  },
20
- "runReact18": true
20
+ "runReact18": true,
21
+ "toolingLabels": [
22
+ "linting"
23
+ ]
21
24
  },
22
25
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
23
26
  "main": "dist/cjs/index.js",