Skip to content

Instantly share code, notes, and snippets.

@B0und
Created October 4, 2023 20:23
Show Gist options
  • Save B0und/b4bcdc6180a474a225d50678e12daeaf to your computer and use it in GitHub Desktop.
Save B0und/b4bcdc6180a474a225d50678e12daeaf to your computer and use it in GitHub Desktop.
module.exports = {
meta: {
type: "problem",
docs: {
description: "replace certain import paths with aliased paths",
category: "Stylistic Issues",
recommended: false,
},
fixable: "code",
schema: []
},
create(context) {
return {
ImportDeclaration(node) {
const sourceValue = node.source.value;
if (sourceValue === "@tver-palm/whyelse-ui") {
context.report({
node: node.source,
message: "Use the aliased path '@ui' for importing from '@tver-palm/whyelse-ui'",
fix(fixer) {
return fixer.replaceText(node.source, "'@ui'");
}
});
}
}
};
}
};
const rule = require("../../../lib/rules/import-alias");
const { RuleTester } = require('eslint');
const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2020, sourceType: "module" }
});
ruleTester.run('import-alias', rule, {
valid: [
{ code: 'import Button from "@ui";' }
],
invalid: [
{
code: 'import Button from "@tver-palm/whyelse-ui";',
output: 'import Button from "@ui";',
errors: [
{ message: "Use the aliased path '@ui' for importing from '@tver-palm/whyelse-ui'" }
]
}
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment