@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
90 lines (89 loc) • 3.12 kB
JavaScript
;
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 _emphasisElements = require("./transformers/emphasis-elements");
var _paragraphElements = require("./transformers/paragraph-elements");
var _spanElements = require("./transformers/span-elements");
var _strongElements = require("./transformers/strong-elements");
var textDocsUrl = 'https://atlassian.design/components/primitives/text';
var rule = (0, _createLintRule.createLintRule)({
meta: {
name: 'use-primitives-text',
type: 'suggestion',
fixable: 'code',
hasSuggestions: true,
schema: [{
type: 'object',
properties: {
failSilently: {
type: 'boolean'
},
inheritColor: {
type: 'boolean'
},
enableUnsafeAutofix: {
type: 'boolean'
},
enableUnsafeReport: {
type: 'boolean'
},
patterns: {
maxLength: _patterns.PATTERNS.length,
type: 'array',
items: {
type: 'string',
enum: _patterns.PATTERNS
},
uniqueItems: true
}
},
additionalProperties: false
}],
docs: {
description: 'Encourage the usage of text components.',
recommended: true,
severity: 'warn'
},
messages: {
preferPrimitivesText: "This element can be replaced with a \"Text\" primitive. See ".concat(textDocsUrl, " for additional guidance."),
preferPrimitivesStackedText: "These paragraphs can be replaced with a \"Text\" and \"Stack\" primitives. See ".concat(textDocsUrl, " for additional guidance.")
}
},
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)({
'JSXElement[openingElement.name.name=span]': function JSXElementOpeningElementNameNameSpan(node) {
return _spanElements.SpanElements.lint(node, {
context: context,
config: config
});
},
'JSXElement[openingElement.name.name=p]': function JSXElementOpeningElementNameNameP(node) {
return _paragraphElements.ParagraphElements.lint(node, {
context: context,
config: config
});
},
'JSXElement[openingElement.name.name=strong]': function JSXElementOpeningElementNameNameStrong(node) {
return _strongElements.StrongElements.lint(node, {
context: context,
config: config
});
},
'JSXElement[openingElement.name.name=em]': function JSXElementOpeningElementNameNameEm(node) {
return _emphasisElements.EmphasisElements.lint(node, {
context: context,
config: config
});
}
}, config);
}
});
var _default = exports.default = rule;