Skip to content

Commit

Permalink
chore: Enable ESLint for apps and fix all errors
Browse files Browse the repository at this point in the history
Nevertheless this causes a huge amount of new warnings.
Previously the shell script for directories to lint was wrong it was generating all app names to lint,
but was missing the `apps/` prefix. Causing only `core` to be linted.

Co-authored-by: Grigorii K. Shartsev <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux and ShGKme committed Jul 1, 2024
1 parent beececf commit df92bea
Show file tree
Hide file tree
Showing 83 changed files with 315 additions and 232 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ module.exports = {
mode: 'typescript',
},
},
overrides: [
// Allow any in tests
{
files: ['**/*.spec.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
},
}
],
}
12 changes: 6 additions & 6 deletions apps/comments/src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const client = createClient(getRootPath())

// set CSRF token header
const setHeaders = (token) => {
client.setHeaders({
// Add this so the server knows it is an request from the browser
'X-Requested-With': 'XMLHttpRequest',
// Inject user auth
requesttoken: token ?? '',
})
client.setHeaders({
// Add this so the server knows it is an request from the browser
'X-Requested-With': 'XMLHttpRequest',
// Inject user auth
requesttoken: token ?? '',
})
}

// refresh headers when request token changes
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/src/services/GetComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const getDirectoryFiles = function(
// Map all items to a consistent output structure (results)
return responseItems.map(item => {
// Each item should contain a stat object
const props = item.propstat!.prop!;
const props = item.propstat!.prop!

return prepareFileFromProps(props, props.id!.toString(), isDetailed)
})
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/src/utils/cancelableRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const cancelableRequest = function(request) {
const fetch = async function(url, options) {
const response = await request(
url,
Object.assign({ signal }, options)
Object.assign({ signal }, options),
)
return response
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/src/dav/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export const getClient = memoize((service) => {
onRequestTokenUpdate(setHeaders)
setHeaders(getRequestToken())

return client;
return client
})
4 changes: 2 additions & 2 deletions apps/dav/src/service/PreferenceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function enableUserStatusAutomation() {
}),
{
configValue: 'yes',
}
},
)
}

Expand All @@ -29,6 +29,6 @@ export async function disableUserStatusAutomation() {
generateOcsUrl('/apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', {
appId: 'dav',
configKey: 'user_status_automation',
})
}),
)
}
4 changes: 2 additions & 2 deletions apps/dav/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const CalDavSettingsView = new View({
sendInvitations: loadState('dav', 'sendInvitations'),
generateBirthdayCalendar: loadState(
'dav',
'generateBirthdayCalendar'
'generateBirthdayCalendar',
),
sendEventReminders: loadState('dav', 'sendEventReminders'),
sendEventRemindersToSharedUsers: loadState(
'dav',
'sendEventRemindersToSharedUsers'
'sendEventRemindersToSharedUsers',
),
sendEventRemindersPush: loadState('dav', 'sendEventRemindersPush'),
}
Expand Down
12 changes: 6 additions & 6 deletions apps/dav/src/views/CalDavSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ describe('CalDavSettings', () => {
},
Vue => {
Vue.prototype.$t = jest.fn((app, text) => text)
}
},
)
expect(TLUtils.container).toMatchSnapshot()
const sendInvitations = TLUtils.getByLabelText(
'Send invitations to attendees'
'Send invitations to attendees',
)
expect(sendInvitations).toBeChecked()
const generateBirthdayCalendar = TLUtils.getByLabelText(
'Automatically generate a birthday calendar'
'Automatically generate a birthday calendar',
)
expect(generateBirthdayCalendar).toBeChecked()
const sendEventReminders = TLUtils.getByLabelText(
'Send notifications for events'
'Send notifications for events',
)
expect(sendEventReminders).toBeChecked()
const sendEventRemindersToSharedUsers = TLUtils.getByLabelText(
'Send reminder notifications to calendar sharees as well'
'Send reminder notifications to calendar sharees as well',
)
expect(sendEventRemindersToSharedUsers).toBeChecked()
const sendEventRemindersPush = TLUtils.getByLabelText(
'Enable notifications for events via push'
'Enable notifications for events via push',
)
expect(sendEventRemindersPush).toBeChecked()

