Skip to content

Commit

Permalink
fix: Обновление конфигурации ESLint (#204)
Browse files Browse the repository at this point in the history
### 📝 Описание изменений
Обновление `@exer7um/eslint-config` до последней версии и исправление
ошибок.
  • Loading branch information
ExEr7um committed Jul 28, 2024
1 parent 20f2a17 commit 17d55ec
Show file tree
Hide file tree
Showing 22 changed files with 497 additions and 192 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

4 changes: 1 addition & 3 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import DefaultTheme from "vitepress/theme"

import "./theme.css"

export default DefaultTheme
export { default } from "vitepress/theme"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"ohash": "^1.1.3"
},
"devDependencies": {
"@exer7um/eslint-config": "1.1.4",
"@exer7um/eslint-config": "1.3.1",
"@exer7um/prettier-config": "0.4.3",
"@nuxt/eslint-config": "0.3.13",
"@nuxt/module-builder": "0.8.1",
Expand Down
593 changes: 444 additions & 149 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/runtime/components/UtilsMapWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mapURL.searchParams.append("z", "16")
class="map-widget"
height="100%"
:src="mapURL.href"
title="map"
width="100%"
></iframe>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/useFetchAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default async function <TResponse>(
headers: {
// Токен авторизации из .env
Authorization: useRuntimeConfig().public.authToken as string,
// Выставляем `csrftoken` из `cookie` в заголовок
"X-CSRFToken": useCookie("csrftoken").value ?? "",
// Проксим `cookie` клиента на сервер
cookie: useRequestHeaders(["cookie"]).cookie ?? "",
// Выставляем `csrftoken` из `cookie` в заголовок
"X-CSRFToken": useCookie("csrftoken").value ?? "",
},
}

Expand Down
4 changes: 1 addition & 3 deletions src/runtime/composables/useHighlightedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export default function (text: string, query: string) {
const regex = new RegExp(`(${query})`, "gi")

/** Строка с добавленными тегами `<mark>` */
const result = text.replace(regex, (match) =>
return text.replace(regex, (match) =>
match ? "<mark>" + match + "</mark>" : match
)

return result
}
6 changes: 2 additions & 4 deletions src/runtime/composables/usePhoneFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* usePhoneFormatter('+79998887766')
* ```
*/
export default function (phone: string): null | string {
export default function (phone: string) {
/** Номер, очищенный от символов, не являющихся цифрами */
const cleaned = ("" + phone).replace(/\D/g, "")
const cleaned = ("" + phone).replaceAll(/\D/g, "")

/**
* Номер, разбитый на части
Expand All @@ -28,6 +28,4 @@ export default function (phone: string): null | string {
const countryCode = match[1] ? "+7" : ""
return `${countryCode}\u00A0${match[2]}\u00A0${match[3]}-${match[4]}-${match[5]}`
}

return null
}
4 changes: 1 addition & 3 deletions src/runtime/composables/usePriceFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
*/
export default function (price: number): string {
/** Форматированная цена */
const formattedPrice = price.toLocaleString("ru-RU", {
return price.toLocaleString("ru-RU", {
currency: "RUB",
minimumFractionDigits: 0,
style: "currency",
})

return formattedPrice
}
5 changes: 4 additions & 1 deletion tests/components/UtilsDate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import UtilsDate from "@/runtime/components/UtilsDate.vue"
import { mount } from "@vue/test-utils"
import VueDatePicker from "@vuepic/vue-datepicker"
import { describe, expect, test } from "vitest"

import UtilsDate from "~/src/runtime/components/UtilsDate.vue"

describe("Компонент UtilsDate", () => {
test("Рендер", () => {
/** Компонент */
Expand Down Expand Up @@ -187,6 +188,7 @@ describe("Компонент UtilsDate", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -213,6 +215,7 @@ describe("Компонент UtilsDate", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
5 changes: 4 additions & 1 deletion tests/components/UtilsInput.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsInput from "@/runtime/components/UtilsInput.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsInput from "~/src/runtime/components/UtilsInput.vue"

describe("Компонент UtilsInput", () => {
const defaultProps = {
id: "test-field",
Expand Down Expand Up @@ -253,6 +254,7 @@ describe("Компонент UtilsInput", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -276,6 +278,7 @@ describe("Компонент UtilsInput", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
13 changes: 8 additions & 5 deletions tests/components/UtilsInputMasked.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsInputMasked from "@/runtime/components/UtilsInputMasked.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsInputMasked from "~/src/runtime/components/UtilsInputMasked.vue"

describe("Компонент UtilsInputMasked", () => {
const defaultProps = {
id: "test-field",
Expand Down Expand Up @@ -130,7 +131,7 @@ describe("Компонент UtilsInputMasked", () => {
/** Компонент */
const wrapper = mount(UtilsInputMasked, {
props: {
pattern: "\\+\\d \\d{3} \\d{3}-\\d{2}-\\d{2}",
pattern: String.raw`\+\d \d{3} \d{3}-\d{2}-\d{2}`,
...defaultProps,
},
})
Expand All @@ -140,7 +141,7 @@ describe("Компонент UtilsInputMasked", () => {

// Проверка атрибута `pattern`
expect(input.attributes("pattern")).toBe(
"\\+\\d \\d{3} \\d{3}-\\d{2}-\\d{2}"
String.raw`\+\d \d{3} \d{3}-\d{2}-\d{2}`
)
})

Expand Down Expand Up @@ -211,7 +212,7 @@ describe("Компонент UtilsInputMasked", () => {
/** Компонент */
const wrapper = mount(UtilsInputMasked, {
props: {
type: "password",
type: "number",
...defaultProps,
},
})
Expand All @@ -220,7 +221,7 @@ describe("Компонент UtilsInputMasked", () => {
const input = wrapper.find("input")

// Проверка значения атрибута `type`.
expect(input.attributes("type")).toBe("password")
expect(input.attributes("type")).toBe("number")
})

test("Работа `v-maska`", async () => {
Expand Down Expand Up @@ -288,6 +289,7 @@ describe("Компонент UtilsInputMasked", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -311,6 +313,7 @@ describe("Компонент UtilsInputMasked", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
3 changes: 2 additions & 1 deletion tests/components/UtilsMapWidget.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsMapWidget from "@/runtime/components/UtilsMapWidget.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsMapWidget from "~/src/runtime/components/UtilsMapWidget.vue"

describe.sequential("Компонент UtilsMapWidget", () => {
/** `ID` виджета */
const widgetId = "widget-id"
Expand Down
5 changes: 4 additions & 1 deletion tests/components/UtilsPassword.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsPassword from "@/runtime/components/UtilsPassword.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsPassword from "~/src/runtime/components/UtilsPassword.vue"

describe.sequential("Компонент UtilsPassword", () => {
const defaultProps = {
id: "test-field",
Expand Down Expand Up @@ -329,6 +330,7 @@ describe.sequential("Компонент UtilsPassword", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -352,6 +354,7 @@ describe.sequential("Компонент UtilsPassword", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
7 changes: 5 additions & 2 deletions tests/components/UtilsPhone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsPhone from "@/runtime/components/UtilsPhone.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsPhone from "~/src/runtime/components/UtilsPhone.vue"

describe("Компонент UtilsPhone", () => {
test("Рендер", () => {
/** Компонент */
Expand Down Expand Up @@ -54,7 +55,7 @@ describe("Компонент UtilsPhone", () => {
expect(input.attributes("maxlength")).toBe("16")
// Проверка атрибута `pattern`
expect(input.attributes("pattern")).toBe(
"\\+\\d \\d{3} \\d{3}-\\d{2}-\\d{2}"
String.raw`\+\d \d{3} \d{3}-\d{2}-\d{2}`
)
// Проверка атрибута `placeholder`
expect(input.attributes("placeholder")).toBe("+7 999 888-77-66")
Expand Down Expand Up @@ -201,6 +202,7 @@ describe("Компонент UtilsPhone", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -224,6 +226,7 @@ describe("Компонент UtilsPhone", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
5 changes: 4 additions & 1 deletion tests/components/UtilsTextArea.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UtilsTextArea from "@/runtime/components/UtilsTextArea.vue"
import { mount } from "@vue/test-utils"
import { describe, expect, test } from "vitest"

import UtilsTextArea from "~/src/runtime/components/UtilsTextArea.vue"

describe("Компонент UtilsTextArea", () => {
const defaultProps = {
id: "test-field",
Expand Down Expand Up @@ -233,6 +234,7 @@ describe("Компонент UtilsTextArea", () => {
const form = event.target as HTMLFormElement

/** Объект со всеми данными формы */
// @ts-expect-error - неправильная автоматическая типизация
this.formData = new FormData(form)
},
},
Expand All @@ -256,6 +258,7 @@ describe("Компонент UtilsTextArea", () => {
await form.trigger("submit")

/** Данные формы */
// @ts-expect-error - неправильная автоматическая типизация
const formData = Object.fromEntries(parentComponent.vm.formData.entries())

// Проверяем, что правильно выставлены все данные
Expand Down
3 changes: 2 additions & 1 deletion tests/composables/useHighlightedText.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useHighlightedText from "@/runtime/composables/useHighlightedText"
import { describe, expect, test } from "vitest"

import useHighlightedText from "~/src/runtime/composables/useHighlightedText"

describe("Функция useHighlightedText", () => {
test("Возвращает текст с выделением", () => {
/** Текст */
Expand Down
7 changes: 4 additions & 3 deletions tests/composables/usePhoneFormatter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import usePhoneFormatter from "@/runtime/composables/usePhoneFormatter"
import { describe, expect, test } from "vitest"

import usePhoneFormatter from "~/src/runtime/composables/usePhoneFormatter"

describe("Функция usePhoneFormatter", () => {
test("Возвращает правильный формат номера", () => {
/** Отформатированный номер */
Expand All @@ -16,10 +17,10 @@ describe("Функция usePhoneFormatter", () => {
expect(formattedNumber).toBe("+7 999 888-77-66")
})

test("При вводе некорректного номера возвращает `null`", () => {
test("При вводе некорректного номера возвращает `undefined`", () => {
/** Отформатированный номер */
const formattedNumber = usePhoneFormatter("1234")

expect(formattedNumber).toBeNull()
expect(formattedNumber).toBeUndefined()
})
})
7 changes: 4 additions & 3 deletions tests/composables/usePriceFormatter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import usePriceFormatter from "@/runtime/composables/usePriceFormatter"
import { describe, expect, test } from "vitest"

import usePriceFormatter from "~/src/runtime/composables/usePriceFormatter"

describe("Функция usePriceFormatter", () => {
test("Возвращает правильный формат цены", () => {
/** Отформатированная цена */
const formattedPrice = usePriceFormatter(1234567)
const formattedPrice = usePriceFormatter(1_234_567)

expect(formattedPrice).toBe("1 234 567 ₽")
})

test("Возвращает правильный формат цены с дробной частью", () => {
/** Отформатированная цена */
const formattedPrice = usePriceFormatter(1234567.89)
const formattedPrice = usePriceFormatter(1_234_567.89)

expect(formattedPrice).toBe("1 234 567,89 ₽")
})
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/basic/app.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<script setup lang="ts"></script>

<template>
<div>basic</div>
</template>
2 changes: 1 addition & 1 deletion tests/fixtures/basic/server/routes/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Sitemap } from "@/src/runtime/api/sitemap-routes"
import type { Sitemap } from "~/src/runtime/api/sitemap-routes"

export default defineEventHandler(() => {
/** Тестовая карта сайта */
Expand Down
4 changes: 2 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Vue from "@vitejs/plugin-vue"
import path from "path"
import { fileURLToPath } from "node:url"
import { defineConfig } from "vitest/config"

export default defineConfig({
plugins: [Vue()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"~": fileURLToPath(new URL("./", import.meta.url)),
},
},
test: {
Expand Down

0 comments on commit 17d55ec

Please sign in to comment.