@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
47 lines • 1.58 kB
JavaScript
import { isNodeOfType } from 'eslint-codemod-utils';
import { createLintRule } from '../utils/create-lint-rule';
import { restrictedPaths } from './paths';
const rule = createLintRule({
meta: {
name: 'no-banned-imports',
type: 'problem',
docs: {
description: 'Disallow importing banned modules.',
recommended: true,
severity: 'error'
},
messages: {
path: "The '{{importSource}}' import is restricted from being used. {{customMessage}}"
}
},
create(context) {
function checkNode(node) {
if (isNodeOfType(node, 'ExportAllDeclaration') || isNodeOfType(node, 'ExportNamedDeclaration') || isNodeOfType(node, 'ImportDeclaration')) {
restrictedPaths.find(({
path,
message
}) => {
var _node$source, _node$source$value;
const source = (_node$source = node.source) === null || _node$source === void 0 ? void 0 : (_node$source$value = _node$source.value) === null || _node$source$value === void 0 ? void 0 : _node$source$value.toString();
if (source && (source === path || source.startsWith(path))) {
context.report({
node,
messageId: 'path',
data: {
importSource: source,
customMessage: message
}
});
}
});
}
}
return {
ImportDeclaration: checkNode,
ExportAllDeclaration: checkNode,
ExportNamedDeclaration: checkNode,
ExportDefaultDeclaration: checkNode
};
}
});
export default rule;