Created
February 26, 2021 07:53
-
-
Save mikaelbr/1c40fba44227565c6b47ad6b2d239dc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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