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",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
|
regexString: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
invalidPrefix: {
|
invalidPrefix: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
@ -57,9 +60,11 @@ module.exports = {
|
|||||||
// create a replacer regex and a target string
|
// create a replacer regex and a target string
|
||||||
const replacers = context.options[0].options.map((option) => [
|
const replacers = context.options[0].options.map((option) => [
|
||||||
// match all string [../]*$invalidPrefix/anything/$invalidSuffix[/anything]
|
// match all string [../]*$invalidPrefix/anything/$invalidSuffix[/anything]
|
||||||
new RegExp(
|
option.regexString ?
|
||||||
`(?:(?:..\\/)*${option.invalidPrefix})+\\/([^\\/]+)\\/${option.invalidSuffix}(\\/(.+))?`
|
new RegExp(option.regexString) :
|
||||||
),
|
new RegExp(
|
||||||
|
`(?:(?:..\\/)*${option.invalidPrefix})+\\/([^\\/]+)${option.invalidSuffix !== "" ? `\\/${option.invalidSuffix}` : ''}(\\/(.+))?`
|
||||||
|
),
|
||||||
option.template ?? `${option.monorepoRoot}/$1$2`,
|
option.template ?? `${option.monorepoRoot}/$1$2`,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ ruleTester.run("no-package-imports", rule, {
|
|||||||
|
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
code: 'import { Button } from "../../packages/components/src/Button"',
|
code: 'import { Button } from "../../../packages/components/src/Button"',
|
||||||
output: 'import { Button } from "@monorepo/components/Button"',
|
output: 'import { Button } from "@monorepo/components/Button"',
|
||||||
parserOptions: { ecmaVersion: 6, sourceType: "module" },
|
parserOptions: { ecmaVersion: 6, sourceType: "module" },
|
||||||
options,
|
options,
|
||||||
@ -71,6 +71,21 @@ ruleTester.run("no-package-imports", rule, {
|
|||||||
],
|
],
|
||||||
errors: [incorrectImport],
|
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"',
|
code: 'import Button from "../../../packages/components/src/Button"',
|
||||||
output: 'import Button from "@monorepo/components/Button"',
|
output: 'import Button from "@monorepo/components/Button"',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user