Skip to content

Commit

Permalink
1.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Kowalski committed Aug 31, 2023
1 parent d9493a4 commit e60701c
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

echo '🕵️‍♂️ Checking your crappy code 🕵️‍♂️'

echo '🕵️‍♂️🕵️‍♂️🕵️‍♂️ dead-code:check 🕵️‍♂️🕵️‍♂️🕵️‍♂️'
yarn dead-code:check || (echo '🤢🤮🤢 dead-code:check failed 🤢🤮🤢'; false)
echo '✅✅✅ dead-code:check ✅✅✅'
echo '🕵️‍♂️🕵️‍♂️🕵️‍♂️ deadCode:check 🕵️‍♂️🕵️‍♂️🕵️‍♂️'
yarn deadCode:check || (echo '🤢🤮🤢 deadCode:check failed 🤢🤮🤢'; false)
echo '✅✅✅ deadCode:check ✅✅✅'

echo '🕵️‍♂️🕵️‍♂️🕵️‍♂️ lint:check 🕵️‍♂️🕵️‍♂️🕵️‍♂️'
yarn lint:check || (echo '🤢🤮🤢 lint:check failed 🤢🤮🤢'; false);
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JestConfigWithTsJest } from "ts-jest";

const jestConfig: JestConfigWithTsJest = {
maxWorkers: "90%",
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": [
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Igor Kowalski (Igorkowalski94)",
"name": "eslint-plugin-project-structure",
"version": "1.4.6",
"version": "1.4.7",
"license": "MIT",
"description": "Eslint plugin that allows you to enforce rules on project structure. Folder and file naming, folder structure, file extensions all under your control to keep your repo consistent even in large teams.",
"keywords": [
Expand Down Expand Up @@ -34,17 +34,16 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"scripts": {
"clean": "del -rf dist",
"build": "tsc -p tsconfig.build.json && node esbuild.config.js",
"dead-code:check": "ts-prune --error",
"types:check": "tsc",
"format": "prettier --write --config .prettierrc.json .",
"format:check": "prettier --check --config .prettierrc.json .",
"lint": "eslint src --max-warnings 0",
"deadCode:check": "ts-prune --error",
"types:check": "tsc",
"lint:check": "eslint src --max-warnings 0",
"clean": "del -rf dist",
"test": "jest --coverage --watch",
"test:check": "jest --coverage --watchAll=false --bail",
"test:current": "jest --coverage --changedSince=origin/main",
"test": "jest --coverage --watch",
"checkAll": "yarn deadCode:check && yarn format:check && yarn lint:check && yarn test:check",
"husky:prepare": "husky install"
},
"dependencies": {
Expand Down
2 changes: 0 additions & 2 deletions src/helpers/getIsFileFromNodeName.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/helpers/getIsFileFromPathName.test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/helpers/getIsFileFromPathName.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/helpers/getNodeType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getIsFileFromNodeName } from "./getIsFileFromNodeName";
import { isFileFromNodeName } from "./isFileFromNodeName";
import { NodeType } from "../types";

export const getNodeType = (nodeName: string): NodeType =>
getIsFileFromNodeName(nodeName) ? "File" : "Folder";
isFileFromNodeName(nodeName) ? "File" : "Folder";
2 changes: 2 additions & 0 deletions src/helpers/isFileFromNodeName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isFileFromNodeName = (nodeName: string): boolean =>
nodeName.includes(".");
15 changes: 15 additions & 0 deletions src/helpers/isFileFromPathname.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isFileFromPathname } from "./isFileFromPathname";

describe("isFileFromPathname", () => {
it("should return false when pathname includes /", () => {
expect(isFileFromPathname("src/componentName")).toEqual(false);
});

it("should return false when pathname includes \\", () => {
expect(isFileFromPathname("src\\componentName")).toEqual(false);
});

it("should return true when pathname not includes / or \\", () => {
expect(isFileFromPathname("componentName")).toEqual(true);
});
});
2 changes: 2 additions & 0 deletions src/helpers/isFileFromPathname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isFileFromPathname = (pathname: string): boolean =>
!(pathname.includes("/") || pathname.includes("\\"));
4 changes: 2 additions & 2 deletions src/validators/validateChildren/helpers/filterRulesByType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getIsFileFromPathname } from "../../../helpers/getIsFileFromPathName";
import { getNodeRule } from "../../../helpers/getNodeRule/getNodeRule";
import { isFileFromPathname } from "../../../helpers/isFileFromPathname";
import { ProjectStructureConfig, Rule } from "../../../types";

