UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

84 lines 2.85 kB
import { createLintRule } from '../utils/create-lint-rule'; import { errorBoundary } from '../utils/error-boundary'; import { getConfig } from './config/get-config'; import { PATTERNS } from './config/patterns'; import { EmphasisElements } from './transformers/emphasis-elements'; import { ParagraphElements } from './transformers/paragraph-elements'; import { SpanElements } from './transformers/span-elements'; import { StrongElements } from './transformers/strong-elements'; var textDocsUrl = 'https://atlassian.design/components/primitives/text'; var rule = 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.length, type: 'array', items: { type: 'string', enum: 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 = getConfig(context.options[0]); return errorBoundary({ 'JSXElement[openingElement.name.name=span]': function JSXElementOpeningElementNameNameSpan(node) { return SpanElements.lint(node, { context: context, config: config }); }, 'JSXElement[openingElement.name.name=p]': function JSXElementOpeningElementNameNameP(node) { return ParagraphElements.lint(node, { context: context, config: config }); }, 'JSXElement[openingElement.name.name=strong]': function JSXElementOpeningElementNameNameStrong(node) { return StrongElements.lint(node, { context: context, config: config }); }, 'JSXElement[openingElement.name.name=em]': function JSXElementOpeningElementNameNameEm(node) { return EmphasisElements.lint(node, { context: context, config: config }); } }, config); } }); export default rule;