Expand Down
4 changes: 2 additions & 2 deletions apps/dav/src/views/CalDavSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
OCP.AppConfig.setValue(
'dav',
'sendInvitations',
value ? 'yes' : 'no'
value ? 'yes' : 'no',
)
},
sendEventReminders(value) {
Expand All @@ -138,7 +138,7 @@ export default {
OCP.AppConfig.setValue(
'dav',
'sendEventRemindersToSharedUsers',
value ? 'yes' : 'no'
value ? 'yes' : 'no',
)
},
sendEventRemindersPush(value) {
Expand Down
7 changes: 4 additions & 3 deletions apps/federatedfilesharing/src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
</template>

<script>
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { confirmPassword } from '@nextcloud/password-confirmation'
import axios from '@nextcloud/axios'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
import '@nextcloud/password-confirmation/dist/style.css'
export default {
Expand Down
4 changes: 2 additions & 2 deletions apps/federatedfilesharing/src/components/PersonalSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M502 197q-96 0-96.5 1.5t-1.5 137-1.5 138-2 2.5T266 432.5 132.5 390t-30 94T74 578l232 77q21 8 21 10t-79.5 117.5T168 899t79.5 56.5T328 1011t81-110 82-110 41 55l83 115q43 60 44 60t79.5-58 79-59-76-112.5-76-113.5T795 632.5t129.5-44-28-94T867 400t-128 42-128.5 43-2.5-7.5-1-38.5l-3-108q-4-133-5-133.5t-97-.5z" /></svg>
</template>
</NcButton>
<NcButton @click="showHtml = !showHtml"
class="social-button__website-button">
<NcButton class="social-button__website-button"
@click="showHtml = !showHtml">
<template #icon>
<Web :size="20" />
</template>
Expand Down
2 changes: 1 addition & 1 deletion apps/federatedfilesharing/src/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const processIncomingShareFromUrl = function() {
password,
},
).done(function(data) {
if (data.hasOwnProperty('legacyMount')) {
if (Object.hasOwn(data, 'legacyMount')) {
reloadFilesList()
} else {
window.OC.Notification.showTemporary(data.message)
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const action = new FileAction({
.every(permission => (permission & Permission.DELETE) !== 0)
},

async exec(node: Node, view: View, dir: string) {
async exec(node: Node) {
try {
await axios.delete(node.encodedSource)

Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { Permission, type Node, View, FileAction, FileType } from '@nextcloud/files'
import { Permission, type Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'

Expand Down
4 changes: 3 additions & 1 deletion apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ComponentPublicInstance, PropType } from 'vue'
import type { FileSource } from '../types.ts'

import { showError } from '@nextcloud/dialogs'
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, View } from '@nextcloud/files'
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { vOnClickOutside } from '@vueuse/components'
Expand Down Expand Up @@ -157,6 +157,8 @@ export default defineComponent({
/**
* When the source changes, reset the preview
* and fetch the new one.
* @param a
* @param b
*/
source(a: Node, b: Node) {
if (a.source !== b.source) {
Expand Down
10 changes: 5 additions & 5 deletions apps/files/src/components/NavigationQuota.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export default {
mounted() {
// If the user has a quota set, warn if the available account storage is <=0
//
// NOTE: This doesn't catch situations where actual *server*
// NOTE: This doesn't catch situations where actual *server*
// disk (non-quota) space is low, but those should probably
// be handled differently anyway since a regular user can't
// can't do much about them (If we did want to indicate server disk
// can't do much about them (If we did want to indicate server disk
// space matters to users, we'd probably want to use a warning
// specific to that situation anyhow. So this covers warning covers
// specific to that situation anyhow. So this covers warning covers
// our primary day-to-day concern (individual account quota usage).
//
if (this.storageStats?.quota > 0 && this.storageStats?.free <= 0) {
Expand All @@ -121,7 +121,7 @@ export default {
* Update the storage stats
* Throttled at max 1 refresh per minute
*
* @param {Event} [event = null] if user interaction
* @param {Event} [event] if user interaction
*/
async updateStorageStats(event = null) {
if (this.loadingStorageStats) {
Expand All @@ -135,7 +135,7 @@ export default {
throw new Error('Invalid storage stats')
}
// Warn the user if the available account storage changed from > 0 to 0
// Warn the user if the available account storage changed from > 0 to 0
// (unless only because quota was intentionally set to 0 by admin in the interim)
if (this.storageStats?.free > 0 && response.data.data?.free <= 0 && response.data.data?.quota > 0) {
this.showStorageFullWarning()
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/components/TransferOwnershipDialogue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<form @submit.prevent="submit">
<p class="transfer-select-row">
<span>{{ readableDirectory }}</span>
<NcButton v-if="directory === undefined"
<NcButton v-if="directory === undefined"
class="transfer-select-row__choose_button"
@click.prevent="start">
{{ t('files', 'Choose file or folder to transfer') }}
Expand All @@ -22,8 +22,8 @@
<label for="targetUser">
<span>{{ t('files', 'New owner') }}</span>
</label>
<NcSelect input-id="targetUser"
v-model="selectedUser"
<NcSelect v-model="selectedUser"
input-id="targetUser"
:options="formatedUserSuggestions"
:multiple="false"
:loading="loadingUsers"
Expand Down
10 changes: 7 additions & 3 deletions apps/files/src/components/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ interface RecycledPoolItem {
item: Node,
}
type DataSource = File | Folder
type DataSourceKey = keyof DataSource
export default Vue.extend({
name: 'VirtualList',
Expand All @@ -73,11 +77,11 @@ export default Vue.extend({
required: true,
},
dataKey: {
type: String,
type: String as PropType<DataSourceKey>,
required: true,
},
dataSources: {
type: Array as PropType<(File | Folder)[]>,
type: Array as PropType<DataSource[]>,
required: true,
},
extraProps: {
Expand Down Expand Up @@ -260,7 +264,7 @@ export default Vue.extend({
// Adding scroll listener AFTER the initial scroll to index
this.$el.addEventListener('scroll', this.onScroll, { passive: true })
this.$_recycledPool = {} as Record<string, any>
this.$_recycledPool = {} as Record<string, DataSource[DataSourceKey]>
},
beforeDestroy() {
Expand Down
16 changes: 7 additions & 9 deletions apps/files/src/composables/useNavigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import { Navigation, View } from '@nextcloud/files'
import nextcloudFiles, { Navigation, View } from '@nextcloud/files'
import { mount } from '@vue/test-utils'
import { defineComponent, nextTick } from 'vue'
import { defineComponent } from 'vue'
import { useNavigation } from './useNavigation'

import nextcloudFiles from '@nextcloud/files'

// Just a wrapper so we can test the composable
const TestComponent = defineComponent({
template: '<div></div>',
Expand Down Expand Up @@ -38,7 +36,7 @@ describe('Composables: useNavigation', () => {
})

it('should return already active navigation', async () => {
const view = new View({ getContents: () => Promise.reject(), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
navigation.register(view)
navigation.setActive(view)
// Now the navigation is already set it should take the active navigation
Expand All @@ -47,7 +45,7 @@ describe('Composables: useNavigation', () => {
})

it('should be reactive on updating active navigation', async () => {
const view = new View({ getContents: () => Promise.reject(), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
navigation.register(view)
const wrapper = mount(TestComponent)

Expand All @@ -72,7 +70,7 @@ describe('Composables: useNavigation', () => {
})

it('should return already registered views', () => {
const view = new View({ getContents: () => Promise.reject(), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
// register before mount
navigation.register(view)
// now mount and check that the view is listed
Expand All @@ -81,8 +79,8 @@ describe('Composables: useNavigation', () => {
})

it('should be reactive on registering new views', () => {
const view = new View({ getContents: () => Promise.reject(), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
const view2 = new View({ getContents: () => Promise.reject(), icon: '<svg></svg>', id: 'view-2', name: 'My View 2', order: 1 })
const view = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-1', name: 'My View 1', order: 0 })
const view2 = new View({ getContents: () => Promise.reject(new Error()), icon: '<svg></svg>', id: 'view-2', name: 'My View 2', order: 1 })

// register before mount
navigation.register(view)
Expand Down
1 change: 0 additions & 1 deletion apps/files/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import registerPersonalFilesView from './views/personal-files'
import registerFilesView from './views/files'
import registerPreviewServiceWorker from './services/ServiceWorker.js'


import { initLivePhotos } from './services/LivePhotos'

// Register file actions
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ __webpack_nonce__ = btoa(getRequestToken())

declare global {
interface Window {
OC: any;
OCA: any;
OCP: any;
OC: Nextcloud.v28.OC;
OCA: Record<string, unknown>;
OCP: Nextcloud.v28.OCP;
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/plugins/search/folderSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { Node } from '@nextcloud/files'
import { emit } from '@nextcloud/event-bus'
import { getFilePickerBuilder } from '@nextcloud/dialogs';
import { getFilePickerBuilder } from '@nextcloud/dialogs'
import { imagePath } from '@nextcloud/router'
import { translate as t } from '@nextcloud/l10n'
import logger from '../../logger'
Expand All @@ -19,7 +19,7 @@ function init() {
return
}

logger.info('Initializing unified search plugin: folder search from files app');
logger.info('Initializing unified search plugin: folder search from files app')
OCA.UnifiedSearch.registerFilterAction({
id: 'files',
appId: 'files',
Expand Down
Loading

0 comments on commit df92bea

Please sign in to comment.