Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Created February 26, 2021 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelbr/1c40fba44227565c6b47ad6b2d239dc9 to your computer and use it in GitHub Desktop.
Save mikaelbr/1c40fba44227565c6b47ad6b2d239dc9 to your computer and use it in GitHub Desktop.
module.exports = {
meta: {
type: 'problem',
fixable: 'code',
schema: [
{
type: 'object',
additionalProperties: {
type: 'string',
},
},
],
},
create: function (context) {
const [mappings] = context.options;
return {
ImportDeclaration(node) {
const actualModule = node.source.value;
for (let specifierNode of node.specifiers) {
const identifier = specifierNode.local.name;
const preferredModule = mappings[identifier];
if (!preferredModule) continue;
if (preferredModule !== actualModule) {
context.report({
node: specifierNode,
message:
'{{ identifier }} should be importet from {{ preferredModule }} not {{ actualModule }}',
data: {
identifier,
preferredModule,
actualModule,
},
});
}
}
},
};
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment