Skip to content

Commit 9c71321

Browse files
tplevkolhein
authored andcommitted
fx(sonar): typescript:S7776: Use Set instead of Array for membership checks
1 parent 025ac89 commit 9c71321

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/ui/src/components/Document/actions/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { DataMapperMetadataService } from '../../../services/datamapper-metadata
44
import { DataMapperStepService } from '../../../services/datamapper-step.service';
55
import { SchemaFileItem, SchemaFileMessage } from './AttachSchema/SchemaFileDataList';
66

7-
const VALID_XML_EXTENSIONS = ['.xml', '.xsd'];
8-
const VALID_JSON_EXTENSIONS = ['.json'];
9-
export const VALID_ALL_EXTENSIONS = [...VALID_XML_EXTENSIONS, ...VALID_JSON_EXTENSIONS];
7+
const VALID_XML_EXTENSIONS = new Set(['.xml', '.xsd']);
8+
const VALID_JSON_EXTENSIONS = new Set(['.json']);
9+
export const VALID_ALL_EXTENSIONS = new Set([...VALID_XML_EXTENSIONS, ...VALID_JSON_EXTENSIONS]);
1010

1111
export function getFileExtension(filePath: string): string {
1212
return filePath.toLowerCase().substring(filePath.lastIndexOf('.'));
@@ -17,11 +17,11 @@ export function getFileName(filePath: string): string {
1717
}
1818

1919
export function isXmlExtension(ext: string): boolean {
20-
return VALID_XML_EXTENSIONS.includes(ext);
20+
return VALID_XML_EXTENSIONS.has(ext);
2121
}
2222

2323
export function isJsonExtension(ext: string): boolean {
24-
return VALID_JSON_EXTENSIONS.includes(ext);
24+
return VALID_JSON_EXTENSIONS.has(ext);
2525
}
2626

2727
/** Public for tests only */
@@ -36,7 +36,7 @@ export async function validateFileExtension(ext: string, documentType: DocumentT
3636
}
3737
return undefined;
3838
}
39-
if (!VALID_ALL_EXTENSIONS.includes(ext)) {
39+
if (!VALID_ALL_EXTENSIONS.has(ext)) {
4040
return `Unknown file extension '${ext}'. Either XML schema (.xsd, .xml) or JSON schema (.json) file is supported.`;
4141
}
4242
return undefined;

packages/ui/src/components/Visualization/Canvas/Form/fields/MediaTypeField/MediaTypeField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FunctionComponent, KeyboardEvent, MouseEvent, Ref, useCallback, useCont
1515

1616
import { SettingsContext } from '../../../../../../providers/settings.provider';
1717

18-
const COMMON_MEDIA_TYPES = [
18+
const COMMON_MEDIA_TYPES = new Set([
1919
'application/json',
2020
'application/xml',
2121
'text/plain',
@@ -49,7 +49,7 @@ const COMMON_MEDIA_TYPES = [
4949
'application/senml+xml',
5050
'application/pkcs7-mime',
5151
'application/pkcs7-signature',
52-
];
52+
]);
5353

5454
const parseMediaTypes = (value: string | undefined): string[] => {
5555
if (!value) {
@@ -76,7 +76,7 @@ export const MediaTypeField: FunctionComponent<FieldProps> = ({ propName, requir
7676
const selectedValues = useMemo(() => parseMediaTypes(value), [value]);
7777

7878
const options = useMemo(() => {
79-
const customValues = selectedValues.filter((item) => !COMMON_MEDIA_TYPES.includes(item));
79+
const customValues = selectedValues.filter((item) => !COMMON_MEDIA_TYPES.has(item));
8080
const merged = new Set<string>([...COMMON_MEDIA_TYPES, ...storedMediaTypes, ...customValues]);
8181
return Array.from(merged);
8282
}, [selectedValues, storedMediaTypes]);

0 commit comments

Comments
 (0)