Browse Source

Maintenance: Mobile - Add eslint rule for Enum names

Vladimir Sheremet 2 years ago
parent
commit
7920b5315c

+ 12 - 0
.eslintrc.js

@@ -84,6 +84,18 @@ module.exports = {
 
     '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
 
+    '@typescript-eslint/naming-convention': [
+      'error',
+      {
+        selector: 'enumMember',
+        format: ['StrictPascalCase'],
+      },
+      {
+        selector: 'typeLike',
+        format: ['PascalCase'],
+      },
+    ],
+
     'vue/component-tags-order': [
       'error',
       {

+ 4 - 4
app/frontend/apps/mobile/components/transition/TransitionViewNavigation/TransitionViewNavigation.stories.ts

@@ -44,7 +44,7 @@ const Template: Story<Args> = (args: Args) => ({
     }
 
     const resetView = () => {
-      setViewTransition(ViewTransitions.REPLACE)
+      setViewTransition(ViewTransitions.Replace)
       component.value = FirstView
     }
 
@@ -57,10 +57,10 @@ const Template: Story<Args> = (args: Args) => ({
 })
 
 export const NextViewTransition = Template.bind({})
-NextViewTransition.args = { newViewTransition: ViewTransitions.NEXT }
+NextViewTransition.args = { newViewTransition: ViewTransitions.Next }
 
 export const PrevViewTransition = Template.bind({})
-PrevViewTransition.args = { newViewTransition: ViewTransitions.PREV }
+PrevViewTransition.args = { newViewTransition: ViewTransitions.Prev }
 
 export const ReplaceViewTransition = Template.bind({})
-ReplaceViewTransition.args = { newViewTransition: ViewTransitions.REPLACE }
+ReplaceViewTransition.args = { newViewTransition: ViewTransitions.Replace }

+ 1 - 1
app/frontend/apps/mobile/components/transition/TransitionViewNavigation/composable.ts

@@ -3,7 +3,7 @@
 import { ref } from 'vue'
 import { ViewTransitions } from './types'
 
-const viewTransition = ref<ViewTransitions>(ViewTransitions.REPLACE)
+const viewTransition = ref<ViewTransitions>(ViewTransitions.Replace)
 
 export const useViewTransition = () => {
   const setViewTransition = (newViewTransition: ViewTransitions) => {

+ 3 - 3
app/frontend/apps/mobile/components/transition/TransitionViewNavigation/types.ts

@@ -1,7 +1,7 @@
 // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
 
 export enum ViewTransitions {
-  NEXT = 'next',
-  PREV = 'prev',
-  REPLACE = 'replace',
+  Next = 'next',
+  Prev = 'prev',
+  Replace = 'replace',
 }

+ 2 - 2
app/frontend/apps/mobile/modules/login/views/Login.vue

@@ -27,7 +27,7 @@ if (props.invalidatedSession === '1') {
 
   notify({
     message: __('The session is no longer valid. Please log in again.'),
-    type: NotificationTypes.WARN,
+    type: NotificationTypes.Warn,
   })
 }
 
@@ -106,7 +106,7 @@ const login = (formData: FormData<LoginFormData>) => {
       const { notify } = useNotifications()
       notify({
         message: errors.generalErrors[0],
-        type: NotificationTypes.ERROR,
+        type: NotificationTypes.Error,
       })
     })
 }

+ 2 - 2
app/frontend/apps/mobile/modules/ticket/views/TicketOverview.vue

@@ -15,14 +15,14 @@ const router = useRouter()
 
 const goTo = () => {
   const { setViewTransition } = useViewTransition()
-  setViewTransition(ViewTransitions.REPLACE)
+  setViewTransition(ViewTransitions.Replace)
 
   router.replace('/')
 }
 
 const goBack = () => {
   const { setViewTransition } = useViewTransition()
-  setViewTransition(ViewTransitions.PREV)
+  setViewTransition(ViewTransitions.Prev)
 
   router.go(-1)
 }

+ 3 - 3
app/frontend/apps/mobile/router/guards/before/viewTransition.ts

@@ -19,7 +19,7 @@ const transitionViewGuard: NavigationGuard = (
   // until the following feature was added: https://github.com/vuejs/vue-router/issues/3453.
   const { setViewTransition } = useViewTransition()
 
-  let newViewTransition: ViewTransitions = ViewTransitions.REPLACE
+  let newViewTransition: ViewTransitions = ViewTransitions.Replace
 
   // In the case that the 'To'-Route has no level, we use the replace transition.
   if (to.meta?.level) {
@@ -28,8 +28,8 @@ const transitionViewGuard: NavigationGuard = (
     if (previousLevel !== to.meta.level) {
       newViewTransition =
         previousLevel < to.meta.level
-          ? ViewTransitions.NEXT
-          : ViewTransitions.PREV
+          ? ViewTransitions.Next
+          : ViewTransitions.Prev
     }
   }
 

+ 9 - 9
app/frontend/shared/components/CommonNotifications/CommonNotifications.stories.ts

@@ -17,10 +17,10 @@ export default {
     type: {
       control: { type: 'select' },
       options: [
-        NotificationTypes.ERROR,
-        NotificationTypes.WARN,
-        NotificationTypes.SUCCESS,
-        NotificationTypes.INFO,
+        NotificationTypes.Error,
+        NotificationTypes.Warn,
+        NotificationTypes.Success,
+        NotificationTypes.Info,
       ],
     },
   },
@@ -51,20 +51,20 @@ const Template: Story<Notification> = (args: Notification) => ({
 })
 
 export const WarnNotification = Template.bind({})
-WarnNotification.args = { type: NotificationTypes.WARN }
+WarnNotification.args = { type: NotificationTypes.Warn }
 
 export const ErrorNotification = Template.bind({})
-ErrorNotification.args = { type: NotificationTypes.ERROR }
+ErrorNotification.args = { type: NotificationTypes.Error }
 
 export const SuccessNotification = Template.bind({})
-SuccessNotification.args = { type: NotificationTypes.SUCCESS }
+SuccessNotification.args = { type: NotificationTypes.Success }
 
 export const InfoNotification = Template.bind({})
-InfoNotification.args = { type: NotificationTypes.INFO }
+InfoNotification.args = { type: NotificationTypes.Info }
 
 export const CallbackNotification = Template.bind({})
 CallbackNotification.args = {
-  type: NotificationTypes.INFO,
+  type: NotificationTypes.Info,
   persistent: true,
   callback: () => {
     // eslint-disable-next-line no-alert

+ 11 - 11
app/frontend/shared/components/CommonNotifications/__tests__/CommonNotifications.spec.ts

@@ -25,7 +25,7 @@ describe('CommonNotifications.vue', () => {
     const { notify } = useNotifications()
     await notify({
       message,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     expect(wrapper.getByTestId('notification')).toBeInTheDocument()
@@ -37,7 +37,7 @@ describe('CommonNotifications.vue', () => {
 
     await notify({
       message,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
       durationMS: 10,
     })
 
@@ -51,7 +51,7 @@ describe('CommonNotifications.vue', () => {
 
     await notify({
       message,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
       durationMS: 10,
       persistent: true,
     })
@@ -70,7 +70,7 @@ describe('CommonNotifications.vue', () => {
 
     await notify({
       message,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
       callback: () => {
         expect(test).toBe(false)
         test = true
@@ -85,17 +85,17 @@ describe('CommonNotifications.vue', () => {
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     expect(wrapper.getAllByTestId('notification')).toHaveLength(3)
@@ -106,17 +106,17 @@ describe('CommonNotifications.vue', () => {
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     await notify({
       message: `${message} - ${notifications.value.length}`,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     clearAllNotifications()
@@ -129,7 +129,7 @@ describe('CommonNotifications.vue', () => {
     const { notify } = useNotifications()
     await notify({
       message,
-      type: NotificationTypes.WARN,
+      type: NotificationTypes.Warn,
     })
 
     expect(wrapper.getIconByName('info')).toBeInTheDocument()

+ 1 - 1
app/frontend/shared/components/CommonNotifications/composable.ts

@@ -39,7 +39,7 @@ const useNotifications = () => {
 
   const hasErrors = () => {
     return notifications.value.some((notification) => {
-      return notification.type === NotificationTypes.ERROR
+      return notification.type === NotificationTypes.Error
     })
   }
 

Some files were not shown because too many files changed in this diff