Skip to content

Commit 77bd49f

Browse files
committed
Add husky pre-commit hook to lint and test
Currently the test suite runs in a few sections and is pretty quick. A push to main will auto-deploy so currently keeping checks local with git hooks instead of a CI environment. This commit also ignores the prop-type rules for existing components. In the future this should be done or typed with typescript.
1 parent ae1e559 commit 77bd49f

File tree

16 files changed

+27
-1
lines changed

16 files changed

+27
-1
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
plugins: ['react', 'prettier'],
1717
rules: {
1818
'prettier/prettier': 'error',
19+
'react/no-unescaped-entities': ['error', { forbid: ['>', '}'] }],
1920
},
2021
settings: {
2122
react: {

.husky/pre-commit

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint
5+
yarn test

components/button.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/prop-types */
12
import React from 'react';
23
import { useTheme } from '../hooks/theme/index';
34

components/content/section.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/prop-types */
12
import React from 'react';
23

34
export function SectionHeading({ children }) {

components/link.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/prop-types */
12
import React from 'react';
23
import { default as NextLink } from 'next/link';
34
import { useTheme } from '../hooks/theme/index';

components/modal.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import FocusLock from 'react-focus-lock';
33

4+
// eslint-disable-next-line react/prop-types
45
export default function Modal({ children, onClose }) {
56
const classNames = [
67
'fixed',

components/rhythm-edit/rhythm-edit.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react/prop-types */
2+
13
import React, { useState } from 'react';
24
import Button from '../button';
35
import { denominatorTerm } from '../../utils/denominator-term';

components/rhythm-edit/validated-wrapper.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ let errorIdCount = 0;
44

55
const getErrorIdCount = () => errorIdCount;
66

7+
// eslint-disable-next-line react/prop-types
78
export function ValidationWrapper({ hasSubmitted, error, children }) {
89
const errorId = `vw-error-${getErrorIdCount()}`;
910
const showError = hasSubmitted && error;

components/rhythm-list.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Rhythm from './rhythm/rhythm';
33
import Button from './button';
44
import { useRhythms } from '../hooks/rhythms';
55

6+
// eslint-disable-next-line react/prop-types
67
export default function RhythmList({ onEdit }) {
78
const [rhythms, rhythmsDispatch] = useRhythms();
89

components/rhythm/rhythm.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/prop-types */
12
import React from 'react';
23
import Occurrence from './occurrence';
34
import { numeratorTerm } from '../../utils/numerator-term';

hooks/rhythms/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function rhythmsReducer(rhythms, action) {
8989
}
9090
}
9191

92+
// eslint-disable-next-line react/prop-types
9293
export const RhythmsProvider = ({ children }) => {
9394
const initialRhythms = initializeRhythms();
9495
const [rhythms, dispatch] = useReducer(rhythmsReducer, initialRhythms);

hooks/theme/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export { themeKeys, themeDefinitions };
99

1010
const ThemeContext = createContext();
1111

12+
// eslint-disable-next-line react/prop-types
1213
export const ThemeProvider = ({ value, children }) => {
1314
const { theme: localStorageTheme } = getLocalStorageTheme() ?? {};
1415
const initialThemeName = value ?? localStorageTheme ?? DEFAULT_THEME;

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"test": "jest",
1010
"lint": "eslint \"**/*.js\"",
1111
"storybook": "start-storybook -p 6006",
12-
"build-storybook": "build-storybook"
12+
"build-storybook": "build-storybook",
13+
"prepare": "husky install"
1314
},
1415
"dependencies": {
1516
"chroma-js": "^2.1.1",
@@ -38,6 +39,7 @@
3839
"eslint-config-prettier": "^8.3.0",
3940
"eslint-plugin-prettier": "^3.4.0",
4041
"eslint-plugin-react": "^7.23.2",
42+
"husky": "^7.0.0",
4143
"jest": "^26.6.3",
4244
"jest-localstorage-mock": "^2.4.9",
4345
"jest-transform-css": "^2.1.0",

pages/_app.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ThemeProvider } from '../hooks/theme/index';
66
import Link from '../components/link';
77
import { useEffect } from 'react';
88

9+
// eslint-disable-next-line react/prop-types
910
function NextApp({ Component, pageProps }) {
1011
useEffect(() => {
1112
// This prevents a vertical shift of content when navigating

pages/home.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SectionParagraph,
1212
} from '../components/content/section';
1313

14+
// eslint-disable-next-line react/prop-types
1415
function Highlight({ children }) {
1516
const [theme] = useTheme();
1617

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -6850,6 +6850,11 @@ human-signals@^1.1.1:
68506850
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
68516851
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==
68526852

6853+
husky@^7.0.0:
6854+
version "7.0.0"
6855+
resolved "https://registry.yarnpkg.com/husky/-/husky-7.0.0.tgz#3dbd5d28e76234689ee29bb41e048f28e3e46616"
6856+
integrity sha512-xK7lO0EtSzfFPiw+oQncQVy/XqV7UVVjxBByc+Iv5iK3yhW9boDoWgvZy3OGo48QKg/hUtZkzz0hi2HXa0kn7w==
6857+
68536858
iconv-lite@0.4.24:
68546859
version "0.4.24"
68556860
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"

0 commit comments

Comments
 (0)