@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
84 lines • 2.57 kB
JavaScript
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';
const textDocsUrl = 'https://atlassian.design/components/primitives/text';
const 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 ${textDocsUrl} for additional guidance.`,
preferPrimitivesStackedText: `These paragraphs can be replaced with a "Text" and "Stack" primitives. See ${textDocsUrl} for additional guidance.`
}
},
create(context) {
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
const config = getConfig(context.options[0]);
return errorBoundary({
'JSXElement[openingElement.name.name=span]': node => {
return SpanElements.lint(node, {
context,
config
});
},
'JSXElement[openingElement.name.name=p]': node => {
return ParagraphElements.lint(node, {
context,
config
});
},
'JSXElement[openingElement.name.name=strong]': node => {
return StrongElements.lint(node, {
context,
config
});
},
'JSXElement[openingElement.name.name=em]': node => {
return EmphasisElements.lint(node, {
context,
config
});
}
}, config);
}
});
export default rule;