Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

EVG-20048: Introduce check-file plugin #2109

Merged
merged 33 commits into from
Nov 30, 2023
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b1ba409
Introduce check-file plugin
SupaJoon Oct 18, 2023
a3e406c
verify tsx and use errorIfStrict
SupaJoon Oct 20, 2023
9889520
prodserver -> prod-server
SupaJoon Oct 30, 2023
647483b
cypress files
SupaJoon Oct 30, 2023
d54ce57
eventLogDiffs
SupaJoon Oct 30, 2023
87b0510
inactive style
SupaJoon Oct 30, 2023
f43cd07
more file name updates
SupaJoon Oct 30, 2023
4976741
toast test
SupaJoon Oct 30, 2023
bd90447
update naming conventions
SupaJoon Oct 30, 2023
f8ea637
404 -> NotFound
SupaJoon Oct 30, 2023
aa95bc4
remove tsx file (replaced by ts file)
SupaJoon Oct 30, 2023
0848548
event copy component
SupaJoon Oct 30, 2023
bc5a909
tsx -> ts
SupaJoon Oct 30, 2023
90c44fe
HostEventString comp
SupaJoon Oct 30, 2023
802787e
utils.tsx -> Utils.tsx
SupaJoon Oct 30, 2023
1f66210
ts -> tsx
SupaJoon Oct 30, 2023
c1a86a6
tsx -> ts
SupaJoon Oct 30, 2023
c8d17f9
update check-file edge cases
SupaJoon Oct 30, 2023
ad6d4c0
Merge branch 'main' of github.com:evergreen-ci/spruce into EVG-20048
SupaJoon Oct 30, 2023
59e8c90
Merge branch 'main' of github.com:evergreen-ci/spruce into EVG-20048
SupaJoon Nov 1, 2023
9034003
comments
SupaJoon Nov 1, 2023
de7196a
create useSubscriptionData hook file
SupaJoon Nov 1, 2023
827ea8e
merge main
SupaJoon Nov 15, 2023
750a352
update buildbaron file name
SupaJoon Nov 15, 2023
161996b
Divider.tsx -> divider.ts
SupaJoon Nov 15, 2023
916dcad
simplify rules
SupaJoon Nov 15, 2023
998cf28
try and fix error
SupaJoon Nov 15, 2023
1013516
merge main
SupaJoon Nov 27, 2023
8fc1528
Merge branch 'main' of github.com:evergreen-ci/spruce into EVG-20048
SupaJoon Nov 27, 2023
bbece55
change dir casing
SupaJoon Nov 27, 2023
33f1d7b
Revert "change dir casing"
SupaJoon Nov 27, 2023
45a7c6e
fix casing
SupaJoon Nov 27, 2023
5defa1c
eslint:fix
SupaJoon Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ module.exports = {
"plugin:jsdoc/recommended-typescript-error",
"plugin:prettier/recommended", // Note: prettier must ALWAYS be the last extension.
],
plugins: ["@typescript-eslint", "sort-destructure-keys"],
plugins: ["@typescript-eslint", "sort-destructure-keys", "check-file"],
settings: {
react: {
version: "detect",
@@ -96,6 +96,30 @@ module.exports = {
// Rules for prettier.
"prettier/prettier": errorIfStrict, // Makes Prettier issues warnings rather than errors.
"sort-destructure-keys/sort-destructure-keys": errorIfStrict,
"check-file/filename-naming-convention": [
errorIfStrict,
{
// GraphQL fragments, mutations and queries
"src/gql/fragments/**/*.graphql": "CAMEL_CASE",
"src/gql/(mutations,queries)/**/*.graphql": "KEBAB_CASE",
// Cypress
"cypress/integration/**/*.ts": "SNAKE_CASE",
// Scripts
"scripts/**/*.{js,ts}": "KEBAB_CASE",
// JS and TS with exceptions
"src/(!test_utils)/**/!(vite-env.d)*.{js,ts}": "CAMEL_CASE",
// All tsx with exceptions
"src/!(test_utils)/**/!(use|getFormSchema|index|test-utils|schemaFields|getColumnsTemplate|githubPRLinkify|jiraLinkify)*.tsx":
"PASCAL_CASE",
// Test utils
"src/test_utils/**/*": "KEBAB_CASE",
// tsx exceptions
"src/**/(use|getFormSchema|index)*.tsx": "CAMEL_CASE",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we further trim these down? So we don't have 4 different conventions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the smallest set that makes sense to me. Let me know what you want to trim and why.

{
ignoreMiddleExtensions: true,
},
],
},
overrides: [
// For React Typescript files in src.
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
"prepare": "husky install",
"prettier": "prettier --write",
"prod": "env-cmd -e devProduction -r .env-cmdrc.local.json yarn start",
"serve": "node scripts/prodServer.js",
"serve": "node scripts/prod-server.js",
"snapshot": "jest storybook.test.ts --watchAll=false",
"staging": "env-cmd -e devStaging -r .env-cmdrc.local.json yarn start",
"start": "vite",
@@ -173,6 +173,7 @@
"eslint": "8.19.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-check-file": "2.6.2",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.2.1",
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/Content/Layout.tsx
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import WelcomeModal from "components/WelcomeModal";
import { CY_DISABLE_NEW_USER_WELCOME_MODAL } from "constants/cookies";
import { size } from "constants/tokens";
import { newSpruceUser } from "constants/welcomeModalProps";
import { useAuthStateContext } from "context/auth";
import { useAuthStateContext } from "context/Auth";
import { UserQuery, UserQueryVariables } from "gql/generated/types";
import { USER } from "gql/queries";
import { useUserSettings } from "hooks";
2 changes: 1 addition & 1 deletion src/components/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import {
WaterfallCommitsRedirect,
} from "components/Redirects";
import { redirectRoutes, routes } from "constants/routes";
import { PageDoesNotExist } from "pages/404";
import { CommitQueue } from "pages/CommitQueue";
import { Commits } from "pages/Commits";
import { ConfigurePatch } from "pages/ConfigurePatch";
@@ -15,6 +14,7 @@ import { Host } from "pages/Host";
import { Hosts } from "pages/Hosts";
import { JobLogs } from "pages/JobLogs";
import { MyPatches } from "pages/MyPatches";
import { PageDoesNotExist } from "pages/NotFound";
import { Preferences } from "pages/Preferences";
import { ProjectPatches } from "pages/ProjectPatches";
import { ProjectSettings } from "pages/ProjectSettings";
2 changes: 1 addition & 1 deletion src/components/Header/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import { CURRENT_PROJECT } from "constants/cookies";
import { wikiUrl } from "constants/externalResources";
import { getCommitsRoute, getUserPatchesRoute, routes } from "constants/routes";
import { size } from "constants/tokens";
import { useAuthStateContext } from "context/auth";
import { useAuthStateContext } from "context/Auth";
import { UserQuery, SpruceConfigQuery } from "gql/generated/types";
import { USER, SPRUCE_CONFIG } from "gql/queries";
import { useLegacyUIURL } from "hooks";
2 changes: 1 addition & 1 deletion src/components/Header/UserDropdown.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { useQuery } from "@apollo/client";
import { useNavbarAnalytics } from "analytics";
import { adminSettingsURL } from "constants/externalResources";
import { PreferencesTabRoutes, getPreferencesRoute } from "constants/routes";
import { useAuthDispatchContext } from "context/auth";
import { useAuthDispatchContext } from "context/Auth";
import { UserQuery } from "gql/generated/types";
import { USER } from "gql/queries";
import { MenuItemType, NavDropdown } from "./NavDropdown";
2 changes: 1 addition & 1 deletion src/components/MetadataCard.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { Body, BodyProps } from "@leafygreen-ui/typography";
import { Skeleton } from "antd";
import { ErrorWrapper } from "components/ErrorWrapper";
import { SiderCard, wordBreakCss } from "components/styles";
import { Divider } from "components/styles/Divider";
import { Divider } from "components/styles/divider";

interface Props {
error: ApolloError;
2 changes: 1 addition & 1 deletion src/components/Settings/EventLog/EventDiffTable.tsx
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
V10HeaderRow as HeaderRow,
} from "@leafygreen-ui/table";
import { fontFamilies } from "@leafygreen-ui/tokens";
import { getEventDiffLines } from "./EventLogDiffs";
import { getEventDiffLines } from "./eventLogDiffs";
import { Event, EventDiffLine, EventValue } from "./types";

type TableProps = {
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProjectEventSettings } from "gql/generated/types";
import { Subset } from "types/utils";
import { getEventDiffLines } from "./EventLogDiffs";
import { getEventDiffLines } from "./eventLogDiffs";

const beforeAddition: Subset<ProjectEventSettings> = {
__typename: "ProjectEventSettings",
2 changes: 1 addition & 1 deletion src/components/VersionRestartModal/VersionTasks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Divider } from "components/styles/Divider";
import { Divider } from "components/styles/divider";
import { TaskStatusFilters } from "components/TaskStatusFilters";
import { BuildVariantsWithChildrenQuery } from "gql/generated/types";
import { versionSelectedTasks } from "hooks/useVersionTaskStatusSelect";
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/components/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Divider } from "./Divider";
import { Divider } from "./divider";
import { FiltersWrapper } from "./filters";
import { inactiveElementStyle } from "./Inactive";
import { inactiveElementStyle } from "./inactive";
import {
ErrorMessage,
InputLabel,
2 changes: 1 addition & 1 deletion src/context/auth.test.tsx → src/context/Auth.test.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {
AuthProvider,
useAuthDispatchContext,
useAuthStateContext,
} from "./auth";
} from "./Auth";

const { cleanup, mockEnv } = mockEnvironmentVariables();

File renamed without changes.
2 changes: 1 addition & 1 deletion src/context/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LeafyGreenProvider from "@leafygreen-ui/leafygreen-provider";
import { AuthProvider } from "context/auth";
import { AuthProvider } from "context/Auth";
import { ToastProvider } from "context/toast";

export const ContextProviders: React.FC<{ children: React.ReactNode }> = ({
File renamed without changes.
2 changes: 1 addition & 1 deletion src/gql/GQLWrapper.tsx
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import {
import { onError } from "@apollo/client/link/error";
import { RetryLink } from "@apollo/client/link/retry";
import { routes } from "constants/routes";
import { useAuthDispatchContext } from "context/auth";
import { useAuthDispatchContext } from "context/Auth";
import { environmentVariables } from "utils";
import {
leaveBreadcrumb,
2 changes: 1 addition & 1 deletion src/pages/404/__snapshots__/NotFound.stories.storyshot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`storybook Storyshots pages/404/NotFound Default 404 1`] = `
exports[`storybook Storyshots pages/NotFound/NotFound Default 404 1`] = `
<div>
<div
style="height: 100%; width: 100%;"
2 changes: 1 addition & 1 deletion src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { useState } from "react";
import { useQuery } from "@apollo/client";
import styled from "@emotion/styled";
import { Navigate, useLocation } from "react-router-dom";
import { useAuthDispatchContext, useAuthStateContext } from "context/auth";
import { useAuthDispatchContext, useAuthStateContext } from "context/Auth";
import { UserQuery, UserQueryVariables } from "gql/generated/types";
import { USER } from "gql/queries";

File renamed without changes.
2 changes: 1 addition & 1 deletion src/pages/Task.tsx
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import { TaskQuery, TaskQueryVariables } from "gql/generated/types";
import { TASK } from "gql/queries";
import { usePolling } from "hooks";
import { useUpdateURLQueryParams } from "hooks/useUpdateURLQueryParams";
import { PageDoesNotExist } from "pages/404";
import { PageDoesNotExist } from "pages/NotFound";
import { RequiredQueryParams, TaskStatus } from "types/task";
import { queryString } from "utils";
import { ActionButtons } from "./task/ActionButtons";
2 changes: 1 addition & 1 deletion src/pages/Version.tsx
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import {
} from "gql/generated/types";
import { VERSION, IS_PATCH_CONFIGURED, HAS_VERSION } from "gql/queries";
import { useSpruceConfig } from "hooks";
import { PageDoesNotExist } from "pages/404";
import { PageDoesNotExist } from "pages/NotFound";
import { isPatchUnconfigured } from "utils/patch";
import { shortenGithash, githubPRLinkify } from "utils/string";
import { jiraLinkify } from "utils/string/jiraLinkify";
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import Badge, { Variant } from "@leafygreen-ui/badge";
import { palette } from "@leafygreen-ui/palette";
import { Body, Description } from "@leafygreen-ui/typography";
import { SiderCard } from "components/styles";
import { Divider } from "components/styles/Divider";
import { Divider } from "components/styles/divider";
import { size } from "constants/tokens";
import type { MenuItemProps } from "./types";

2 changes: 1 addition & 1 deletion src/pages/configurePatch/index.tsx
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
} from "gql/generated/types";
import { PATCH_CONFIGURE } from "gql/queries";
import { usePageTitle } from "hooks";
import { PageDoesNotExist } from "pages/404";
import { PageDoesNotExist } from "pages/NotFound";
import { validateObjectId } from "utils/validators";
import ConfigurePatchCore from "./configurePatchCore";

Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@ import { PodEvent } from "types/pod";
import { Unpacked } from "types/utils";
import { reportError } from "utils/errorReporting";

export const getEventCopy = (
event: Unpacked<PodEventsQuery["pod"]["events"]["eventLogEntries"]>
) => {
interface EventCopyProps {
event: Unpacked<PodEventsQuery["pod"]["events"]["eventLogEntries"]>;
}
export const EventCopy: React.FC<EventCopyProps> = ({ event }) => {
const { data, eventType } = event;
const taskLink = (
<ShortenedRouterLink
6 changes: 4 additions & 2 deletions src/pages/container/EventsTable/index.tsx
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import { PodEventsQuery, PodEventsQueryVariables } from "gql/generated/types";
import { POD_EVENTS } from "gql/queries";
import { useDateFormat } from "hooks";
import { url } from "utils";
import { getEventCopy } from "./util";
import { EventCopy } from "./EventCopy";

const { getLimitFromSearch, getPageFromSearch } = url;

@@ -85,7 +85,9 @@ const EventsTable: React.FC<{}> = () => {
<Cell data-cy={`${datum.eventType}-time`}>
{getDateCopy(datum.timestamp)}
</Cell>
<Cell>{getEventCopy(datum)}</Cell>
<Cell>
<EventCopy event={datum} />
</Cell>
</Row>
)}
</Table>
Original file line number Diff line number Diff line change
@@ -40,10 +40,15 @@ const TaskLink: React.FC<TaskLinkProps> = ({ "data-cy": dataCy, taskId }) => (
{taskId}
</ShortenedRouterLink>
);
export const getHostEventString = (
eventType: string,
data: HostEventLogData
) => {

interface HostEventStringProps {
eventType: string;
data: HostEventLogData;
}
export const HostEventString: React.FC<HostEventStringProps> = ({
data,
eventType,
}) => {
const succeededString = "succeeded";
const failedString = "failed";

@@ -281,9 +286,8 @@ export const getHostEventString = (
)}
</span>
);

default:
return `${eventType}`;
return <span>{eventType}</span>;
}
};

9 changes: 7 additions & 2 deletions src/pages/host/HostTable.tsx
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ import Pagination from "components/Pagination";
import { size } from "constants/tokens";
import { HostEventsQuery } from "gql/generated/types";
import { useDateFormat } from "hooks";
import { getHostEventString } from "pages/host/getHostEventString";
import { HostCard } from "pages/host/HostCard";
import { HostEventString } from "pages/host/HostEventString";

export const HostTable: React.FC<{
loading: boolean;
@@ -77,7 +77,12 @@ export const HostTable: React.FC<{
<Cell data-cy={`${datum.eventType}-time`}>
{getDateCopy(datum.timestamp)}
</Cell>
<Cell>{getHostEventString(datum.eventType, datum.data)}</Cell>
<Cell>
<HostEventString
eventType={datum.eventType}
data={datum.data}
/>
</Cell>
</Row>
)}
</Table>
Original file line number Diff line number Diff line change
@@ -37,7 +37,8 @@ import {
} from "types/subscription";
import { jiraLinkify } from "utils/string/jiraLinkify";
import { ClearSubscriptions } from "./ClearSubscriptions";
import { getResourceRoute, useSubscriptionData } from "./utils";
import { useSubscriptionData } from "./useSubscriptionData";
import { getResourceRoute } from "./utils";

const { gray } = palette;

Original file line number Diff line number Diff line change
@@ -2,22 +2,15 @@ import { useMemo } from "react";
import { useQuery } from "@apollo/client";
import styled from "@emotion/styled";
import { LeafyGreenTableRow } from "@leafygreen-ui/table";
import {
getCommitsRoute,
getPatchRoute,
getTaskRoute,
getVersionRoute,
} from "constants/routes";
import { size } from "constants/tokens";
import { convertFamilyTrigger } from "constants/triggers";
import {
GeneralSubscription,
Selector,
UserSubscriptionsQuery,
UserSubscriptionsQueryVariables,
GeneralSubscription,
Selector,
} from "gql/generated/types";
import { USER_SUBSCRIPTIONS } from "gql/queries";
import { ResourceType } from "types/triggers";

export const useSubscriptionData = () => {
const { data } = useQuery<
@@ -108,34 +101,7 @@ const ExpandedBlock = styled.pre`
padding: ${size.s} ${size.l};
`;

export const getResourceRoute = (
Copy link
Contributor Author

@SupaJoon SupaJoon Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this function so this file exports the hook only.

resourceType: ResourceType,
selector: Selector
) => {
const { data: id, type } = selector;

if (!id) {
return "";
}

switch (resourceType) {
case ResourceType.Build:
case ResourceType.Version: {
if (type === "project") {
return getCommitsRoute(id);
}
return getVersionRoute(id);
}
case ResourceType.Patch:
return getPatchRoute(id, { configure: false });
case ResourceType.Task:
return getTaskRoute(id);
default:
return "";
}
};

export const formatRegexSelectors = (regexSelectors: Selector[]) => ({
const formatRegexSelectors = (regexSelectors: Selector[]) => ({
"regex-selectors": regexSelectors.reduce<Record<string, string>>(
(obj, { data, type }) => ({
...obj,
Loading