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
Show file tree
Hide file tree
Changes from 22 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
24 changes: 23 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -96,6 +96,28 @@ 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/**/!(vite-env.d|custom-queries)*.{js,ts}": "CAMEL_CASE",
// All tsx with exceptions
"src/**/!(use|getFormSchema|index|test-utils|toast-decorator|schemaFields|getColumnsTemplate|githubPRLinkify|jiraLinkify)*.tsx":
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we hardcode all of these exceptions or can we update these to match the pattern we have established?
e.g. jiraLinkify -> JiraLinkify.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reviewed these and think these makes sense as is because I think pascal case should be used to represent react components only. Although these files use JSX, they aren't really React components.

  • githubPRLinkify and jiraLinkify shouldn't be React components so they are easily composable.
  • use represents hooks
  • getFormSchema sometimes uses JSX but is always destructured
  • index isn't generally capitalized
  • test-utils and toast-decorator use JSX but are utils and not components
  • getColumnsTemplate has the same reasoning as getFormSchema

"PASCAL_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.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -174,6 +174,7 @@
"eslint": "8.19.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.8.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",
Expand Down
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
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/EventLog/EventDiffTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
V10HeaderRow as HeaderRow,
} from "@leafygreen-ui/table/new";
import { fontFamilies } from "@leafygreen-ui/tokens";
import { getEventDiffLines } from "./EventLogDiffs";
import { getEventDiffLines } from "./eventLogDiffs";
import { Event, EventDiffLine, EventValue } from "./types";

type TableProps = {
Expand Down
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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Divider } from "./Divider";
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be lower case and doesn't need the TSX extension. Divider.tsx

import { FiltersWrapper } from "./filters";
import { inactiveElementStyle } from "./Inactive";
import { inactiveElementStyle } from "./inactive";
import {
ErrorMessage,
InputLabel,
Expand Down
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
Expand Up @@ -4,7 +4,7 @@ import {
AuthProvider,
useAuthDispatchContext,
useAuthStateContext,
} from "./auth";
} from "./Auth";

const { cleanup, mockEnv } = mockEnvironmentVariables();

Expand Down
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 }> = ({
Expand Down
2 changes: 1 addition & 1 deletion src/gql/GQLWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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%;"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pages/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/configurePatch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { PodEventsQuery } from "gql/generated/types";
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
Expand Down
6 changes: 4 additions & 2 deletions src/pages/container/EventsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

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

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

Expand Down
9 changes: 7 additions & 2 deletions src/pages/host/HostTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ import { useMemo } from "react";
import { useQuery } from "@apollo/client";
import styled from "@emotion/styled";
import { LeafyGreenTableRow } from "@leafygreen-ui/table/new";
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<
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions src/pages/preferences/preferencesTabs/notificationTab/utils.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
getCommitsRoute,
getPatchRoute,
getTaskRoute,
getVersionRoute,
} from "constants/routes";
import { Selector } from "gql/generated/types";
import { ResourceType } from "types/triggers";

export const getResourceRoute = (
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 "";
}
};
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.

This doesn't actually need the .tsx extension because they don't contain any tsx but I changed it to tsx because to match the current pattern. I see how tsx could make sense since the file exports the entry to a page which has a bunch of tsx.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this change is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we change this back to .ts then I will either need to add an exception since it's currently pascal case, or convert it into camelcase. I prefer converting it into camel case.

File renamed without changes.
Loading