Syntax fixes (#5367)

* Declare return types on functions

And a very few other type related minor fixes

* Minor syntax fixes

* Remove unnecessary escape chars in regexes
* Remove unnecessary awaits
* Replace deprecated req.connection with req.socket
* Replace deprecated upload with uploadOne
* Remove unnecessary eslint-disable-next-line comments
* Comment empty functions / catch or finally clauses
* Fix irregular whitespaces
* Add missing returns (null)
* Remove unreachable code
* A few logical fixes
* Remove / Handle non-null assertions which are certainly unnecessary (e.g. in
tests)
This commit is contained in:
Pascal Jufer
2021-04-29 18:11:43 +02:00
committed by GitHub
parent 40eba791fa
commit acd41eb0be
231 changed files with 646 additions and 527 deletions

View File

@@ -29,6 +29,7 @@
<script lang="ts">
import { defineComponent, computed, inject, ref } from '@vue/composition-api';
import { getInterfaces } from '@/interfaces';
import { InterfaceConfig } from '@/interfaces/types';
export default defineComponent({
props: {
@@ -49,7 +50,7 @@ export default defineComponent({
const selectedInterface = computed(() => {
if (!values.value[props.interfaceField]) return;
return interfaces.value.find((inter) => inter.id === values.value[props.interfaceField]);
return interfaces.value.find((inter: InterfaceConfig) => inter.id === values.value[props.interfaceField]);
});
return { selectedInterface, values };

View File

@@ -15,7 +15,7 @@
import { defineComponent, computed, PropType, inject, ref, watch } from '@vue/composition-api';
import i18n from '@/lang';
import { getInterfaces } from '@/interfaces';
import { types } from '@/types';
import { InterfaceConfig } from '@/interfaces/types';
export default defineComponent({
props: {
@@ -47,9 +47,11 @@ export default defineComponent({
const items = computed(() => {
return interfaces.value
.filter((inter) => inter.relational !== true && inter.system !== true)
.filter((inter) => selectedType.value === undefined || inter.types.includes(selectedType.value))
.map((inter) => {
.filter((inter: InterfaceConfig) => inter.relational !== true && inter.system !== true)
.filter(
(inter: InterfaceConfig) => selectedType.value === undefined || inter.types.includes(selectedType.value)
)
.map((inter: InterfaceConfig) => {
return {
text: inter.name,
value: inter.id,

View File

@@ -136,7 +136,7 @@ export default defineComponent({
codemirror.value.setOption('mode', { name: 'javascript', json: true });
CodeMirror.registerHelper('lint', 'json', (text: string) => {
const found: {}[] = [];
const found: Record<string, any> = [];
const parser = jsonlint.parser;
parser.parseError = (str: string, hash: any) => {
@@ -150,7 +150,9 @@ export default defineComponent({
if (text.length > 0) {
try {
jsonlint.parse(text);
} catch (e) {}
} finally {
// Do nothing
}
}
return found;
});
@@ -273,7 +275,9 @@ export default defineComponent({
if (props.type === 'json') {
try {
emit('input', JSON.parse(props.template));
} catch {}
} finally {
// Do nothing
}
} else {
emit('input', props.template);
}

View File

@@ -113,7 +113,7 @@ export default defineComponent({
if (!image.value) return null;
const { filesize, width, height, type } = image.value;
return `${i18n.n(width)}x${i18n.n(height)} ${formatFilesize(filesize)} ${type}`;
return `${i18n.n(width)}x${i18n.n(height)} ${formatFilesize(filesize)} ${type}`;
});
watch(

View File

@@ -4,7 +4,7 @@ import { InterfaceConfig } from './types';
let interfacesRaw: Ref<InterfaceConfig[]>;
let interfaces: Ref<InterfaceConfig[]>;
export function getInterfaces() {
export function getInterfaces(): Record<string, Ref> {
if (!interfacesRaw) {
interfacesRaw = ref([]);
}

View File

@@ -329,7 +329,6 @@ export default defineComponent({
} else {
val[anyRelation.value.many_field] = cloneDeep(item);
}
} else {
}
return val;

View File

@@ -86,6 +86,7 @@ import useSort from './use-sort';
import { getFieldsFromTemplate } from '@/utils/get-fields-from-template';
import adjustFieldsForDisplays from '@/utils/adjust-fields-for-displays';
import { usePermissionsStore, useUserStore } from '@/stores';
import { DisplayConfig } from '@/displays/types';
export default defineComponent({
components: { DrawerItem, DrawerCollection, Draggable },
@@ -138,7 +139,7 @@ export default defineComponent({
let relatedDisplayTemplate = relationCollection.value.meta?.display_template;
if (relatedDisplayTemplate) {
const regex = /({{.*?}})/g;
const parts = relatedDisplayTemplate.split(regex).filter((p) => p);
const parts = relatedDisplayTemplate.split(regex).filter((p: DisplayConfig) => p);
for (const part of parts) {
if (part.startsWith('{{') === false) continue;

View File

@@ -6,7 +6,7 @@ export default function useActions(
value: Ref<(string | number | Record<string, any>)[] | null>,
relation: Ref<RelationInfo>,
emit: (newValue: any[] | null) => void
) {
): Record<string, any> {
// Returns the junction item with the given Id.
function getJunctionItem(id: string | number) {
const { junctionPkField } = relation.value;

View File

@@ -6,7 +6,7 @@ export default function useEdit(
value: Ref<(string | number | Record<string, any>)[] | null>,
relation: Ref<RelationInfo>,
emit: (newVal: any[] | null) => void
) {
): Record<string, any> {
const editModalActive = ref(false);
const currentlyEditing = ref<string | number | null>(null);
const relatedPrimaryKey = ref<string | number | null>(null);

View File

@@ -14,7 +14,7 @@ export default function usePreview(
getUpdatedItems: () => Record<string, any>[],
getNewItems: () => Record<string, any>[],
getPrimaryKeys: () => (string | number)[]
) {
): Record<string, Ref> {
// Using a ref for the table headers here means that the table itself can update the
// values if it needs to. This allows the user to manually resize the columns for example

View File

@@ -12,7 +12,7 @@ export type RelationInfo = {
relationCollection: string;
};
export default function useRelation(collection: Ref<string>, field: Ref<string>) {
export default function useRelation(collection: Ref<string>, field: Ref<string>): Record<string, any> {
const relationsStore = useRelationsStore();
const collectionsStore = useCollectionsStore();

View File

@@ -8,7 +8,7 @@ export default function useSelection(
items: Ref<Record<string, any>[]>,
relation: Ref<RelationInfo>,
emit: (newVal: any[] | null) => void
) {
): Record<string, any> {
const selectModalActive = ref(false);
const selectedPrimaryKeys = computed(() => {

View File

@@ -8,7 +8,7 @@ export default function useSort(
fields: Ref<string[]>,
items: Ref<Record<string, any>[]>,
emit: (newVal: any[] | null) => void
) {
): Record<string, any> {
const sort = ref<Sort>({ by: relation.value.sortField || fields.value[0], desc: false });
const sortedItems = computed(() => {

View File

@@ -32,7 +32,7 @@ export type CustomSyntax = {
box: 'inline' | 'block';
};
export function useEdit(codemirror: Ref<CodeMirror.EditorFromTextArea | null>, customSyntaxBlocks: CustomSyntax[]) {
export function useEdit(codemirror: Ref<CodeMirror.EditorFromTextArea | null>): Record<string, any> {
const alterations: AlterationFunctions = {
heading(selection, { cursorTo }, options) {
const level = options?.level || 3;

View File

@@ -235,7 +235,7 @@ export default defineComponent({
}
);
const { edit } = useEdit(codemirror, props.customSyntax);
const { edit } = useEdit(codemirror);
const html = computed(() => {
let md = props.value || '';

View File

@@ -4,10 +4,11 @@ import { Component } from 'vue';
import api from '@/api';
import { getRootPath } from '@/utils/get-root-path';
import asyncPool from 'tiny-async-pool';
import { InterfaceConfig } from './types';
const { interfacesRaw } = getInterfaces();
export async function registerInterfaces() {
export async function registerInterfaces(): Promise<void> {
const context = require.context('.', true, /^.*index\.ts$/);
const modules = context
@@ -36,7 +37,7 @@ export async function registerInterfaces() {
interfacesRaw.value = modules;
interfacesRaw.value.forEach((inter) => {
interfacesRaw.value.forEach((inter: InterfaceConfig) => {
registerComponent('interface-' + inter.id, inter.component);
if (typeof inter.options !== 'function' && Array.isArray(inter.options) === false) {

View File

@@ -12,7 +12,7 @@
<div class="grid-element full">
<p class="type-label">{{ $t('interfaces.repeater.edit_fields') }}</p>
<repeater v-model="repeaterValue" :template="`{{ field }} — {{ interface }}`" :fields="repeaterFields" />
<repeater v-model="repeaterValue" :template="`{{ field }} — {{ interface }}`" :fields="repeaterFields" />
</div>
</div>
</template>

View File

@@ -2,7 +2,7 @@ function cssVar(name: string) {
return getComputedStyle(document.body).getPropertyValue(name);
}
export default function getEditorStyles(font: 'sans-serif' | 'serif' | 'monospace') {
export default function getEditorStyles(font: 'sans-serif' | 'serif' | 'monospace'): string {
return `
body {
color: ${cssVar('--foreground-normal')};

View File

@@ -10,7 +10,7 @@ type ImageSelection = {
height?: number;
};
export default function useImage(editor: Ref<any>, imageToken: Ref<string>) {
export default function useImage(editor: Ref<any>, imageToken: Ref<string>): Record<string, any> {
const imageDrawerOpen = ref(false);
const imageSelection = ref<ImageSelection | null>(null);

View File

@@ -8,7 +8,7 @@ type LinkSelection = {
newTab: boolean;
};
export default function useLink(editor: Ref<any>) {
export default function useLink(editor: Ref<any>): Record<string, any> {
const linkDrawerOpen = ref(false);
const linkSelection = ref<LinkSelection>({
url: null,

View File

@@ -9,7 +9,7 @@ type MediaSelection = {
height?: number;
};
export default function useMedia(editor: Ref<any>, imageToken: Ref<string>) {
export default function useMedia(editor: Ref<any>, imageToken: Ref<string>): Record<string, any> {
const mediaDrawerOpen = ref(false);
const mediaSelection = ref<MediaSelection | null>(null);
const openMediaTab = ref(['video']);

View File

@@ -1,7 +1,7 @@
import { Ref, ref } from '@vue/composition-api';
import i18n from '@/lang';
export default function useSourceCode(editor: Ref<any>) {
export default function useSourceCode(editor: Ref<any>): Record<string, any> {
const codeDrawerOpen = ref(false);
const code = ref<string>();