@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
43 lines • 1.61 kB
JavaScript
import { createLintRule } from '../utils/create-lint-rule';
import { createModuleImportListener } from '../utils/create-module-import-listener';
import { isModuleFromPackage } from '../utils/is-module-from-package';
import { layeringLibraries } from './libraries';
var rule = createLintRule({
meta: {
name: 'no-third-party-layering',
type: 'problem',
docs: {
description: 'Disallow third-party layering libraries, such as Popper.js and Floating UI. Use a Design System layering component or `@atlaskit/top-layer`.',
recommended: false,
severity: 'error'
},
messages: {
noThirdPartyLayering: 'Do not use `{{specifier}}`. Layers built with it are not in the Design System layer stack: top layer surfaces paint above them, and one press of Escape can close more than one layer. Use a Design System layering component, or `@atlaskit/top-layer` if no component fits.'
}
},
create: function create(context) {
return createModuleImportListener({
onModuleImport: function onModuleImport(_ref) {
var node = _ref.node,
specifier = _ref.specifier;
var isLayeringLibrary = layeringLibraries.some(function (packageName) {
return isModuleFromPackage({
specifier: specifier,
packageName: packageName
});
});
if (!isLayeringLibrary) {
return;
}
context.report({
node: node,
messageId: 'noThirdPartyLayering',
data: {
specifier: specifier
}
});
}
});
}
});
export default rule;