export interface FilterRulesByType {
Expand All @@ -15,7 +15,7 @@ export const filterRulesByType = ({
}: FilterRulesByType): boolean => {
const nodeRule = getNodeRule(rule, config);

const isFile = getIsFileFromPathname(pathname);
const isFile = isFileFromPathname(pathname);
const isFolderNode = !!nodeRule.children;
const isFileNode = !!nodeRule.extension;

Expand Down
4 changes: 4 additions & 0 deletions src/validators/validateName/helpers/getInvalidRegexError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FinalError } from "../../../errors/FinalError/FinalError";

export const getInvalidRegexError = (regex: string): FinalError =>
new FinalError(`\n\n🔥 Regex: ${regex} is invalid. 🔥\n\n`);
1 change: 0 additions & 1 deletion src/validators/validateName/helpers/getIsRegex.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/validators/validateName/helpers/isRegex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isRegex = (regex: string): boolean => /^\/(.+)\/$/.test(regex);
9 changes: 9 additions & 0 deletions src/validators/validateName/helpers/isRegexInvalid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const isRegexInvalid = (regex: string): boolean => {
try {
new RegExp(regex);
} catch (e) {
return true;
}

return false;
};
11 changes: 11 additions & 0 deletions src/validators/validateName/validateName.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getInvalidNameError } from "./helpers/getInvalidNameError";
import { getInvalidRegexError } from "./helpers/getInvalidRegexError";
import { getNameError } from "./helpers/getNameError";
import { getNameRegexError } from "./helpers/validateRegexPattern/helpers/getNameRegexError";
import { validateName } from "./validateName";
Expand All @@ -17,6 +18,16 @@ describe("validateName", () => {
},
);

it("should throw error when regex is invalid", () => {
expect(() =>
validateName({
nodeName: "componentName.api",
ruleName: "/^?/",
parentName: "parentName",
}),
).toThrow(getInvalidRegexError("/^?/"));
});

it("should not throw error when nodeName match regex", () => {
expect(() =>
validateName({
Expand Down
7 changes: 5 additions & 2 deletions src/validators/validateName/validateName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getInvalidNameError } from "./helpers/getInvalidNameError";
import { getIsRegex } from "./helpers/getIsRegex";
import { getInvalidRegexError } from "./helpers/getInvalidRegexError";
import { getNameError } from "./helpers/getNameError";
import { isRegex } from "./helpers/isRegex";
import { isRegexInvalid } from "./helpers/isRegexInvalid";
import { validateRegexPattern } from "./helpers/validateRegexPattern/validateRegexPattern";
import { RegexParameters } from "../../types";

Expand All @@ -18,8 +20,9 @@ export const validateName = ({
regexParameters,
}: ValidateName): void => {
if (typeof ruleName !== "string") throw getInvalidNameError(ruleName);
if (isRegexInvalid(ruleName)) throw getInvalidRegexError(ruleName);

if (getIsRegex(ruleName))
if (isRegex(ruleName))
return validateRegexPattern({
nodeName,
parentName,
Expand Down
4 changes: 2 additions & 2 deletions src/validators/validatePath/helpers/getNodeName.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { sep } from "path";

import { getFileNameWithoutExtension } from "./getFileNameWithoutExtension";
import { getIsFileFromPathname } from "../../../helpers/getIsFileFromPathName";
import { isFileFromPathname } from "../../../helpers/isFileFromPathname";

interface GetNodeNameReturn {
nodeName: string;
fileNameWithExtension: string | undefined;
}

export const getNodeName = (pathname: string): GetNodeNameReturn => {
const isFile = getIsFileFromPathname(pathname);
const isFile = isFileFromPathname(pathname);

const currentNodeName = pathname.split(sep)[0];

Expand Down

0 comments on commit e60701c

Please sign in to comment.