mirror of
https://github.com/foomo/eslint-plugin.git
synced 2025-10-16 12:25:34 +00:00
chore(feat): make suffix optional
This commit is contained in:
parent
8cda565b7d
commit
7487be08e5
@ -27,6 +27,9 @@ module.exports = {
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
regexString: {
|
||||
type: "string",
|
||||
},
|
||||
invalidPrefix: {
|
||||
type: "string",
|
||||
},
|
||||
@ -57,9 +60,11 @@ module.exports = {
|
||||
// create a replacer regex and a target string
|
||||
const replacers = context.options[0].options.map((option) => [
|
||||
// match all string [../]*$invalidPrefix/anything/$invalidSuffix[/anything]
|
||||
new RegExp(
|
||||
`(?:(?:..\\/)*${option.invalidPrefix})+\\/([^\\/]+)\\/${option.invalidSuffix}(\\/(.+))?`
|
||||
),
|
||||
option.regexString ?
|
||||
new RegExp(option.regexString) :
|
||||
new RegExp(
|
||||
`(?:(?:..\\/)*${option.invalidPrefix})+\\/([^\\/]+)${option.invalidSuffix !== "" ? `\\/${option.invalidSuffix}` : ''}(\\/(.+))?`
|
||||
),
|
||||
option.template ?? `${option.monorepoRoot}/$1$2`,
|
||||
]);
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ ruleTester.run("no-package-imports", rule, {
|
||||
|
||||
invalid: [
|
||||
{
|
||||
code: 'import { Button } from "../../packages/components/src/Button"',
|
||||
code: 'import { Button } from "../../../packages/components/src/Button"',
|
||||
output: 'import { Button } from "@monorepo/components/Button"',
|
||||
parserOptions: { ecmaVersion: 6, sourceType: "module" },
|
||||
options,
|
||||
@ -71,6 +71,21 @@ ruleTester.run("no-package-imports", rule, {
|
||||
],
|
||||
errors: [incorrectImport],
|
||||
},
|
||||
{
|
||||
code: 'import Button from "../../../packages/components/Button"',
|
||||
output: 'import Button from "@monorepo/components/Button"',
|
||||
parserOptions: { ecmaVersion: 6, sourceType: "module" },
|
||||
options: [{
|
||||
options: [
|
||||
{
|
||||
invalidPrefix: "packages",
|
||||
invalidSuffix: "",
|
||||
monorepoRoot: "@monorepo",
|
||||
},
|
||||
],
|
||||
}],
|
||||
errors: [incorrectImport],
|
||||
},
|
||||
{
|
||||
code: 'import Button from "../../../packages/components/src/Button"',
|
||||
output: 'import Button from "@monorepo/components/Button"',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user