@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
46 lines • 1.84 kB
JavaScript
import { isNodeOfType } from 'eslint-codemod-utils';
import { createLintRule } from '../utils/create-lint-rule';
import { restrictedPaths } from './paths';
var rule = createLintRule({
meta: {
name: 'no-unsupported-drag-and-drop-libraries',
type: 'problem',
docs: {
description: 'Disallow importing unsupported drag and drop modules.',
recommended: true,
severity: 'error'
},
messages: {
path: "The '{{importSource}}' import is restricted from being used. Please use Pragmatic drag and drop: our performance focused drag and drop library that can be used to power any experience for any techstack. See https://staging.atlassian.design/components/pragmatic-drag-and-drop/. {{customMessage}}"
}
},
create: function create(context) {
function checkNode(node) {
if (isNodeOfType(node, 'ExportAllDeclaration') || isNodeOfType(node, 'ExportNamedDeclaration') || isNodeOfType(node, 'ImportDeclaration')) {
restrictedPaths.find(function (_ref) {
var _node$source;
var path = _ref.path,
message = _ref.message;
var source = (_node$source = node.source) === null || _node$source === void 0 || (_node$source = _node$source.value) === null || _node$source === void 0 ? void 0 : _node$source.toString();
if (source && (source === path || source.startsWith(path))) {
context.report({
node: node,
messageId: 'path',
data: {
importSource: source,
customMessage: message
}
});
}
});
}
}
return {
ImportDeclaration: checkNode,
ExportAllDeclaration: checkNode,
ExportNamedDeclaration: checkNode,
ExportDefaultDeclaration: checkNode
};
}
});
export default rule;