Skip to content

Commit

Permalink
chore(eslint-config): activate 'vue/require-explicit-emits' rule
Browse files Browse the repository at this point in the history
Co-Authored-By: Florian Wendelborn <[email protected]>
  • Loading branch information
Isokaeder and FlorianWendelborn committed May 31, 2024
1 parent e6924cf commit 2ed14f3
Show file tree
Hide file tree
Showing 63 changed files with 105 additions and 5 deletions.
8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ const config = tseslint.config(
* @see {@link https://eslint.org/docs/latest/use/configure/ignore#ignoring-files}
*/
{
ignores: ['**/dist/**', '**/.nuxt/**', '**/.turbo/**', '**/*.js'],
ignores: [
'**/dist/**',
'**/.nuxt/**',
'**/.turbo/**',
'**/*.js',
'**/vite.config.ts.timestamp-*', // used by vite to interpret vite.config.ts
],
},
...eslintConfig3YD.configs.global,
{
Expand Down
21 changes: 20 additions & 1 deletion packages/documentation/components/ComponentInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,27 @@
</tbody>
</table>
</KtHeading>

<KtHeading
v-if="component.emits && component.emits.length > 0"
text="Emits"
:toggleStatus="showEmits"
toggleCloseText="Hide"
toggleText="Show"
type="toggle"
@toggle="showEmits = !showEmits"
>
<div style="display: flex; flex-wrap: wrap; gap: 4px">
<template v-for="emit in component.emits">
<code :key="emit" v-text="`@${emit}`" />
</template>
</div>
</KtHeading>
</div>
</template>

<script lang="ts">
import { Kotti } from '@3yourmind/kotti-ui'
import { KtHeading, Kotti } from '@3yourmind/kotti-ui'
import { Yoco } from '@3yourmind/yoco'
import { Dashes } from '@metatypes/typography'
import castArray from 'lodash/castArray'
Expand All @@ -150,11 +166,13 @@ export default defineComponent({
name: 'ComponentInfo',
components: {
ComponentInfoSlots,
KtHeading,
},
props: {
component: {
required: true,
type: Object as PropType<{
emits?: string[]
meta: Kotti.Meta
name: string
props?: Record<string, unknown>
Expand Down Expand Up @@ -266,6 +284,7 @@ export default defineComponent({
return result
}),
showEmits: ref(false),
showProps: ref(false),
stringifyPropDefault: (
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export default {
'vue/no-useless-v-bind': 'warn',
'vue/require-component-is': 'error',
'vue/require-default-prop': 'off', // disabled because it doesn’t handle boolean props correctly
'vue/require-explicit-emits': 'error',
},
}),
},
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-accordion/KtAccordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ANIMATION_DURATION = 300
export default defineComponent({
name: 'KtAccordion',
props: makeProps(KottiAccordion.propsSchema),
emits: ['update:isClosed'],
setup(props, { emit }) {
const contentInnerRef = ref<HTMLElement | null>(null)
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-avatar/KtAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { KottiAvatar } from './types'
export default defineComponent({
name: 'KtAvatar',
props: makeProps(KottiAvatar.propsSchema),
emits: ['click'],
setup(props, { emit, slots }) {
const avatarFallback = ref(true)
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-banner/KtBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default defineComponent({
KtButton,
},
props: makeProps(KottiBanner.propsSchema),
emits: ['click'],
setup(props, { slots }) {
const translations = useTranslationNamespace('KtBanner')
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-button/KtButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { KottiButton } from './types'
export default defineComponent({
name: 'KtButton',
props: makeProps(KottiButton.propsSchema),
emits: ['click', 'update:toggleStatus'],
setup(props, { emit, slots }) {
const helpTextContentRef = ref<Element | null>(null)
const helpTextTriggerRef = ref<Element | null>(null)
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-button/KtSplitButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default defineComponent({
ActionsItem,
},
props: makeProps(KottiSplitButton.propsSchema),
emits: ['click'],
setup(props, { emit }) {
const { isTippyOpen, setIsTippyOpen, tippyContentRef, tippyTriggerRef } =
useActionsTippy({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const propsSchema = KottiSplitButton.actionSchema.extend({
export default defineComponent({
name: 'SplitButtonActionsItem',
props: makeProps(propsSchema),
emits: ['click', 'updateIndexInFocus'],
setup(props, { emit }) {
const itemRef = ref<HTMLButtonElement | null>(null)
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-card/KtCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineComponent({
name: 'KtCard',
components: { KtButton },
props: makeProps(KottiCard.propsSchema),
emits: ['click', 'clickOnPrimaryButton', 'clickOnSecondaryButton'],
setup(props, { emit }) {
const hasActions = computed(
() =>
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-comment/KtComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default defineComponent({
KtCommentInput,
},
props: makeProps(KottiComment.propsSchema),
emits: ['add', 'delete', 'edit'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtComment')
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-comment/KtCommentInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default defineComponent({
CommentTextArea,
},
props: makeProps(KottiCommentInput.propsSchema),
emits: ['add', 'cancel'],
setup(props, { emit }) {
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
const localIsInternal = ref<KottiComment.PropsInternal['isInternal']>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { KottiComment } from '../types'
export default defineComponent({
name: 'CommentActions',
props: makeProps(KottiComment.Actions.schema),
emits: ['delete', 'reply', 'update:isEditing'],
setup(_, { emit }) {
const translations = useTranslationNamespace('KtComment')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineComponent({
CommentInlineEdit,
},
props: makeProps(KottiComment.Entry.schema),
emits: ['delete', 'edit', 'reply'],
setup(props, { emit }) {
const isEditing = ref(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineComponent({
CommentTextArea,
},
props: makeProps(KottiComment.InlineEdit.schema),
emits: ['edit', 'update:isEditing'],
setup(props, { emit }) {
const localMessage =
ref<KottiComment.InlineEdit.PropsInternal['message']>('')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { KottiComment } from '../types'
export default defineComponent({
name: 'CommentTextArea',
props: makeProps(KottiComment.TextArea.schema),
emits: ['cancel', 'confirm', 'input', 'toggleInternal'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtComment')
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-drawer/KtDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { KottiDrawer } from './types'
export default defineComponent({
name: 'KtDrawer',
props: makeProps(KottiDrawer.propsSchema),
emits: ['close'],
setup(props, { emit }) {
const isExpanded = ref(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default defineComponent({
TakePhoto,
},
props: makeProps(KottiFieldFileUploadRemote.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldFileUploadRemote.ValueInternal>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Shared } from '../types'
export default defineComponent({
name: 'ActionButton',
props: makeProps(Shared.ActionButton.schema),
emits: ['click'],
setup(props) {
return {
classes: computed(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { isSelectingMultipleFilesWhenNotAllowed } from '../validators'
export default defineComponent({
name: 'DropArea',
props: makeProps(Shared.DropArea.schema),
emits: ['addFiles'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default defineComponent({
ItemLayout,
},
props: makeProps(KottiFieldFileUpload.FileItem.schema),
emits: ['remove'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default defineComponent({
ItemLayout,
},
props: makeProps(KottiFieldFileUpload.FileItem.schema),
emits: ['remove'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum State {
export default defineComponent({
name: 'CapturePhoto',
props: makeProps(Shared.TakePhoto.captureSchema),
emits: ['capture', 'close', 'error'],
setup(_, { emit }) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Shared } from '../../types'
export default defineComponent({
name: 'ErrorViewer',
props: makeProps(Shared.TakePhoto.errorSchema),
emits: ['close', 'retry'],
setup(props) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { Shared } from '../../types'
export default defineComponent({
name: 'ReviewPhoto',
props: makeProps(Shared.TakePhoto.reviewSchema),
emits: ['accept', 'close', 'reject'],
setup() {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default defineComponent({
ReviewPhoto,
},
props: makeProps(Shared.TakePhoto.schema),
emits: ['addFiles'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtFieldFileUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default defineComponent({
EditIcon,
},
props: makeProps(KottiFieldInlineEdit.propsSchema),
emits: ['confirm', 'input'],
setup(props, { emit }) {
const { forceUpdate, forceUpdateKey } = useForceUpdate()
const translations = useTranslationNamespace('KtFieldInlineEdit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineComponent({
tabIndex: { type: Number, default: 0 },
dataTest: { type: String, default: null },
},
emits: ['confirm'],
setup(props, { emit }) {
return {
buttonProps: computed(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default defineComponent({
KtField,
},
props: makeProps(KottiFieldNumber.propsSchema),
emits: ['blur', 'input'],
setup(props, { emit }) {
const field = useField<KottiFieldNumber.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineComponent({
name: 'KtFieldPassword',
components: { KtField },
props: makeProps(KottiFieldPassword.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldPassword.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default defineComponent({
KtField,
},
props: makeProps(KottiFieldRadioGroup.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldRadioGroup.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default defineComponent({
isDropdownOpen: { required: true, type: Boolean },
showClear: { required: true, type: Boolean },
},
emits: ['update:isDropdownOpen'],
setup(props, { emit }) {
return {
containerClasses: computed(() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default defineComponent({
KtTag,
},
props: makeProps(propsSchema),
emits: ['emit', 'input'],
setup(props, { emit: rawEmit }) {
const emit = (event: string, payload: unknown) => {
rawEmit('emit', { event, payload })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default defineComponent({
FieldSelectOptionsItem,
},
props: makeProps(propsSchema),
emits: ['close', 'input'],
setup(props, { emit }) {
const translations = useTranslationNamespace('KtFieldSelects')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const propsSchema = z.object({
export default defineComponent({
name: 'FieldSelectOptionsItem',
props: makeProps(propsSchema),
emits: ['click', 'scrollTo'],
setup(props, { emit }) {
const optionRef = ref<HTMLDivElement | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default defineComponent({
KtField,
},
props: makeProps(KottiFieldTextArea.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldTextArea.Value>({
emit,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-text/KtFieldText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineComponent({
KtField,
},
props: makeProps(KottiFieldText.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldText.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default defineComponent({
ToggleInner,
},
props: makeProps(KottiFieldToggle.propsSchema),
emits: ['input'],
setup(props, { emit, slots }) {
const field = useField<KottiFieldToggle.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineComponent({
ToggleInner,
},
props: makeProps(KottiFieldToggleGroup.propsSchema),
emits: ['input'],
setup(props, { emit }) {
const field = useField<KottiFieldToggleGroup.Value>({
emit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineComponent({
type: { default: 'checkbox', type: String },
value: { default: null, type: Boolean as PropType<boolean | null> },
},
emits: ['input'],
setup(props, { emit }) {
return {
onInput: (event: Event) => {
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field/KtField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default defineComponent({
isRange: { default: false, type: Boolean },
useFieldset: { default: false, type: Boolean },
},
emits: ['click', 'mousedown'],
setup(props) {
const inputId = computed(() =>
props.isRange
Expand Down
4 changes: 2 additions & 2 deletions packages/kotti-ui/source/kotti-field/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { yocoIconSchema } from '@3yourmind/yoco'
import type { Ref, SetupContext } from 'vue'
import type { Ref } from 'vue'
import { z } from 'zod'

import type { ReplaceRecordType } from '../types/utilities'
Expand Down Expand Up @@ -55,7 +55,7 @@ export module KottiField {

export module Hook {
export interface Parameters<DATA_TYPE> {
emit: SetupContext['emit']
emit: (name: 'input', ...args: unknown[]) => void

/**
* Useful for checking validation on required fields
Expand Down
Loading

0 comments on commit 2ed14f3

Please sign in to comment.