Skip to content

Commit

Permalink
Applied new perfectionist rules
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Nov 25, 2024
1 parent 7cc3d64 commit 8faa801
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion packages/collector/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import js from "@eslint/js";
import eslintComments from "@eslint-community/eslint-plugin-eslint-comments";
import commentsConfig from "@eslint-community/eslint-plugin-eslint-comments/configs";
import js from "@eslint/js";
import jest from "eslint-plugin-jest";
import perfectionist from "eslint-plugin-perfectionist";
import preferArrowFunctions from "eslint-plugin-prefer-arrow-functions";
Expand Down
174 changes: 87 additions & 87 deletions packages/collector/src/interfaces/ProjectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import type { PoptavkyError } from "../exceptions/PoptavkyError";

import { ProjectInfoError } from "../exceptions/ProjectInfoError";

interface ProjectInfoMaintainer {
email?: string;
export interface ProjectInfo {
description: string;
"help-issue-label"?: string;
links: Array<ProjectInfoLink>;
maintainers: Array<ProjectInfoMaintainer>;
name: string;
"short-description": string;
tags?: Array<string>;
}

interface ProjectInfoLinkSlack {
channel: string;
space: string;
type: "slack";
uri: string;
}
type ProjectInfoLink =
| ProjectInfoLinkNamed
| ProjectInfoLinkOther
| ProjectInfoLinkSlack;

interface ProjectInfoLinkNamed {
name: string;
Expand All @@ -25,87 +28,16 @@ interface ProjectInfoLinkOther {
uri: string;
}

type ProjectInfoLink =
| ProjectInfoLinkNamed
| ProjectInfoLinkOther
| ProjectInfoLinkSlack;

export interface ProjectInfo {
description: string;
"help-issue-label"?: string;
links: Array<ProjectInfoLink>;
maintainers: Array<ProjectInfoMaintainer>;
name: string;
"short-description": string;
tags?: Array<string>;
}

function assertIsProjectInfoMaintainer(
maintainer: unknown,
errorFn: (e: string) => PoptavkyError,
): asserts maintainer is ProjectInfoMaintainer {
if (typeof maintainer !== "object" || maintainer === null) {
throw errorFn("The maintainer isn't a valid object.");
}
if (!("name" in maintainer)) {
throw errorFn('The maintainer doesn\'t contain the required field "name".');
}
if (typeof maintainer.name !== "string") {
throw errorFn('The field "name" is not a string.');
}
if ("email" in maintainer && typeof maintainer.email !== "string") {
throw errorFn('The field "email" is not a string.');
}
interface ProjectInfoLinkSlack {
channel: string;
space: string;
type: "slack";
uri: string;
}

function assertIsProjectInfoLink(
link: unknown,
errorFn: (e: string) => PoptavkyError,
): asserts link is ProjectInfoLink {
if (typeof link !== "object" || link === null) {
throw errorFn("The link isn't a valid object.");
}
if (!("type" in link)) {
throw errorFn('The link doesn\'t contain the required field "type".');
}
if (!("uri" in link)) {
throw errorFn('The link doesn\'t contain the required field "uri".');
}
if (typeof link.type !== "string") {
throw errorFn('The field "type" is not a string.');
}
if (typeof link.uri !== "string") {
throw errorFn('The field "uri" is not a string.');
}
if (link.type === "slack") {
if (!("space" in link)) {
throw errorFn('The link doesn\'t contain the field "space".');
}
if (!("channel" in link)) {
throw errorFn('The link doesn\'t contain the field "channel".');
}
if (typeof link.space !== "string") {
throw errorFn('The field "space" is not a string.');
}
if (typeof link.channel !== "string") {
throw errorFn('The field "channel" is not a string.');
}
} else if (
["facebook-group", "facebook-page", "github-repo"].includes(link.type)
) {
if (!("name" in link)) {
throw errorFn('The link doesn\'t contain the field "name".');
}
if (typeof link.name !== "string") {
throw errorFn('The field "name" is not a string.');
}
} else if (
!["demo", "docs", "email", "homepage", "issue-tracker", "wiki"].includes(
link.type,
)
) {
throw errorFn("The link type is unsupported.");
}
interface ProjectInfoMaintainer {
email?: string;
name: string;
}

export function assertIsProjectInfo(
Expand Down Expand Up @@ -186,3 +118,71 @@ export function assertIsProjectInfo(
}
}
}

function assertIsProjectInfoLink(
link: unknown,
errorFn: (e: string) => PoptavkyError,
): asserts link is ProjectInfoLink {
if (typeof link !== "object" || link === null) {
throw errorFn("The link isn't a valid object.");
}
if (!("type" in link)) {
throw errorFn('The link doesn\'t contain the required field "type".');
}
if (!("uri" in link)) {
throw errorFn('The link doesn\'t contain the required field "uri".');
}
if (typeof link.type !== "string") {
throw errorFn('The field "type" is not a string.');
}
if (typeof link.uri !== "string") {
throw errorFn('The field "uri" is not a string.');
}
if (link.type === "slack") {
if (!("space" in link)) {
throw errorFn('The link doesn\'t contain the field "space".');
}
if (!("channel" in link)) {
throw errorFn('The link doesn\'t contain the field "channel".');
}
if (typeof link.space !== "string") {
throw errorFn('The field "space" is not a string.');
}
if (typeof link.channel !== "string") {
throw errorFn('The field "channel" is not a string.');
}
} else if (
["facebook-group", "facebook-page", "github-repo"].includes(link.type)
) {
if (!("name" in link)) {
throw errorFn('The link doesn\'t contain the field "name".');
}
if (typeof link.name !== "string") {
throw errorFn('The field "name" is not a string.');
}
} else if (
!["demo", "docs", "email", "homepage", "issue-tracker", "wiki"].includes(
link.type,
)
) {
throw errorFn("The link type is unsupported.");
}
}

function assertIsProjectInfoMaintainer(
maintainer: unknown,
errorFn: (e: string) => PoptavkyError,
): asserts maintainer is ProjectInfoMaintainer {
if (typeof maintainer !== "object" || maintainer === null) {
throw errorFn("The maintainer isn't a valid object.");
}
if (!("name" in maintainer)) {
throw errorFn('The maintainer doesn\'t contain the required field "name".');
}
if (typeof maintainer.name !== "string") {
throw errorFn('The field "name" is not a string.');
}
if ("email" in maintainer && typeof maintainer.email !== "string") {
throw errorFn('The field "email" is not a string.');
}
}
4 changes: 2 additions & 2 deletions packages/collector/src/interfaces/ProjectListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Project } from "./Project";
import type { ProjectInfo } from "./ProjectInfo";
import type { ProjectIssue } from "./ProjectIssue";

export type ProjectListing = {
export type ProjectListing = Project & {
info: ProjectInfo;
issues: Array<ProjectIssue>;
} & Project;
};

0 comments on commit 8faa801

Please sign in to comment.