@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
94 lines (93 loc) • 4.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _createLintRule = require("../utils/create-lint-rule");
var _errorBoundary = require("../utils/error-boundary");
var _getConfig = require("./config/get-config");
var _patterns = require("./config/patterns");
var _restrictedCapitalisation = require("./linters/restricted-capitalisation");
var _restrictedProperty = require("./linters/restricted-property");
var _wrappedTokenValue = require("./linters/wrapped-token-value");
var typescriptErrorMessage = 'There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.';
var rule = (0, _createLintRule.createLintRule)({
meta: {
name: 'use-latest-xcss-syntax-typography',
type: 'problem',
fixable: 'code',
hasSuggestions: false,
schema: [{
type: 'object',
properties: {
failSilently: {
type: 'boolean'
},
patterns: {
maxLength: _patterns.PATTERNS.length,
type: 'array',
items: {
type: 'string',
enum: _patterns.PATTERNS
},
uniqueItems: true
}
},
additionalProperties: false
}],
docs: {
description: 'Prohibits use of unsafe styling properties in xcss. Please use Text/Heading primitives instead.',
recommended: true,
severity: 'warn'
},
messages: {
noRestrictedTypographyProperties: "Don't set '{{ property }}' on xcss as it allows invalid combinations of typography tokens. ".concat(typescriptErrorMessage),
noRestrictedTypographyPropertiesHeading: "Don't set '{{ property }}' on xcss in combination with 'font' heading tokens. ".concat(typescriptErrorMessage),
noRestrictedCapitalisation: "Avoid using ALL CAPS as it reduces readability and is bad for accessibility.",
noWrappedTokenTypographyValues: "Don't wrap typography tokens in xcss. ".concat(typescriptErrorMessage)
}
},
create: function create(context) {
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
var config = (0, _getConfig.getConfig)(context.options[0]);
return (0, _errorBoundary.errorBoundary)({
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__IdentifierName_FontSizeLineHeightFontWeightLetterSpacing_(node) {
return _restrictedProperty.RestrictedProperty.lint(node, {
context: context,
config: config
});
},
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__LiteralValue_FontSizeLineHeightFontWeightLetterSpacing_(node) {
return _restrictedProperty.RestrictedProperty.lint(node, {
context: context,
config: config
});
},
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=textTransform]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__IdentifierNameTextTransform(node) {
return _restrictedCapitalisation.RestrictedCapitalisation.lint(node, {
context: context,
config: config
});
},
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=textTransform]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__LiteralValueTextTransform(node) {
return _restrictedCapitalisation.RestrictedCapitalisation.lint(node, {
context: context,
config: config
});
},
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__IdentifierName_FontFontFamilyFontWeight_(node) {
return _wrappedTokenValue.WrappedTokenValue.lint(node, {
context: context,
config: config
});
},
'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcss_ObjectExpression__Property__LiteralValue_FontFontFamilyFontWeight_(node) {
return _wrappedTokenValue.WrappedTokenValue.lint(node, {
context: context,
config: config
});
}
}, config);
}
});
var _default = exports.default = rule;