@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
93 lines (92 loc) • 4.76 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 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: 'Use Text or Heading with the appropriate size instead of setting {{ property }} in legacy xcss(). Their supported props and complete font.* tokens keep typography consistent.',
noRestrictedTypographyPropertiesHeading: 'Remove the {{ property }} override from this legacy xcss() heading style. Choose Heading size or a complete font.heading.* token instead of overriding one part of the heading typography.',
noRestrictedCapitalisation: 'Remove textTransform: uppercase from this style and use sentence case in the authored text. Preserve required casing for product names and acronyms.',
noWrappedTokenTypographyValues: "Inside legacy xcss(), pass a bare typography token name, for example font: 'font.heading.medium', rather than token('font.heading.medium'). Compiled cssMap() uses token() calls instead."
}
},
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;