diff --git a/.eslintrc.js b/.eslintrc.js index 504dc12b44..b4a499b3d3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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", + }, + { + ignoreMiddleExtensions: true, + }, + ], }, overrides: [ // For React Typescript files in src. diff --git a/cypress/integration/404.ts b/cypress/integration/not_found.ts similarity index 100% rename from cypress/integration/404.ts rename to cypress/integration/not_found.ts diff --git a/cypress/integration/projectHealth/taskHistory.ts b/cypress/integration/projectHealth/task_history.ts similarity index 100% rename from cypress/integration/projectHealth/taskHistory.ts rename to cypress/integration/projectHealth/task_history.ts diff --git a/cypress/integration/projectHealth/variantHistory.ts b/cypress/integration/projectHealth/variant_history.ts similarity index 100% rename from cypress/integration/projectHealth/variantHistory.ts rename to cypress/integration/projectHealth/variant_history.ts diff --git a/cypress/integration/task/task-queue-position.ts b/cypress/integration/task/task_queue_position.ts similarity index 100% rename from cypress/integration/task/task-queue-position.ts rename to cypress/integration/task/task_queue_position.ts diff --git a/package.json b/package.json index f61889d637..8755c6d6c3 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,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", @@ -174,6 +174,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", diff --git a/scripts/prodServer.js b/scripts/prod-server.js similarity index 100% rename from scripts/prodServer.js rename to scripts/prod-server.js diff --git a/src/components/Content/Layout.tsx b/src/components/Content/Layout.tsx index d05af83fa5..6e870453ed 100644 --- a/src/components/Content/Layout.tsx +++ b/src/components/Content/Layout.tsx @@ -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"; diff --git a/src/components/Content/index.tsx b/src/components/Content/index.tsx index f672760462..fb016acab5 100644 --- a/src/components/Content/index.tsx +++ b/src/components/Content/index.tsx @@ -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"; diff --git a/src/components/Header/Navbar.tsx b/src/components/Header/Navbar.tsx index 730ac0a9f9..ec96dde990 100644 --- a/src/components/Header/Navbar.tsx +++ b/src/components/Header/Navbar.tsx @@ -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"; diff --git a/src/components/Header/UserDropdown.tsx b/src/components/Header/UserDropdown.tsx index 235ae98717..2ead04aca1 100644 --- a/src/components/Header/UserDropdown.tsx +++ b/src/components/Header/UserDropdown.tsx @@ -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"; diff --git a/src/components/MetadataCard.tsx b/src/components/MetadataCard.tsx index f6b98a96cf..c6bbc9031c 100644 --- a/src/components/MetadataCard.tsx +++ b/src/components/MetadataCard.tsx @@ -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; diff --git a/src/components/Settings/EventLog/EventDiffTable.tsx b/src/components/Settings/EventLog/EventDiffTable.tsx index 8dcb283f65..ff1c1f56df 100644 --- a/src/components/Settings/EventLog/EventDiffTable.tsx +++ b/src/components/Settings/EventLog/EventDiffTable.tsx @@ -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 = { diff --git a/src/components/Settings/EventLog/EventLogDiffs.test.ts b/src/components/Settings/EventLog/eventLogDiffs.test.ts similarity index 98% rename from src/components/Settings/EventLog/EventLogDiffs.test.ts rename to src/components/Settings/EventLog/eventLogDiffs.test.ts index e6a4346ac0..56e2da9b65 100644 --- a/src/components/Settings/EventLog/EventLogDiffs.test.ts +++ b/src/components/Settings/EventLog/eventLogDiffs.test.ts @@ -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 = { __typename: "ProjectEventSettings", diff --git a/src/components/Settings/EventLog/EventLogDiffs.ts b/src/components/Settings/EventLog/eventLogDiffs.ts similarity index 100% rename from src/components/Settings/EventLog/EventLogDiffs.ts rename to src/components/Settings/EventLog/eventLogDiffs.ts diff --git a/src/components/VersionRestartModal/VersionTasks.tsx b/src/components/VersionRestartModal/VersionTasks.tsx index 35113fa21e..8c222e3725 100644 --- a/src/components/VersionRestartModal/VersionTasks.tsx +++ b/src/components/VersionRestartModal/VersionTasks.tsx @@ -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"; diff --git a/src/components/styles/Divider.tsx b/src/components/styles/divider.ts similarity index 100% rename from src/components/styles/Divider.tsx rename to src/components/styles/divider.ts diff --git a/src/components/styles/filters.tsx b/src/components/styles/filters.ts similarity index 100% rename from src/components/styles/filters.tsx rename to src/components/styles/filters.ts diff --git a/src/components/styles/Inactive.ts b/src/components/styles/inactive.ts similarity index 100% rename from src/components/styles/Inactive.ts rename to src/components/styles/inactive.ts diff --git a/src/components/styles/index.ts b/src/components/styles/index.ts index 4131f9214b..4164dc3b49 100644 --- a/src/components/styles/index.ts +++ b/src/components/styles/index.ts @@ -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, diff --git a/src/context/auth.test.tsx b/src/context/Auth.test.tsx similarity index 99% rename from src/context/auth.test.tsx rename to src/context/Auth.test.tsx index e534e53a38..2225495a31 100644 --- a/src/context/auth.test.tsx +++ b/src/context/Auth.test.tsx @@ -4,7 +4,7 @@ import { AuthProvider, useAuthDispatchContext, useAuthStateContext, -} from "./auth"; +} from "./Auth"; const { cleanup, mockEnv } = mockEnvironmentVariables(); diff --git a/src/context/auth.tsx b/src/context/Auth.tsx similarity index 100% rename from src/context/auth.tsx rename to src/context/Auth.tsx diff --git a/src/context/Providers.tsx b/src/context/Providers.tsx index 5c76fc937b..65f8bf9940 100644 --- a/src/context/Providers.tsx +++ b/src/context/Providers.tsx @@ -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 }> = ({ diff --git a/src/context/toast/toast.test.tsx b/src/context/toast/Toast.test.tsx similarity index 100% rename from src/context/toast/toast.test.tsx rename to src/context/toast/Toast.test.tsx diff --git a/src/gql/GQLWrapper.tsx b/src/gql/GQLWrapper.tsx index f0e62bd846..9953470eed 100644 --- a/src/gql/GQLWrapper.tsx +++ b/src/gql/GQLWrapper.tsx @@ -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, diff --git a/src/pages/404/__snapshots__/NotFound.stories.storyshot b/src/pages/404/__snapshots__/NotFound.stories.storyshot index 72ac7fb7d0..584c2f537b 100644 --- a/src/pages/404/__snapshots__/NotFound.stories.storyshot +++ b/src/pages/404/__snapshots__/NotFound.stories.storyshot @@ -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`] = `
-) => { +interface EventCopyProps { + event: Unpacked; +} +export const EventCopy: React.FC = ({ event }) => { const { data, eventType } = event; const taskLink = ( = () => { {getDateCopy(datum.timestamp)} - {getEventCopy(datum)} + + + )} diff --git a/src/pages/distroSettings/tabs/GeneralTab/transformers.test.tsx b/src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts similarity index 100% rename from src/pages/distroSettings/tabs/GeneralTab/transformers.test.tsx rename to src/pages/distroSettings/tabs/GeneralTab/transformers.test.ts diff --git a/src/pages/distroSettings/tabs/TaskTab/transformers.test.tsx b/src/pages/distroSettings/tabs/TaskTab/transformers.test.ts similarity index 100% rename from src/pages/distroSettings/tabs/TaskTab/transformers.test.tsx rename to src/pages/distroSettings/tabs/TaskTab/transformers.test.ts diff --git a/src/pages/host/getHostEventString.tsx b/src/pages/host/HostEventString.tsx similarity index 97% rename from src/pages/host/getHostEventString.tsx rename to src/pages/host/HostEventString.tsx index 5fb95127b0..515a628a7a 100644 --- a/src/pages/host/getHostEventString.tsx +++ b/src/pages/host/HostEventString.tsx @@ -40,10 +40,15 @@ const TaskLink: React.FC = ({ "data-cy": dataCy, taskId }) => ( {taskId} ); -export const getHostEventString = ( - eventType: string, - data: HostEventLogData -) => { + +interface HostEventStringProps { + eventType: string; + data: HostEventLogData; +} +export const HostEventString: React.FC = ({ + data, + eventType, +}) => { const succeededString = "succeeded"; const failedString = "failed"; @@ -281,9 +286,8 @@ export const getHostEventString = ( )} ); - default: - return `${eventType}`; + return {eventType}; } }; diff --git a/src/pages/host/HostTable.tsx b/src/pages/host/HostTable.tsx index 040fa6679d..3508247d7f 100644 --- a/src/pages/host/HostTable.tsx +++ b/src/pages/host/HostTable.tsx @@ -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<{ {getDateCopy(datum.timestamp)} - {getHostEventString(datum.eventType, datum.data)} + + + )} diff --git a/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx b/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx index b6ffa57ef5..56d8d37ab8 100644 --- a/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx +++ b/src/pages/preferences/preferencesTabs/notificationTab/UserSubscriptions.tsx @@ -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; diff --git a/src/pages/preferences/preferencesTabs/notificationTab/utils.tsx b/src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx similarity index 81% rename from src/pages/preferences/preferencesTabs/notificationTab/utils.tsx rename to src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx index e7c67d5510..a7cd7ea8d0 100644 --- a/src/pages/preferences/preferencesTabs/notificationTab/utils.tsx +++ b/src/pages/preferences/preferencesTabs/notificationTab/useSubscriptionData.tsx @@ -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 = ( - 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>( (obj, { data, type }) => ({ ...obj, diff --git a/src/pages/preferences/preferencesTabs/notificationTab/utils.ts b/src/pages/preferences/preferencesTabs/notificationTab/utils.ts new file mode 100644 index 0000000000..818e423601 --- /dev/null +++ b/src/pages/preferences/preferencesTabs/notificationTab/utils.ts @@ -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 ""; + } +}; diff --git a/src/pages/task/TaskTabs.tsx b/src/pages/task/TaskTabs.tsx index aecf854f73..68646edb51 100644 --- a/src/pages/task/TaskTabs.tsx +++ b/src/pages/task/TaskTabs.tsx @@ -11,7 +11,7 @@ import { usePrevious } from "hooks"; import { useTabShortcut } from "hooks/useTabShortcut"; import { TaskTab } from "types/task"; import { queryString } from "utils"; -import { BuildBaron } from "./taskTabs/BuildBaron"; +import { BuildBaron } from "./taskTabs/buildBaron"; import { useBuildBaronVariables } from "./taskTabs/buildBaronAndAnnotations"; import { ExecutionTasksTable } from "./taskTabs/ExecutionTasksTable"; import FileTable from "./taskTabs/FileTable"; diff --git a/src/pages/task/taskTabs/BuildBaron.ts b/src/pages/task/taskTabs/buildBaron.ts similarity index 100% rename from src/pages/task/taskTabs/BuildBaron.ts rename to src/pages/task/taskTabs/buildBaron.ts diff --git a/src/utils/commits/bucketByCommit.test.tsx b/src/utils/commits/bucketByCommit.test.ts similarity index 100% rename from src/utils/commits/bucketByCommit.test.tsx rename to src/utils/commits/bucketByCommit.test.ts diff --git a/yarn.lock b/yarn.lock index fc6863f65d..be7669f470 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9042,6 +9042,14 @@ eslint-module-utils@^2.7.3: dependencies: debug "^3.2.7" +eslint-plugin-check-file@2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-check-file/-/eslint-plugin-check-file-2.6.2.tgz#2e60d567ce7d087727d19c7e7b5b9def1e5b693e" + integrity sha512-z3Rur4JjOdNH0fia1IH7JQseo9NLuFVtw9j8P6z2c5XmXWemH7/qGpmMB8XbOt9bJBNpmPlNAGJty9b3EervPw== + dependencies: + is-glob "^4.0.3" + micromatch "^4.0.5" + eslint-plugin-cypress@^2.12.1: version "2.14.0" resolved "https://registry.yarnpkg.com/eslint-plugin-cypress/-/eslint-plugin-cypress-2.14.0.tgz#c65e1f592680dd25bbd00c86194ee85fecf59bd7"