better code: safer
Massimo Melina committed
Aug 2, 2023 at 15:35 UTC
5c5d227a29ca82d7f138d90f91f698fd66f26fab
5 files changed
+5
-5
admin/src/ArrayField.ts
+1
-1
@@ -11,7 +11,7 @@ import { Box, FormHelperText, FormLabel } from '@mui/material'
11
type ArrayFieldProps<T> = FieldProps<T[]> & { fields: FieldDescriptor[], height?: number }
12
export function ArrayField<T extends object>({ label, helperText, fields, value, onChange, onError, getApi, ...rest }: ArrayFieldProps<T>) {
13
const rows = useMemo(() => (value||[]).map((x,$idx) =>
14
- setHidden({ ...x } as any, 'id' in x ? { $idx } : { id: $idx })),
14
+ setHidden({ ...x } as any, x.hasOwnProperty('id') ? { $idx } : { id: $idx })),
15
[JSON.stringify(value)]) //eslint-disable-line
16
const form = {
17
fields: fields.map(({ $width, $column, ...rest }) => rest)
mui-grid-form/StringStringField.ts
+1
-1
@@ -71,7 +71,7 @@ export function StringStringField({ value, onChange, keyLabel='key', valueLabel=
71
onChange(v, more){
72
if (!v) return
73
more.cancel()
74
- if (value && v in value)
74
+ if (value?.hasOwnProperty(v))
75
return alert(keyLabel + " entry already present")
76
justEntered.current = v // the way dom is manipulated will cause focus on wrong element, so we have to re-focus
77
onChange({ ...value, [v]:'' }, { ...more, was:value })
src/config.ts
+1
-1
@@ -112,7 +112,7 @@ export function defineConfig<T, CT=T>(k: string, defaultValue: T, compiler?: Sub
112
}
113
114
export function configKeyExists(k: string) {
115
- return k in configProps
115
+ return configProps.hasOwnProperty(k)
116
}
117
118
const stack: any[] = []
src/github.ts
+1
-1
@@ -42,7 +42,7 @@ export async function downloadPlugin(repo: string, branch='', overwrite?: boolea
42
return new ApiError(HTTP_BAD_REQUEST, "bad repo")
43
const folder2repo = getFolder2repo()
44
const folder = overwrite ? _.findKey(folder2repo, x => x===repo)! // use existing folder
45
- : short in folder2repo ? repo.replace('/','-') // longer form only if another plugin is using short form
45
+ : folder2repo.hasOwnProperty(short) ? repo.replace('/','-') // longer form only if another plugin is using short form
46
: short
47
const installPath = PLUGINS_PATH + '/' + folder
48
const GITHUB_ZIP_ROOT = short + '-' + branch // GitHub puts everything within this folder
src/perm.ts
+1
-1
@@ -74,7 +74,7 @@ export async function updateAccount(account: Account, changer?:Changer) {
74
if (account.belongs) {
75
account.belongs = wantArray(account.belongs)
76
_.remove(account.belongs, b => {
77
- if (b in accounts) return
77
+ if (accounts.hasOwnProperty(b)) return
78
console.error(`account ${username} belongs to non-existing ${b}`)
79
return true
80
})