Skip to content

chore: add precommit hook and update linted files #1534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ if [ -n "$2" ]; then
exit 0
fi

echo "Running linter..."
yarn lint

# Check linter exit status
if [ $? -ne 0 ]; then
echo "Linting failed. Please fix lint errors before committing."
exit 1
else
echo "Adding linted files to staging..."
git add .
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not want to add all files, in an automatic way without the contributor knowing. This should be the developers choice to include changes.

  1. It is possible for a contributor to have changes they do not want to include with the commit.
  2. I think this prevents contributor from making smaller commits to group similar changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So should this be a prepush hook instead? If it's a prepush hook, then commitizen shouldn't be called at all because that's already been done before they ran git push, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK made that change

fi

exec < /dev/tty && git cz --hook || true
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const AtAGlance = ({
{timeCommitment && (
<GlanceItem item={timeCommitment} type="timeCommitment" />
)}
{stemOptText && (
<GlanceItem item={stemOptText} type="stemOptText" />
)}
{stemOptText && <GlanceItem item={stemOptText} type="stemOptText" />}
</ul>
</section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ const DetailPage = ({
mathIntensity={
atAGlance?.mathIntensity || resolver.getMathIntensity()
}
stemOptText={
resolver.hasStemOptText()
}

stemOptText={resolver.hasStemOptText()}
/>
)}
{!introContent?.hideRequiredCourses &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const glanceItemsMap = {
},
mathIntensity: { icon: "calculator", title: "Math intensity" },
timeCommitment: { icon: "calendar-alt", title: "Time commitment" },
stemOptText: {icon: "star", title: "STEM-OPT extension eligible"}
stemOptText: { icon: "star", title: "STEM-OPT extension eligible" },
};

const GRID_VIEW_ID = "grid-view";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RfiSelect } from "../../controls";
* @param {{ gaData: import("../../../../../../shared/services/googleAnalytics").GAEventObject}} props
*/
// eslint-disable-next-line react/prop-types
export const Campus = ({ gaData, autoFocus}) => {
export const Campus = ({ gaData, autoFocus }) => {
const label = "Which applies to you?";
const name = "Campus";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from "react";

import { gaEventPropTypes, trackGAEvent } from "../../../../../../shared";
import { PII_VALUE } from "../../../core/utils/constants";
import { fetchCountries } from "../../../core/utils/fetchCountries";
import { useRfiContext } from "../../../core/utils/rfiContext";
import { RfiSelect } from "../../controls";
import { PII_VALUE } from "../../../core/utils/constants";

// Options
function getCountryOptions(resultsArrayOfObjects) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";

import { gaEventPropTypes, trackGAEvent } from "../../../../../../shared";
import { RfiEmailInput } from "../../controls";
import { PII_VALUE } from "../../../core/utils/constants";
import { RfiEmailInput } from "../../controls";

/**
* @param {{ gaData: import("../../../../../../shared/services/googleAnalytics").GAEventObject}} props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";

import { gaEventPropTypes, trackGAEvent } from "../../../../../../shared";
import { RfiTextInput } from "../../controls";
import { PII_VALUE } from "../../../core/utils/constants";
import { RfiTextInput } from "../../controls";

/**
* @param {{ gaData: import("../../../../../../shared/services/googleAnalytics").GAEventObject}} props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";

import { gaEventPropTypes, trackGAEvent } from "../../../../../../shared";
import { RfiTextInput } from "../../controls";
import { PII_VALUE } from "../../../core/utils/constants";
import { RfiTextInput } from "../../controls";

/**
* @param {{ gaData: import("../../../../../../shared/services/googleAnalytics").GAEventObject}} props
Expand Down
2 changes: 1 addition & 1 deletion packages/app-rfi/src/components/steps/questions/Phone.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";

import { gaEventPropTypes, trackGAEvent } from "../../../../../../shared";
import { RfiPhone } from "../../controls";
import { PII_VALUE } from "../../../core/utils/constants";
import { RfiPhone } from "../../controls";

/**
* @param {{ gaData: import("../../../../../../shared/services/googleAnalytics").GAEventObject}} props
Expand Down
4 changes: 2 additions & 2 deletions packages/app-webdir-ui/src/ProfileCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const ProfileCard = ({ ...props }) => {
<ul className="person-contact-info">
{props.email && (
<li>
<span className="fas fa-envelope"/>
<span className="fas fa-envelope" />
<a
onClick={() => sendEvent(props.email)}
href={`mailto:${props.email.toLowerCase()}`}
Expand All @@ -108,7 +108,7 @@ const ProfileCard = ({ ...props }) => {
)}
{formattedTelephone && (
<li>
<span className="fas fa-phone"/>
<span className="fas fa-phone" />
<a
onClick={() => sendEvent(formattedTelephone)}
href={`tel:${formattedTelephone}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const WebDirLayout = styled.div`
.uds-grid > .row {
gap: 1rem;
& > div {
flex: 0 0 282px;
flex: 0 0 282px;
}
}

Expand Down Expand Up @@ -47,7 +47,7 @@ const FacultyRankLayout = styled.div`
.uds-grid > .row {
gap: 1rem;
& > div {
flex: 0 0 282px;
flex: 0 0 282px;
}
}
.view-toggle {
Expand Down
4 changes: 1 addition & 3 deletions packages/app-webdir-ui/src/grid/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ const Grid = ({

return (
<div className={`uds-grid ${className || ""}`}>
<div className={`row ${rowClassName || ""}`}>
{renderContent()}
</div>
<div className={`row ${rowClassName || ""}`}>{renderContent()}</div>
</div>
);
};
Expand Down
6 changes: 4 additions & 2 deletions packages/component-header-footer/src/footer/index.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ const StyledFooter = styled.footer`
sans-serif;
line-height: 1.5rem;

a:focus, button:focus {
a:focus,
button:focus {
outline: none;
box-shadow: 0 0 0 2px var(--color-base-white), 0 0 0 4px var(--color-base-grey-7) !important;
box-shadow: 0 0 0 2px var(--color-base-white),
0 0 0 4px var(--color-base-grey-7) !important;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// @ts-check
import { render, fireEvent, cleanup } from "@testing-library/react";
import React from "react";

import { NavbarContainer, BUTTON_ERROR_MESSAGE } from ".";

import { trackGAEvent } from "../../../../../../../shared";
import { AppContextProvider } from "../../../core/context/app-context";

jest.mock("../../../../../../../shared", () => ({
idGenerator: jest.fn().mockImplementation(function* () {
Expand All @@ -11,9 +15,6 @@ jest.mock("../../../../../../../shared", () => ({
trackGAEvent: jest.fn(),
}));

import { NavbarContainer, BUTTON_ERROR_MESSAGE } from ".";
import { AppContextProvider } from "../../../core/context/app-context";

const stateWithButtons = {
navTree: [
{
Expand Down Expand Up @@ -66,12 +67,12 @@ const stateWithButtons = {
buttons: [
{ text: "Login", href: "/login" },
{ text: "Sign Up", onClick: jest.fn() },
{ text: "Contact", onClick: jest.fn(), href: "#" }
{ text: "Contact", onClick: jest.fn(), href: "#" },
],
breakpoint: "lg"
breakpoint: "lg",
};

const renderNavbarContainer = (props) => {
const renderNavbarContainer = props => {
return render(
<AppContextProvider initialValue={props}>
<NavbarContainer />
Expand Down Expand Up @@ -133,7 +134,9 @@ describe("#NavbarContainer Button Tests", () => {
it("should log an error for buttons with both onClick and href", () => {
cleanup();

const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
const consoleErrorSpy = jest
.spyOn(console, "error")
.mockImplementation(() => {});

renderNavbarContainer(stateWithButtons);

Expand All @@ -145,13 +148,14 @@ describe("#NavbarContainer Button Tests", () => {
it("should not render buttons section when no buttons exist in context", () => {
const stateWithoutButtons = {
...stateWithButtons,
buttons: []
buttons: [],
};

cleanup();
const noButtonsComponent = renderNavbarContainer(stateWithoutButtons);

const buttonsContainer = noButtonsComponent.queryByTestId("buttons-container");
const buttonsContainer =
noButtonsComponent.queryByTestId("buttons-container");
expect(buttonsContainer).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ DropdownItem.propTypes = {
dropdownName: PropTypes.string,
items: PropTypes.arrayOf(
PropTypes.arrayOf(
PropTypes.shape({
text: PropTypes.string,
selected: PropTypes.bool,
onClick: PropTypes.func,
href: PropTypes.string,
})
)
PropTypes.shape({
text: PropTypes.string,
selected: PropTypes.bool,
onClick: PropTypes.func,
href: PropTypes.string,
})
)
),
buttons: PropTypes.arrayOf(PropTypes.shape(ButtonPropTypes)),
classes: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ describe("#Navbar Container Component with onClick and no href", () => {
navTree: testNavTreeWithOnClickEventAndNoHref.map(item => ({
...item,
onClick: item.items?.length ? undefined : () => onClick(),
items: item.items?.map(subMenu =>
subMenu.map(subItem => ({
...subItem,
onClick: subItem.onClick ? () => subMenuOnClick() : () => undefined,
}))
) || undefined,
items:
item.items?.map(subMenu =>
subMenu.map(subItem => ({
...subItem,
onClick: subItem.onClick
? () => subMenuOnClick()
: () => undefined,
}))
) || undefined,
})),
});
navItems = component.queryAllByTestId("nav-item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("#Button", () => {

it("should call onClick", () => {
fireEvent.click(element);
expect(buttonOnClick).toBeCalledTimes(1);
expect(buttonOnClick).toHaveBeenCalledTimes(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ describe("#Button Icon", () => {

it("should call onClick", () => {
fireEvent.click(element);
expect(buttonOnClick).toBeCalledTimes(1);
expect(buttonOnClick).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("#Tag Button", () => {

it("should call onClick", () => {
fireEvent.click(element);
expect(buttonOnClick).toBeCalledTimes(1);
expect(buttonOnClick).toHaveBeenCalledTimes(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
} from "../../../../../shared";
import { Button } from "../Button/Button";
import { GaEventWrapper } from "../GaEventWrapper/GaEventWrapper";
import { AnchorMenuWrapper } from "./AnchorMenu.styles";
import { useBaseSpecificFramework } from "../GaEventWrapper/useBaseSpecificFramework";
import { AnchorMenuWrapper } from "./AnchorMenu.styles";

const menuTitle = "On This Page";

Expand All @@ -44,7 +44,6 @@ export const AnchorMenu = ({
firstElementId,
focusFirstFocusableElement = false,
}) => {

const { isReact, isBootstrap } = useBaseSpecificFramework();

const anchorMenuRef = useRef(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const Pagination = ({
};

const renderPages = () => {

if (totalPages < 5) {
return (
<>
Expand Down Expand Up @@ -119,7 +118,7 @@ export const Pagination = ({
1
</PageItem>
)}
{selectedPage > (totalPages - displayMinimumPages ) && (
{selectedPage > totalPages - displayMinimumPages && (
<PageItem
isClickeable
ariaLabel={`Page 2 of ${totalPages}`}
Expand All @@ -144,10 +143,10 @@ export const Pagination = ({
{renderedPages[renderedPages.length - 1] < totalPages - 1 && (
<PageItem ellipses>...</PageItem>
)}
{selectedPage < displayMinimumPages + 1 && (
{selectedPage < displayMinimumPages + 1 && (
<PageItem
isClickeable
ariaLabel={`Page ${totalPages-1} of ${totalPages}`}
ariaLabel={`Page ${totalPages - 1} of ${totalPages}`}
selectedPage={selectedPage === totalPages - 1}
onClick={e => handleChangePage(e, totalPages - 1)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import PropTypes from "prop-types";
import React from "react";

import { GaEventWrapper } from "../../GaEventWrapper/GaEventWrapper";
import { NavControlButtons } from "./NavControls.styles";
import { useBaseSpecificFramework } from "../../GaEventWrapper/useBaseSpecificFramework";
import { NavControlButtons } from "./NavControls.styles";

/**
* @typedef {Object} NavControlsProps
Expand Down