restrict imports from @scm-manager source directories

This commit is contained in:
Sebastian Sdorra
2020-06-16 07:23:23 +02:00
parent 58b2e4b30a
commit 685acbc6fc
4 changed files with 45 additions and 15 deletions

View File

@@ -0,0 +1,6 @@
import React, { FC } from "react";
import { Button } from "@scm-manager/ui-components";
const SpecialButton: FC = () => <Button color="primary">Special</Button>;
export default SpecialButton;

View File

@@ -0,0 +1,6 @@
import React, { FC } from "react";
import Button from "@scm-manager/ui-components/src/buttons/Button";
const SpecialButton: FC = () => <Button color="primary">Special</Button>;
export default SpecialButton;

View File

@@ -37,6 +37,10 @@ const nodeConfiguration = {
}
};
const restrictImportConfig = {
patterns: ["@scm-manager/*/*"]
};
const typescriptConfiguration = {
parser: "@typescript-eslint/parser",
extends: ["react-app", "plugin:@typescript-eslint/recommended"],
@@ -45,6 +49,7 @@ const typescriptConfiguration = {
"@typescript-eslint/ban-ts-ignore": "warn",
"no-console": "error",
"jsx-a11y/href-no-hash": "off",
"no-restricted-imports": ["error", restrictImportConfig],
...rules
}
};

View File

@@ -25,7 +25,6 @@
const { ESLint } = require("eslint");
const path = require("path");
describe("should lint files", () => {
const eslint = new ESLint();
const resource = path.join(__dirname, "__resources__");
@@ -46,6 +45,7 @@ describe("should lint files", () => {
ids.forEach(id => expect(results).toContain(id));
};
describe("should lint different file types", () => {
it("should lint tsx files", async () => {
const { errors, warnings } = await lint("TypescriptWithJsx.tsx");
expectContains(errors, "no-console", "quotes", "semi");
@@ -64,3 +64,16 @@ describe("should lint files", () => {
expectContains(warnings, "prettier/prettier");
});
});
describe("lint @scm-manager imports", () => {
it("should return an error for source imports", async () => {
const { errors } = await lint("AvoidSourceImport.tsx");
expectContains(errors, "no-restricted-imports");
});
it("should return no error for package imports", async () => {
const { errors, warnings } = await lint("AllowRootImport.tsx");
expect(errors).toEqual([]);
expect(warnings).toEqual([]);
});
});