Skip to content

Commit

Permalink
style: Ban interfaces in linter
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-kiliushin committed Jun 17, 2023
1 parent d189e9a commit 973bf2b
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 103 deletions.
60 changes: 21 additions & 39 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", "node_modules"],
ignorePatterns: ["dist", "node_modules", "src/api"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
Expand All @@ -25,6 +25,26 @@ module.exports = {
plugins: ["react", "@typescript-eslint", "@typescript-eslint/eslint-plugin"],
root: true,
rules: {
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/naming-convention": [
1,
{
selector: "typeAlias",
format: ["StrictPascalCase"],
prefix: ["T"],
},
{
format: ["StrictPascalCase"],
prefix: ["are", "can", "did", "does", "has", "is", "should", "will"],
selector: "variable",
types: ["boolean"],
},
],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-extra-semi": 1,
"@typescript-eslint/no-unused-vars": 0,
"arrow-parens": 1,
camelcase: 1,
"max-params": ["error", 2],
Expand All @@ -39,44 +59,6 @@ module.exports = {
"no-tabs": 1,
"react/jsx-sort-props": ["warn", { ignoreCase: true }],
"react/prop-types": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-extra-semi": 1,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/naming-convention": [
1,
{
format: ["StrictPascalCase"],
prefix: ["I"],
selector: "interface",
},
{
format: ["StrictPascalCase"],
prefix: ["are", "can", "did", "does", "has", "is", "should", "will"],
selector: "variable",
types: ["boolean"],
},
],
// "sort-keys": [
// "warn",
// "asc",
// {
// caseSensitive: true,
// minKeys: 2,
// natural: false,
// },
// ],
// 'sort-imports': [
// 'error',
// {
// allowSeparatedGroups: true,
// ignoreCase: false,
// ignoreDeclarationSort: false,
// ignoreMemberSort: false,
// memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
// },
// ],
},
settings: {
react: {
Expand Down
4 changes: 2 additions & 2 deletions cypress/constants/test-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const testUsers = {
},
} as const

export type ITestUser = typeof testUsers[keyof typeof testUsers]
export type TTestUser = (typeof testUsers)[keyof typeof testUsers]

export const credentialsByTestUserId: Record<ITestUser["id"], { password: string; username: ITestUser["username"] }> = {
export const credentialsByTestUserId: Record<TTestUser["id"], { password: string; username: TTestUser["username"] }> = {
"1": {
username: testUsers.johnDoe.username,
password: testUsers.johnDoe.password,
Expand Down
6 changes: 3 additions & 3 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="cypress" />
import { ITestUser, credentialsByTestUserId } from "../constants/test-users"
import { TTestUser, credentialsByTestUserId } from "../constants/test-users"

// ***********************************************
// This example commands.ts shows you how to
Expand Down Expand Up @@ -41,9 +41,9 @@ import { ITestUser, credentialsByTestUserId } from "../constants/test-users"
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Chainable {
authorize(testUserId: ITestUser["id"]): Promise<void>
authorize(testUserId: TTestUser["id"]): Promise<void>
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import "./commands"
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Chainable {
mount: typeof mount
}
Expand Down
2 changes: 1 addition & 1 deletion declarations/mui.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BreakpointOverrides from ""

declare module "@mui/system" {
// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface BreakpointOverrides {
sm: false
md: false
Expand Down
6 changes: 3 additions & 3 deletions src/components/BreadcrumbsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link, useLocation } from "react-router-dom"

import { useGetBoardQuery } from "#api/boards"

interface IBreadcrumb {
type TBreadcrumb = {
element: ReactNode
hrefTemplate: string
}
Expand All @@ -28,7 +28,7 @@ const BoardName: FC = () => {
return <>{getBoardResult.data?.board.name}</>
}

const breadcrumbsByPathnamePatterns: { pathnamePatterns: RegExp[]; breadcrumbs: IBreadcrumb[] }[] = [
const breadcrumbsByPathnamePatterns: { pathnamePatterns: RegExp[]; breadcrumbs: TBreadcrumb[] }[] = [
{
pathnamePatterns: [/^\/boards$/, /^\/boards\/create$/],
breadcrumbs: [{ element: "Boards", hrefTemplate: "/boards" }],
Expand Down Expand Up @@ -71,7 +71,7 @@ export const BreadcrumbsPanel: FC = () => {
const location = useLocation()
const boardId = useBoardId()

const breadcrumbs = useMemo<IBreadcrumb[] | undefined>(() => {
const breadcrumbs = useMemo<TBreadcrumb[] | undefined>(() => {
for (const group of breadcrumbsByPathnamePatterns) {
const doesPathnameMatchGroupPathnamePatterns = group.pathnamePatterns.some((pathnamePattern) => {
return pathnamePattern.test(location.pathname)
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getChildByDisplayName } from "#utils/getChildByDisplayName"
import { DataLayoutControls } from "./subcomponents/DataLayoutControls"
import { DataLayoutHeading } from "./subcomponents/DataLayoutHeading"
import { DataLayoutTableContainer } from "./subcomponents/DataLayoutTableContainer"
import { IDataLayoutWithSubcomponents, IDataLayoutWithoutSubcomponents } from "./types"
import { TDataLayoutWithSubcomponents, TDataLayoutWithoutSubcomponents } from "./types"

const Header = styled("div")({
display: "flex",
Expand All @@ -15,7 +15,7 @@ const Header = styled("div")({
rowGap: "8px",
})

const _DataLayout: IDataLayoutWithoutSubcomponents = ({ children }) => {
const _DataLayout: TDataLayoutWithoutSubcomponents = ({ children }) => {
const table = getChildByDisplayName({ children, displayName: "DataLayoutTableContainer" })
const controls = getChildByDisplayName({ children, displayName: "DataLayoutControls" })
const heading = getChildByDisplayName({ children, displayName: "DataLayoutHeading" })
Expand All @@ -35,6 +35,6 @@ _DataLayout.Controls = DataLayoutControls
_DataLayout.Heading = DataLayoutHeading
_DataLayout.TableContainer = DataLayoutTableContainer

const DataLayout = _DataLayout as IDataLayoutWithSubcomponents
const DataLayout = _DataLayout as TDataLayoutWithSubcomponents

export { DataLayout }
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { TableContainer } from "@mui/material"
import { FC, PropsWithChildren, createContext } from "react"

interface IDataLayoutTableContainerContext {
type TDataLayoutTableContainerContext = {
columnsAmount: number
}
export const DateLayoutTableContainerContext = createContext<IDataLayoutTableContainerContext>({
export const DateLayoutTableContainerContext = createContext<TDataLayoutTableContainerContext>({
columnsAmount: 0,
})

interface IDataLayoutTableProps {
type TDataLayoutTableProps = {
columnsWidths: string[]
}

const DataLayoutTableContainer: FC<PropsWithChildren<IDataLayoutTableProps>> = ({ children, columnsWidths }) => {
const DataLayoutTableContainer: FC<PropsWithChildren<TDataLayoutTableProps>> = ({ children, columnsWidths }) => {
const columnWidthByCellSelector: Record<string, { width: string }> = {}
columnsWidths.forEach((columnWidth, columnWidthIndex) => {
columnWidthByCellSelector[`& td:nth-of-type(${columnWidthIndex + 1})`] = { width: columnWidth }
Expand Down
7 changes: 3 additions & 4 deletions src/components/DataLayout/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { DataLayoutControls } from "./subcomponents/DataLayoutControls"
import { DataLayoutHeading } from "./subcomponents/DataLayoutHeading"
import { DataLayoutTableContainer } from "./subcomponents/DataLayoutTableContainer"

export interface IDataLayoutProps {}
type IDataLayoutComponent = FC<PropsWithChildren<IDataLayoutProps>>
type TDataLayoutComponent = FC<PropsWithChildren>

export interface IDataLayoutWithoutSubcomponents extends IDataLayoutComponent {
export type TDataLayoutWithoutSubcomponents = TDataLayoutComponent & {
Controls?: typeof DataLayoutControls
Heading?: typeof DataLayoutHeading
TableContainer?: typeof DataLayoutTableContainer
}

export interface IDataLayoutWithSubcomponents extends IDataLayoutComponent {
export type TDataLayoutWithSubcomponents = TDataLayoutComponent & {
Controls: typeof DataLayoutControls
Heading: typeof DataLayoutHeading
TableContainer: typeof DataLayoutTableContainer
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getChildByDisplayName } from "#utils/getChildByDisplayName"
import { DialogBody } from "./subcomponents/DialogBody"
import { DialogFooter } from "./subcomponents/DialogFooter"
import { DialogHeader } from "./subcomponents/DialogHeader"
import { IDialogWithSubcomponents, IDialogWithoutSubcomponents } from "./types"
import { TDialogWithSubcomponents, TDialogWithoutSubcomponents } from "./types"

const DialogWindow = styled("div")(({ theme }) => ({
backgroundColor: theme.palette.background.default,
Expand All @@ -31,7 +31,7 @@ const HeaderWithCloseButton = styled("div")({
gridTemplateColumns: "auto min-content",
})

const _Dialog: IDialogWithoutSubcomponents = ({ children, closeDialog, closeDialogHref }) => {
const _Dialog: TDialogWithoutSubcomponents = ({ children, closeDialog, closeDialogHref }) => {
const navigate = useNavigate()

const header = getChildByDisplayName({ children, displayName: "DialogHeader" })
Expand Down Expand Up @@ -84,6 +84,6 @@ _Dialog.Body = DialogBody
_Dialog.Footer = DialogFooter
_Dialog.Header = DialogHeader

const Dialog = _Dialog as IDialogWithSubcomponents
const Dialog = _Dialog as TDialogWithSubcomponents

export { Dialog }
8 changes: 4 additions & 4 deletions src/components/Dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { DialogBody } from "./subcomponents/DialogBody"
import { DialogFooter } from "./subcomponents/DialogFooter"
import { DialogHeader } from "./subcomponents/DialogHeader"

export interface IDialogProps {
export type TDialogProps = {
closeDialog?: () => void
closeDialogHref?: string
}
type IDialogComponent = FC<PropsWithChildren<IDialogProps>>
type TDialogComponent = FC<PropsWithChildren<TDialogProps>>

export interface IDialogWithoutSubcomponents extends IDialogComponent {
export type TDialogWithoutSubcomponents = TDialogComponent & {
Header?: typeof DialogHeader
Body?: typeof DialogBody
Footer?: typeof DialogFooter
}

export interface IDialogWithSubcomponents extends IDialogComponent {
export type TDialogWithSubcomponents = TDialogComponent & {
Header: typeof DialogHeader
Body: typeof DialogBody
Footer: typeof DialogFooter
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Dashboard as DashboardIcon, Person as PersonIcon } from "@mui/icons-material"

interface ISection {
type TSection = {
icon: React.ReactElement
id: string
path: string
}

export const section: ISection[] = [
export const section: TSection[] = [
{ icon: <DashboardIcon />, id: "boards", path: "/boards" },
{ icon: <PersonIcon />, id: "auth", path: "/auth" },
]
Expand Down
11 changes: 6 additions & 5 deletions src/components/form-contructor/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import {
RadioGroup as MuiRadioGroup,
Radio,
} from "@mui/material"
import { FC } from "react"
import { UseFormRegister } from "react-hook-form"

interface IRadioGroupOption {
type TRadioGroupOption = {
label: string
value: number | string
}
interface IRadioGroupProps {
fieldValue: IRadioGroupOption["value"]
type TRadioGroupProps = {
fieldValue: TRadioGroupOption["value"]
helperText: string | undefined
label: string
name: string
options: IRadioGroupOption[]
options: TRadioGroupOption[]
register: UseFormRegister<any> // eslint-disable-line @typescript-eslint/no-explicit-any
setValue(fieldName: string, newValue: string | number): void
}

export const RadioGroup: React.FC<IRadioGroupProps> = ({
export const RadioGroup: FC<TRadioGroupProps> = ({
fieldValue,
helperText,
label,
Expand Down
4 changes: 2 additions & 2 deletions src/views/auth/Login/form-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const validationSchema = yup
})
.required()

export const defaultValues: FormValues = {
export const defaultValues: TFormValues = {
password: "",
username: "",
}

export type FormValues = yup.InferType<typeof validationSchema>
export type TFormValues = yup.InferType<typeof validationSchema>
4 changes: 2 additions & 2 deletions src/views/auth/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RowGroup } from "#components/RowGroup"
import { apolloClient } from "#utils/apolloClient"

import { Container } from "../components"
import { FieldName, FormValues, defaultValues, validationSchema } from "./form-helpers"
import { FieldName, TFormValues, defaultValues, validationSchema } from "./form-helpers"

export const Login: FC = () => {
const navigate = useNavigate()
Expand All @@ -21,7 +21,7 @@ export const Login: FC = () => {
handleSubmit,
register,
setError,
} = useForm<FormValues>({
} = useForm<TFormValues>({
defaultValues,
mode: "onChange",
resolver: yupResolver(validationSchema),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum FieldName {
Date = "date",
}

export interface IFormValues {
export type TFormValues = {
[FieldName.Amount]: BudgetRecord["amount"] | null
[FieldName.CategoryId]: BudgetRecord["category"]["id"] | null
[FieldName.Comment]: BudgetRecord["comment"]
Expand Down

0 comments on commit 973bf2b

Please sign in to comment.