UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

84 lines • 3.02 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: "Use named Text from @atlaskit/primitives/compiled/text with the appropriate size. Preserve paragraph semantics with as=\"p\" where applicable; see ".concat(textDocsUrl, "."), preferPrimitivesStackedText: "Use compiled Text for each paragraph inside a compiled Stack, with space set to a matching space.* token. Preserve paragraph semantics with Text as=\"p\" and choose spacing that retains the intended layout; see ".concat(textDocsUrl, ".") } }, 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;