Skip to content

Commit c862398

Browse files
authored
chore(eslint): add simple import sort plugin and rules (#127)
* chore(eslint): add simple import sort plugin and rules * fix unit tests
1 parent 28d1e7f commit c862398

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+299
-184
lines changed

.eslintrc

+19-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"react-hooks",
2222
"jsx-a11y",
2323
"import",
24-
"unused-imports"
24+
"unused-imports",
25+
"simple-import-sort"
2526
],
2627
"settings": {
2728
"react": {
@@ -32,6 +33,23 @@
3233
"object-shorthand": "error",
3334
"no-undef": "off",
3435
"no-duplicate-imports": "error",
36+
"import/first": "error",
37+
"import/newline-after-import": "error",
38+
"import/no-duplicates": "error",
39+
"simple-import-sort/exports": "error",
40+
"simple-import-sort/imports": [
41+
"error",
42+
{
43+
"groups": [
44+
["^react", "^@?\\w"],
45+
["^(@components|@models|@services|@stores|@hooks|@helpers|@utils|@tests)(/.*|$)"],
46+
["^\\u0000"],
47+
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
48+
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
49+
["^.+\\.s?css$"]
50+
]
51+
}
52+
],
3553
"@typescript-eslint/consistent-type-imports": [
3654
"error",
3755
{
@@ -44,22 +62,6 @@
4462
"argsIgnorePattern": "^_",
4563
"varsIgnorePattern": "^_"
4664
}
47-
],
48-
"import/order": [
49-
"error",
50-
{
51-
"newlines-between": "always",
52-
"alphabetize": {
53-
"order": "asc"
54-
},
55-
"groups": [
56-
"builtin",
57-
"external",
58-
"internal",
59-
"parent",
60-
["index", "sibling"]
61-
]
62-
}
6365
]
6466
}
6567
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"eslint:fix": "eslint --fix .",
3636
"prettier:check": "prettier --check .",
3737
"prettier:write": "prettier --write .",
38-
"test": "DEBUG_PRINT_LIMIT=30000 jest --config tests/jest.config.js",
38+
"test": "DEBUG_PRINT_LIMIT=30000 jest --silent --config tests/jest.config.js",
3939
"test:watch": "yarn test --watch",
4040
"test:coverage": "yarn test --coverage",
4141
"test:clear-cache": "jest --clearCache",
@@ -97,6 +97,7 @@
9797
"eslint-plugin-jsx-a11y": "^6.8.0",
9898
"eslint-plugin-react": "^7.33.2",
9999
"eslint-plugin-react-hooks": "^4.6.0",
100+
"eslint-plugin-simple-import-sort": "^12.1.1",
100101
"eslint-plugin-unused-imports": "^3.0.0",
101102
"husky": "^8.0.3",
102103
"jest": "^29.7.0",

src/components/App.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { generateCalendarRange } from '@helpers';
2-
import { getWeeksInMonth } from '@internationalized/date';
3-
import { act, render } from '@testing-library/react';
41
import React from 'react';
52
import { useCalendar } from 'react-aria';
63
import { useCalendarState } from 'react-stately';
4+
import { getWeeksInMonth } from '@internationalized/date';
5+
import { act, render } from '@testing-library/react';
6+
7+
import { generateCalendarRange } from '@helpers';
78

89
import App from './App';
910

src/components/App.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import React from 'react';
2+
import { Navigate, Route, Routes } from 'react-router-dom';
3+
import { setDefaultOptions } from 'date-fns';
4+
import { enGB } from 'date-fns/locale';
5+
16
import {
7+
AccountPage,
28
AppHeader,
39
Calendar,
4-
AccountPage,
510
HabitsPage,
611
Snackbars,
712
} from '@components';
8-
import { setDefaultOptions } from 'date-fns';
9-
import { enGB } from 'date-fns/locale';
10-
import React from 'react';
11-
import { Navigate, Route, Routes } from 'react-router-dom';
1213

1314
import Providers from './Providers';
1415

src/components/Providers.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { supabaseClient } from '@helpers';
2-
import { NextUIProvider } from '@nextui-org/react';
3-
import { SessionContextProvider } from '@supabase/auth-helpers-react';
41
import React, { type ReactNode } from 'react';
52
import { I18nProvider } from 'react-aria';
63
import { BrowserRouter, useNavigate } from 'react-router-dom';
4+
import { NextUIProvider } from '@nextui-org/react';
5+
import { SessionContextProvider } from '@supabase/auth-helpers-react';
6+
7+
import { supabaseClient } from '@helpers';
78

89
type ProviderProps = {
910
children: ReactNode;

src/components/calendar/Calendar.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import Calendar from './Calendar';
22

3+
jest.mock('@stores', () => ({
4+
useHabitsStore: jest.fn(),
5+
useOccurrencesStore: jest.fn(),
6+
useTraitsStore: jest.fn(),
7+
}));
8+
39
describe(Calendar.name, () => {
410
it('should be tested', () => {
511
expect(true).toBeTruthy();

src/components/calendar/Calendar.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import React from 'react';
2+
import { type AriaButtonProps, useCalendar, useLocale } from 'react-aria';
3+
import { useCalendarState } from 'react-stately';
4+
import { CalendarDate, GregorianCalendar } from '@internationalized/date';
5+
16
import { generateCalendarRange } from '@helpers';
27
import { useDocumentTitle } from '@hooks';
3-
import { CalendarDate, GregorianCalendar } from '@internationalized/date';
48
import { useOccurrencesStore } from '@stores';
59
import { capitalizeFirstLetter } from '@utils';
6-
import React from 'react';
7-
import { type AriaButtonProps, useCalendar, useLocale } from 'react-aria';
8-
import { useCalendarState } from 'react-stately';
910

1011
import CalendarGrid from './CalendarGrid';
1112
import CalendarHeader from './CalendarHeader';

src/components/calendar/CalendarCell.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import CalendarCell from './CalendarCell';
22

3+
jest.mock('@stores', () => ({
4+
useHabitsStore: jest.fn(),
5+
useOccurrencesStore: jest.fn(),
6+
useTraitsStore: jest.fn(),
7+
}));
8+
39
describe(CalendarCell.name, () => {
410
it('should render', () => {
511
expect(true).toBe(true);

src/components/calendar/CalendarCell.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useScreenSize } from '@hooks';
1+
import React from 'react';
22
import { CalendarBlank } from '@phosphor-icons/react';
3-
import { useOccurrencesStore } from '@stores';
43
import { useUser } from '@supabase/auth-helpers-react';
54
import clsx from 'clsx';
65
import { format } from 'date-fns';
76
import { AnimatePresence, motion } from 'framer-motion';
8-
import React from 'react';
7+
8+
import { useScreenSize } from '@hooks';
9+
import { useOccurrencesStore } from '@stores';
910

1011
import OccurrenceChip from './OccurrenceChip';
1112

src/components/calendar/CalendarGrid.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import CalendarGrid from './CalendarGrid';
22

3+
jest.mock('@stores', () => ({
4+
useHabitsStore: jest.fn(),
5+
useOccurrencesStore: jest.fn(),
6+
useTraitsStore: jest.fn(),
7+
}));
8+
39
describe(CalendarGrid.name, () => {
410
it('should be tested', () => {
511
expect(true).toBeTruthy();

src/components/calendar/CalendarHeader.test.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { render } from '@testing-library/react';
21
import React from 'react';
2+
import { render } from '@testing-library/react';
33

44
import CalendarHeader, { type CalendarHeaderProps } from './CalendarHeader';
55

6+
jest.mock('@stores', () => ({
7+
useHabitsStore: jest.fn(),
8+
useOccurrencesStore: jest.fn(),
9+
useTraitsStore: jest.fn(),
10+
}));
11+
612
describe(CalendarHeader.name, () => {
713
const props: CalendarHeaderProps = {
814
activeMonthLabel: 'January',

src/components/calendar/CalendarHeader.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useScreenSize } from '@hooks';
2-
import { Select, SelectItem, Button, SelectSection } from '@nextui-org/react';
1+
import React from 'react';
2+
import { Button, Select, SelectItem, SelectSection } from '@nextui-org/react';
33
import { ArrowFatLeft, ArrowFatRight } from '@phosphor-icons/react';
4-
import { useTraitsStore, useHabitsStore, useOccurrencesStore } from '@stores';
54
import { useUser } from '@supabase/auth-helpers-react';
6-
import React from 'react';
5+
6+
import { useScreenSize } from '@hooks';
7+
import { useHabitsStore, useOccurrencesStore, useTraitsStore } from '@stores';
78

89
type NavigationButtonProps = {
910
disabled: boolean;

src/components/calendar/CalendarMonthGrid.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { type CalendarDate, getWeeksInMonth } from '@internationalized/date';
2-
import clsx from 'clsx';
31
import React, { type ForwardedRef } from 'react';
42
import { useLocale } from 'react-aria';
53
import { type CalendarState } from 'react-stately';
4+
import { type CalendarDate, getWeeksInMonth } from '@internationalized/date';
5+
import clsx from 'clsx';
66

77
import CalendarCell from './CalendarCell';
88

src/components/calendar/DayHabitModalDialog.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useHabitsStore, useOccurrencesStore } from '@stores';
1+
import React from 'react';
22
import { useUser } from '@supabase/auth-helpers-react';
33
import { fireEvent, render, waitFor } from '@testing-library/react';
4-
import { makeTestHabit } from '@tests';
54
import { format } from 'date-fns';
6-
import React from 'react';
5+
6+
import { useHabitsStore, useOccurrencesStore } from '@stores';
7+
import { makeTestHabit } from '@tests';
78

89
import DayHabitModalDialog from './DayHabitModalDialog';
910

src/components/calendar/DayHabitModalDialog.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import React, { type MouseEventHandler } from 'react';
12
import {
23
Button,
34
Modal,
4-
ModalContent,
5-
ModalHeader,
65
ModalBody,
6+
ModalContent,
77
ModalFooter,
8+
ModalHeader,
89
Select,
910
SelectItem,
1011
} from '@nextui-org/react';
11-
import { useHabitsStore, useOccurrencesStore } from '@stores';
1212
import { useUser } from '@supabase/auth-helpers-react';
1313
import { format } from 'date-fns';
14-
import React, { type MouseEventHandler } from 'react';
14+
15+
import { useHabitsStore, useOccurrencesStore } from '@stores';
1516

1617
type DayHabitModalDialogProps = {
1718
open: boolean;

src/components/calendar/OccurrenceChip.test.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useScreenSize } from '@hooks';
1+
import React from 'react';
22
import { fireEvent, render, waitFor } from '@testing-library/react';
3+
4+
import { useScreenSize } from '@hooks';
35
import { makeTestOccurrence } from '@tests';
46
import { getHabitIconUrl } from '@utils';
5-
import React from 'react';
67

78
import OccurrenceChip, { type OccurrenceChipProps } from './OccurrenceChip';
89

src/components/calendar/OccurrenceChip.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import React from 'react';
12
import type { Occurrence } from '@models';
23
import { Badge, Button, Tooltip } from '@nextui-org/react';
34
import { Trash } from '@phosphor-icons/react';
5+
46
import { getHabitIconUrl } from '@utils';
5-
import React from 'react';
67

78
export type OccurrenceChipProps = {
89
occurrences: Occurrence[];

src/components/calendar/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './Calendar';
22
export { default as Calendar } from './Calendar';
3-
43
export * from './OccurrenceChip';
54
export { default as OccurrenceChip } from './OccurrenceChip';

src/components/common/Alert/Alert.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React, { type ReactNode } from 'react';
12
import { type ButtonProps } from '@nextui-org/react';
23
import {
34
BellRinging,
@@ -9,7 +10,6 @@ import {
910
WarningCircle,
1011
} from '@phosphor-icons/react';
1112
import clsx from 'clsx';
12-
import React, { type ReactNode } from 'react';
1313
import { type SetRequired, type ValueOf } from 'type-fest';
1414

1515
export type ButtonColor = ValueOf<

src/components/common/ConfirmDialog/ConfirmDialog.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { render } from '@testing-library/react';
21
import React from 'react';
2+
import { render } from '@testing-library/react';
33

44
import ConfirmDialog from './ConfirmDialog';
55

src/components/common/ConfirmDialog/ConfirmDialog.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import React from 'react';
12
import {
23
Button,
3-
ModalBody,
4-
ModalHeader,
54
Modal,
5+
ModalBody,
66
ModalContent,
7+
ModalHeader,
78
} from '@nextui-org/react';
8-
import React from 'react';
99

1010
type ConfirmDialogProps = {
1111
open: boolean;

src/components/common/PasswordInput/PasswordInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import React, { type ChangeEventHandler } from 'react';
12
import { Button, Input } from '@nextui-org/react';
23
import { Eye, EyeSlash } from '@phosphor-icons/react';
3-
import React, { type ChangeEventHandler } from 'react';
44

55
type PasswordInputProps = {
66
variant?: 'flat' | 'bordered' | 'faded' | 'underlined';

src/components/common/Snackbars/Snackbars.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Alert } from '@components';
1+
import React from 'react';
22
import { Button } from '@nextui-org/react';
3-
import { useSnackbarsStore } from '@stores';
43
import { AnimatePresence, motion } from 'framer-motion';
5-
import React from 'react';
4+
5+
import { Alert } from '@components';
6+
import { useSnackbarsStore } from '@stores';
67

78
const Snackbars = () => {
89
const { snackbars, hideSnackbar } = useSnackbarsStore();

src/components/common/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
export * from './Alert';
12
export * from './ConfirmDialog';
2-
export * from './VisuallyHiddenInput';
33
export * from './PasswordInput';
4-
export * from './Alert';
54
export * from './Snackbars';
5+
export * from './VisuallyHiddenInput';

src/components/habit/add-habit/AddHabitDialogButton.test.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { StorageBuckets, uploadFile } from '@services';
2-
import { useSnackbarsStore, useHabitsStore } from '@stores';
1+
import React from 'react';
32
import { useUser } from '@supabase/auth-helpers-react';
43
import { act, fireEvent, render, waitFor } from '@testing-library/react';
5-
import React from 'react';
4+
5+
import { StorageBuckets, uploadFile } from '@services';
6+
import { useHabitsStore, useSnackbarsStore } from '@stores';
67

78
import AddHabitDialogButton from './AddHabitDialogButton';
89

src/components/habit/add-habit/AddHabitDialogButton.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { AddCustomTraitModal, VisuallyHiddenInput } from '@components';
2-
import { useTextField, useFileField } from '@hooks';
1+
import React from 'react';
32
import {
43
Button,
54
Input,
@@ -13,9 +12,11 @@ import {
1312
Textarea,
1413
} from '@nextui-org/react';
1514
import { CloudArrowUp, Plus } from '@phosphor-icons/react';
16-
import { useHabitsStore, useTraitsStore } from '@stores';
1715
import { useUser } from '@supabase/auth-helpers-react';
18-
import React from 'react';
16+
17+
import { AddCustomTraitModal, VisuallyHiddenInput } from '@components';
18+
import { useFileField, useTextField } from '@hooks';
19+
import { useHabitsStore, useTraitsStore } from '@stores';
1920

2021
const AddHabitDialogButton = () => {
2122
const user = useUser();

0 commit comments

Comments
 (0)