Skip to content

Commit

Permalink
feat: add layer-imports eslint rule, fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Mar 13, 2024
1 parent f012a6b commit 242ed67
Show file tree
Hide file tree
Showing 46 changed files with 80 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ module.exports = {
'react/no-array-index-key': 'off',
'react/jsx-no-useless-fragment': 'off',
'paths-fixes/path-checker': ['error', { alias: '@' }],
'paths-fixes/layer-imports': [
'error',
{
alias: '@',
ignoreImportPatterns: ['**/StoreProvider', '**/testing'],
},
],
'paths-fixes/public-api-imports': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion config/storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { addDecorator } from '@storybook/react';
import { StyleDecorator } from '../../src/shared/config/storybook/StyleDecorator/StyleDecorator';
import { ThemeDecorator } from '../../src/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '../../src/app/providers/ThemeProvider';
import { RouterDecorator } from '../../src/shared/config/storybook/RouterDecorator/RouterDecorator';
import { SuspenseDecorator } from '../../src/shared/config/storybook/SuspenseDecorator/SuspenseDecorator';
import { Theme } from '../../src/shared/const/theme';

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand Down
9 changes: 8 additions & 1 deletion extractedTranslations/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"Error with getting article data": "Error with getting article data",
"Exit": "Exit",
"IT": "IT",
"Leave your feedback on the article, it will help improve the quality": "Leave your feedback on the article, it will help improve the quality",
"Profile": "Profile",
"Rate the article": "Rate the article",
"Read more": {
"": {
"": {
Expand All @@ -30,6 +32,7 @@
"Search": "Search",
"Send": "Send",
"Sort by": "Sort by",
"Thanks for review!": "Thanks for review!",
"Try to reload page": "Try to reload page",
"You don`t have access to this page!": "You don`t have access to this page!",
"ascending": "ascending",
Expand All @@ -48,7 +51,11 @@
"no comments": "no comments",
"throw error": "throw error",
"views": "views",
"Ваш отзыв": "Ваш отзыв",
"Главная страница": "Главная страница",
"Закрыть": "Закрыть",
"Обновить страницу": "Обновить страницу",
"Произошла непредвиденная ошибка": "Произошла непредвиденная ошибка"
"Отправить": "Отправить",
"Произошла непредвиденная ошибка": "Произошла непредвиденная ошибка",
"Статьи не найдены": "Статьи не найдены"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"eslint-plugin-i18next": "^5.1.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-paths-fixes": "^0.0.3",
"eslint-plugin-paths-fixes": "^0.0.6",
"eslint-plugin-react": "^7.29.2",
"eslint-plugin-react-hooks": "^4.3.0",
"file-loader": "^6.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, { Suspense, useEffect } from 'react';
import './styles/index.scss';
import { useDispatch, useSelector } from 'react-redux';
import { classNames } from '@/shared/lib/classNames/classNames';
import { AppRouter } from '@/app/providers/router';
import { AppRouter } from './providers/router';
import { Navbar } from '@/widgets/Navbar';
import { Sidebar } from '@/widgets/Sidebar';
import { getUserInited, userActions } from '@/entities/User';
import { useTheme } from '@/app/providers/ThemeProvider';
import { useTheme } from '@/shared/lib/hook/useTheme/useTheme';

function App() {
const { theme } = useTheme();
Expand Down
10 changes: 6 additions & 4 deletions src/app/providers/StoreProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { StoreProvider } from '@/app/providers/StoreProvider/ui/StoreProvider';
import { StoreProvider } from './ui/StoreProvider';
import {
AppDispatch,
createReduxStore,
} from '@/app/providers/StoreProvider/config/store';
import type { StateSchema, ThunkExtraArg, ThunkConfig } from '@/app/providers/StoreProvider/config/StateSchema';
} from './config/store';
import type {
StateSchema, ThunkExtraArg, ThunkConfig, ReduxStoreWithManager, StateSchemaKey,
} from './config/StateSchema';

export {
StoreProvider, createReduxStore, StateSchema, ThunkExtraArg, ThunkConfig,
StoreProvider, createReduxStore, StateSchema, ThunkExtraArg, ThunkConfig, ReduxStoreWithManager, StateSchemaKey,
};
export type { AppDispatch };
4 changes: 2 additions & 2 deletions src/app/providers/StoreProvider/ui/StoreProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReactNode } from 'react';
import { Provider } from 'react-redux';
import { ReducersMapObject } from '@reduxjs/toolkit';
import { createReduxStore } from '@/app/providers/StoreProvider/config/store';
import { StateSchema } from '@/app/providers/StoreProvider/config/StateSchema';
import { StateSchema } from '../../StoreProvider/config/StateSchema';
import { createReduxStore } from '../../StoreProvider/config/store';

interface StoreProviderProps {
children?: ReactNode | any;
Expand Down
4 changes: 0 additions & 4 deletions src/app/providers/ThemeProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import ThemeProvider from './ui/ThemeProvider';
import { useTheme } from './lib/useTheme';
import { Theme } from './lib/ThemeContext';

export {
ThemeProvider,
useTheme,
Theme,
};
16 changes: 0 additions & 16 deletions src/app/providers/ThemeProvider/lib/ThemeContext.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/app/providers/ThemeProvider/ui/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {
FC, ReactNode, useMemo, useState,
} from 'react';
import { LOCAL_STORAGE_THEME_KEY, Theme, ThemeContext } from '../lib/ThemeContext';
import { ThemeContext } from '../../../../shared/lib/context/ThemeContext';
import { Theme } from '@/shared/const/theme';
import { LOCAL_STORAGE_THEME_KEY } from '@/shared/const/localstorage';

const defaultTheme = localStorage.getItem(LOCAL_STORAGE_THEME_KEY) as Theme || Theme.LIGHT;

Expand Down
6 changes: 3 additions & 3 deletions src/app/providers/router/ui/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { memo, Suspense, useCallback } from 'react';
import { Route, Routes } from 'react-router-dom';
import { RequireAuth } from '@/app/providers/router/ui/RequireAuth';
import { PageLoader } from '@/widgets/PageLoader';
import { routeConfig } from '@/app/providers/router/config/routeConfig';
import { RequireAuth } from './RequireAuth';
import { routeConfig } from '../config/routeConfig';
import { AppRoutesProps } from '@/shared/types/router';
import { PageLoader } from '@/features/PageLoader';

const AppRouter = () => {
const renderWithWrapper = useCallback((route: AppRoutesProps) => {
Expand Down
2 changes: 1 addition & 1 deletion src/features/AuthByUsername/ui/LoginModal/LoginModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Suspense } from 'react';
import { Modal } from '@/shared/ui/Modal/Modal';
import { LoginFormAsync } from '../LoginForm/LoginForm.async';
import { PageLoader } from '@/widgets/PageLoader';
import { PageLoader } from '../../../PageLoader';

interface LoginModalProps {
className?: string;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { classNames } from '@/shared/lib/classNames/classNames';
import { Theme, useTheme } from '@/app/providers/ThemeProvider';
import { Button, ButtonTheme } from '@/shared/ui/Button/Button';
import LightIcon from '../../../shared/assets/icons/theme-light.svg';
import DarkIcon from '../../../shared/assets/icons/theme-dark.svg';
import { Theme } from '@/shared/const/theme';
import { useTheme } from '@/shared/lib/hook/useTheme/useTheme';

interface ThemeSwitcherProps {
className?: string;
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ root.render(
</StoreProvider>
</BrowserRouter>,
);
export { Theme } from '@/shared/const/theme';
2 changes: 1 addition & 1 deletion src/pages/AboutPage/ui/AboutPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { AboutPage } from '../index';
import { Theme } from '@/shared/const/theme';

export default {
title: 'pages/AboutPage',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MainPage/ui/MainPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { StoreDecorator } from '@/shared/config/storybook/StoreDecorator/StoreDecorator';
import { MainPage } from '../../MainPage';
import { Theme } from '@/shared/const/theme';

export default {
title: 'pages/MainPage',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NotFoundPage/ui/NotFoundPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { NotFoundPage } from './NotFoundPage';
import { Theme } from '@/shared/const/theme';

export default {
title: 'pages/NotFoundPage',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilePage/ui/ProfilePage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { StoreDecorator } from '@/shared/config/storybook/StoreDecorator/StoreDecorator';
import ProfilePage from './ProfilePage';
import { Country } from '../../../entities/Country';
import { Currency } from '../../../entities/Currency';
import { Theme } from '@/shared/const/theme';

export default {
title: 'pages/ProfilePage',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line paths-fixes/layer-imports
import '@/app/styles/index.scss';
import { Story } from '@storybook/react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Story } from '@storybook/react';
import { Theme, ThemeProvider } from '@/app/providers/ThemeProvider';
import { Theme } from '@/shared/const/theme';
// eslint-disable-next-line paths-fixes/layer-imports
import { ThemeProvider } from '@/app/providers/ThemeProvider';

export const ThemeDecorator = (theme: Theme) => (StoryComponent: Story) => (
<ThemeProvider initialTheme={theme}>
Expand Down
1 change: 1 addition & 0 deletions src/shared/const/localstorage.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const USER_LOCALSTORAGE_KEY = 'user';
export const ARTICLE_VIEW_LOCALSTORAGE_KEY = 'articles_view';
export const LOCAL_STORAGE_THEME_KEY = 'theme';
5 changes: 5 additions & 0 deletions src/shared/const/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Theme {
LIGHT = 'app_light_theme',
DARK = 'app_dark_theme',
ORANGE = 'app_orange_theme',
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Reducer } from '@reduxjs/toolkit';
import {
ReduxStoreWithManager,
StateSchemaKey,
} from '@/app/providers/StoreProvider/config/StateSchema';
} from '@/app/providers/StoreProvider';

export type ReducersList = {
[name in StateSchemaKey]?: Reducer;
Expand Down
9 changes: 9 additions & 0 deletions src/shared/lib/context/ThemeContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createContext } from 'react';
import { Theme } from '../../const/theme';

export interface ThemeContextProps {
theme?: Theme;
setTheme?: (theme: Theme) => void;
}

export const ThemeContext = createContext<ThemeContextProps>({});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useContext } from 'react';
import { LOCAL_STORAGE_THEME_KEY, Theme, ThemeContext } from './ThemeContext';
import { ThemeContext } from '../../context/ThemeContext';
import { Theme } from '../../../const/theme';
import { LOCAL_STORAGE_THEME_KEY } from '../../../const/localstorage';

interface UseThemeResult {
toggleTheme: () => void;
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RouteProps } from 'react-router-dom';
// eslint-disable-next-line paths-fixes/layer-imports
import { UserRole } from '@/entities/User';

export type AppRoutesProps = RouteProps & {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/AppLink/AppLink.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { AppLink, AppLinkTheme } from './AppLink';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/AppLink',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { Button, ButtonSize, ButtonTheme } from './Button';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/Button',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, {
memo, ReactNode, useCallback, useEffect,
} from 'react';
import { classNames } from '@/shared/lib/classNames/classNames';
import { useTheme } from '@/app/providers/ThemeProvider';
import { AnimationProvider, useAnimationLibs } from '@/shared/lib/components/AnimationProvider';
import { Overlay } from '../Overlay/Overlay';
import cls from './Drawer.module.scss';
import { Portal } from '../Portal/Portal';
import { useTheme } from '@/shared/lib/hook/useTheme/useTheme';

interface DrawerProps {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Loader/Loader.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { Loader } from './Loader';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/Loader',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { Modal } from '../Modal/Modal';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/Modal',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { ReactNode } from 'react';
import { classNames, Mods } from '@/shared/lib/classNames/classNames';
import { useTheme } from '@/app/providers/ThemeProvider';
import { useModal } from '@/shared/lib/hook/useModal/useModal';
import { Overlay } from '../Overlay/Overlay';
import { Portal } from '../Portal/Portal';
import cls from './Modal.module.scss';
import { useTheme } from '@/shared/lib/hook/useTheme/useTheme';

interface ModalProps {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Skeleton/Skeleton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';

import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { Skeleton } from './Skeleton';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/Skeleton',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Theme } from '@/app/providers/ThemeProvider';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Text, TextSize, TextTheme } from '../Text/Text';
import { Theme } from '@/shared/const/theme';

export default {
title: 'shared/Text',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/ThemeSwitcher/ui/ThemeSwitcher.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from '@/shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from '@/app/providers/ThemeProvider';
import { ThemeSwitcher } from './ThemeSwitcher';
import { Theme } from '@/shared/const/theme';

export default {
title: 'widgets/ThemeSwitcher',
Expand Down
3 changes: 2 additions & 1 deletion src/shared/ui/ThemeSwitcher/ui/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { memo } from 'react';
import { classNames } from '@/shared/lib/classNames/classNames';
import { Theme, useTheme } from '@/app/providers/ThemeProvider';
import LightIcon from '@/shared/assets/icons/theme-light.svg';
import DarkIcon from '@/shared/assets/icons/theme-dark.svg';
import { Button, ButtonTheme } from '../../Button/Button';
import { Theme } from '@/shared/const/theme';
import { useTheme } from '@/shared/lib/hook/useTheme/useTheme';

interface ThemeSwitcherProps {
className?: string;
Expand Down
Loading

0 comments on commit 242ed67

Please sign in to comment.