mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 18:51:10 +01:00
restrict imports from @scm-manager source directories
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user