Created
October 4, 2023 20:23
-
-
Save B0und/b4bcdc6180a474a225d50678e12daeaf 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", | |
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'"); | |
} | |
}); | |
} | |
} | |
}; | |
} | |
}; |
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
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