Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/six-pots-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@sap-ux/cds-odata-annotation-converter': patch
'@sap-ux-private/preview-middleware-client': patch
'@sap-ux/control-property-editor': patch
'@sap-ux/serve-static-middleware': patch
'@sap-ux/odata-service-inquirer': patch
'@sap-ux/ui5-application-writer': patch
'@sap-ux/cds-annotation-parser': patch
'@sap-ux/fiori-docs-embeddings': patch
'@sap-ux/fiori-elements-writer': patch
'@sap-ux/odata-annotation-core': patch
'@sap-ux/annotation-generator': patch
'@sap-ux/fiori-annotation-api': patch
'@sap-ux/jest-environment-ui5': patch
'@sap-ux/environment-check': patch
'@sap-ux/axios-extension': patch
'@sap-ux/inquirer-common': patch
'@sap-ux/deploy-tooling': patch
'@sap-ux/project-access': patch
'@sap-ux/fe-fpm-writer': patch
'@sap-ux/launch-config': patch
'@sap-ux/ui-components': patch
'@sap-ux/adp-tooling': patch
---

fix sonar issues
2 changes: 1 addition & 1 deletion packages/adp-tooling/src/cf/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function validateSmartTemplateApplication(manifest: Manifest): Prom
throw new Error(t('error.adpDoesNotSupportSelectedApplication'));
}

if (manifest['sap.ui5'] && manifest['sap.ui5'].flexEnabled === false) {
if (manifest['sap.ui5']?.flexEnabled === false) {
throw new Error(t('error.appDoesNotSupportFlexibility'));
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/annotation-generator/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { adaptFilePath } from './utils';

const draftSpecificFields = ['IsActiveEntity', 'HasActiveEntity', 'HasDraftEntity'];
const draftSpecificFields = new Set(['IsActiveEntity', 'HasActiveEntity', 'HasDraftEntity']);

const commonNodeModulePath = join('node_modules', '@sap', 'cds', 'common.cds');
const managedProperties = ['createdAt', 'createdBy', 'modifiedAt', 'modifiedBy'];
const managedProperties = new Set(['createdAt', 'createdBy', 'modifiedAt', 'modifiedBy']);

const FACETS_PROP_NAME_LABEL = 'Label';
const FACETS_PROP_NAME_ID = 'ID';
Expand Down Expand Up @@ -311,7 +311,7 @@ function generateFieldGroup(context: Context): RawAnnotation {
function getDataFieldRecordCollection(context: Context, isListReport = false): AnnotationRecord[] {
const { project, metadataService, entityType } = context;

const properties = entityType.entityProperties.filter((property) => !draftSpecificFields.includes(property.name));
const properties = entityType.entityProperties.filter((property) => !draftSpecificFields.has(property.name));

const keyCount = moveKeysToBeginning(isListReport, entityType, properties);

Expand Down Expand Up @@ -427,7 +427,7 @@ function isPropertyFromCommonNodeModule(propName: string, locationUri?: string):
if (!propName || !locationUri) {
return false;
}
return managedProperties.includes(propName) && locationUri.endsWith(commonNodeModulePath);
return managedProperties.has(propName) && locationUri.endsWith(commonNodeModulePath);
}

function isHidden(hiddenAnno: Hidden | undefined): boolean {
Expand Down Expand Up @@ -629,7 +629,7 @@ function getValueListParameterDisplayOnly(
prop.isComplexType ||
hidden ||
prop.edmPrimitiveType === 'Edm.Guid' ||
draftSpecificFields.includes(prop.name) ||
draftSpecificFields.has(prop.name) ||
isPropertyFromCommonNodeModule(prop.name, prop.location?.uri);

return !isOmit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export class GeneratorService extends AdtService {
return GeneratorService.adtCategory;
}

private id: string;

/**
* Get the UI service generator for the given referenced object.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/cds-annotation-parser/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class AnnotationParser extends CstParser {
* https://chevrotain.io/docs/guide/performance.html#caching-arrays-of-alternatives
*/
v?: IOrAlt<void>[];
private CST_STACK: AssignmentCstNode[] = [];
private readonly CST_STACK: AssignmentCstNode[] = [];

text = '';
constructor() {
Expand Down
93 changes: 39 additions & 54 deletions packages/cds-annotation-parser/src/transformer/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,17 @@ class CstToAstVisitor extends Visitor {
return undefined;
}

/**
* Builds operator.
*
* @param operatorToken Operator CST token
* @param range Token range
* @returns Operator node
*/
private buildOperator(operatorToken: IToken, range: Range): Operator {
return { type: OPERATOR_TYPE, value: operatorToken.image, range };
}

/**
* Converts expression children to expression ast node.
*
Expand All @@ -693,17 +704,6 @@ class CstToAstVisitor extends Visitor {
* @returns Expression value ast node
*/
expression(context: ExpressionChildren, location: CstNodeLocation): Expression | Path {
/**
* Builds operator.
*
* @param operatorToken Operator CST token
* @param range Token range
* @returns Operator node
*/
function buildOperator(operatorToken: IToken, range: Range): Operator {
const operator: Operator = { type: OPERATOR_TYPE, value: operatorToken.image, range };
return operator;
}
const openToken = existsAndNotRecovered(context.LParen) ? this.createToken(context.LParen[0]) : undefined;
const closeToken = existsAndNotRecovered(context.RParen) ? this.createToken(context.RParen[0]) : undefined;
const range = this.locationToRange(location);
Expand All @@ -713,7 +713,7 @@ class CstToAstVisitor extends Visitor {
return node;
}
}
const operators = (context.Operator ?? []).map((token) => buildOperator(token, this.tokenToRange(token)));
const operators = (context.Operator ?? []).map((token) => this.buildOperator(token, this.tokenToRange(token)));
const operands = (context.value ?? []).map((token) => this.visit(token) as AnnotationValue);
const expression = { operators, operands, openToken, closeToken, range };
const unsupportedOperator = operators.find((operator) => {
Expand Down Expand Up @@ -1070,7 +1070,7 @@ class CstToAstVisitor extends Visitor {
*/
path(context: PathChildren, location: CstNodeLocation): Path {
const segments: Identifier[] = (context.pathSegment ?? [])
.map((segment, i) => {
.flatMap((segment, i) => {
const quotedIdentifiers =
segment.children.quotedIdentifier?.reduce(
(acc: { token: IToken; delimiter: Delimiter }[], quotedIdentifier) => {
Expand Down Expand Up @@ -1126,60 +1126,46 @@ class CstToAstVisitor extends Visitor {
const identifiers = this.getIdentifierToken(segment);
return [...identifiers, ...quotedIdentifiers, ...delimitedIdentifiers, ...fromErrorRecovery];
})
.reduce((acc, allSegments) => [...acc, ...allSegments], [])
.sort((a, b) => compareTokensByPosition(a.token, b.token))
.map(({ token, delimiter }) => this.tokenToIdentifier(token, delimiter));
const separators: Separator[] = [
...(context.pathSegment ?? []).map((segment) => {
...(context.pathSegment ?? []).flatMap((segment) => {
const quotedIdentifiers =
segment.children.quotedIdentifier?.reduce(
(acc: { token: IToken; delimiter: Delimiter }[], quotedIdentifier) => {
const childrenSeparators = quotedIdentifier.children.PathSegmentSeparator ?? [];
return [
...acc,
...childrenSeparators.map((token) => ({
token,
delimiter: Delimiter.quoted
}))
];
},
[]
) ?? [];
segment.children.quotedIdentifier?.flatMap((quotedIdentifier) => {
const childrenSeparators = quotedIdentifier.children.PathSegmentSeparator ?? [];
return childrenSeparators.map((token) => ({
token,
delimiter: Delimiter.quoted
}));
}) ?? [];
const delimitedIdentifiers =
segment.children.delimitedIdentifier?.reduce(
(acc: { token: IToken; delimiter: Delimiter }[], delimitedIdentifier) => {
if (!delimitedIdentifier.children.DelimitedIdentifier) {
return [
...acc,
{
token: this.createEmptyIdentifier(
delimitedIdentifier.children.IdentifierStart[0],
delimitedIdentifier.children.DelimitedIdentifierExit[0]
),
delimiter: Delimiter.exclamationSquareBrackets
}
];
}
const childrenSeparators = delimitedIdentifier.children.PathSegmentSeparator ?? [];

segment.children.delimitedIdentifier?.flatMap((delimitedIdentifier) => {
if (!delimitedIdentifier.children.DelimitedIdentifier) {
return [
...acc,
...childrenSeparators.map((token) => ({
token,
{
token: this.createEmptyIdentifier(
delimitedIdentifier.children.IdentifierStart[0],
delimitedIdentifier.children.DelimitedIdentifierExit[0]
),
delimiter: Delimiter.exclamationSquareBrackets
}))
}
];
},
[]
) ?? [];
}
const childrenSeparators = delimitedIdentifier.children.PathSegmentSeparator ?? [];

return childrenSeparators.map((token) => ({
token,
delimiter: Delimiter.exclamationSquareBrackets
}));
}) ?? [];
return [...quotedIdentifiers, ...delimitedIdentifiers];
}),
(context.PathSegmentSeparator ?? []).map((token) => ({
token,
delimiter: Delimiter.none
}))
]
.reduce((acc, allSegments) => [...acc, ...allSegments], [])
.flat()
.sort((a, b) => compareTokensByPosition(a.token, b.token))
.map(({ token, delimiter }) => this.tokenToSeparator(token, delimiter));

Expand Down Expand Up @@ -1269,8 +1255,7 @@ class CstToAstVisitor extends Visitor {
) {
this.recoverFromMissingValue(assignment.children.Colon[0], property);
} else if (
assignment.children?.value &&
assignment.children?.value.length &&
assignment.children?.value?.length &&
assignment.children.value[0]?.children?.path &&
assignments[assignmentIndex + 1] &&
!assignments[assignmentIndex + 1].children?.path
Expand Down
13 changes: 4 additions & 9 deletions packages/cds-odata-annotation-converter/src/printer/indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ const CLOSING_CHARACTERS = new Set([']', '}', ')']);
*
* @param string - String representing a complete element
* @param indentInfo - indentation level, default 0 and skipFirstLine a boolean flag, flag to skip indenting first line if insert position is known.
* @param indentInfo.level
* @param indentInfo.skipFirstLine
* @returns Indent a string representing a complete element.
*/
export function indent(
string: string,
indentInfo = {
level: 0,
skipFirstLine: false
}
): string {
let level = indentInfo.level;
export function indent(string: string, { level = 0, skipFirstLine = false } = {}): string {
const parts = string.split('\n');
for (let i = 0; i < parts.length; i++) {
const line = parts[i];
const change = indentChange(line);
if (change < 0) {
level += change;
}
if (indentInfo.skipFirstLine && i === 0) {
if (skipFirstLine && i === 0) {
level += change;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/control-property-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function App(appProps: AppProps): ReactElement {
const paddingWidth = 40;
const width = node.clientWidth;
const availableWidth = width - paddingWidth;
const requiredWidth = parseInt(previewWidth, 10);
const requiredWidth = Number.parseInt(previewWidth, 10);
if (availableWidth < requiredWidth) {
const scale = availableWidth / requiredWidth;
dispatch(changePreviewScale(scale));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FilterOptions } from '../../slice';
import { FilterName } from '../../slice';
import type { IGroup } from '@fluentui/react';

const commonVisibleControls = [
const commonVisibleControls = new Set([
'sap.ui.comp.smarttable.SmartTable',
'sap.m.Column',
'sap.ui.comp.smartfilterbar.SmartFilterBar',
Expand All @@ -26,7 +26,7 @@ const commonVisibleControls = [
'sap.ovp.ui.Card',
'sap.ui.extensionpoint',
'sap.ui.extensionpoint.child'
];
]);

/**
* Filter model. If none of filter conditions meet, model without filter is returned.
Expand Down Expand Up @@ -113,7 +113,7 @@ function filterByCommonlyUsedControls(model: OutlineNode[], filterOption: Filter
for (const item of model) {
let parentMatch = false;
const controlType = item.controlType;
if (commonVisibleControls.includes(controlType)) {
if (commonVisibleControls.has(controlType)) {
parentMatch = true;
// add node without its children
filteredModel.push({ ...item, children: [] });
Expand Down Expand Up @@ -145,7 +145,7 @@ export const adaptExpandCollapsed = (groups: IGroup[], collapsed: IGroup[]) => {
return;
}
for (const group of groups) {
const [collapsedResult] = collapsed.filter((data) => isSame(group.data.path, data.data.path));
const collapsedResult = collapsed.find((data) => isSame(group.data.path, data.data.path));
if (collapsedResult) {
group.isCollapsed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ const Funnel = (): ReactElement => {
const action = filterNodes([{ name, value: isChecked }]);
dispatch(action);
};
const showEditablePropertiesChecked = filterQuery.filter(
(item) => item.name === FilterName.showEditableProperties
)[0].value as boolean;
const showEditablePropertiesChecked = filterQuery.find((item) => item.name === FilterName.showEditableProperties)
?.value as boolean | undefined;
const checked = showEditablePropertiesChecked;
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export function PropertiesList(): ReactElement {
const controlChanges = useSelector<RootState, ControlChangeStats | undefined>(
(state) => state.changes.controls[control?.id ?? '']
);
const isEditableOnly = useSelector<RootState, FilterOptions[]>((state) => state.filterQuery).filter(
const isEditableOnly = useSelector<RootState, FilterOptions[]>((state) => state.filterQuery).find(
(item) => item.name === FilterName.showEditableProperties
)[0].value as boolean;
)?.value as boolean | undefined;
const [filterValue, setFilterValue] = useState('');
if (!control) {
// Nothing selected, show message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function StringEditor(propertyInputProps: PropertyInputProps): ReactEleme
if (type === FLOAT_VALUE_TYPE) {
let newValue: string | number = String(e.currentTarget.value);
if (type === FLOAT_VALUE_TYPE && !isExpression(newValue)) {
newValue = parseFloat(String(newValue?.trim()));
newValue = Number.parseFloat(String(newValue?.trim()));
}
setCachedValue(controlId, name, InputType.number, newValue);
setValue(newValue);
Expand Down Expand Up @@ -119,7 +119,7 @@ export function StringEditor(propertyInputProps: PropertyInputProps): ReactEleme
} else {
if (type === INTEGER_VALUE_TYPE && !isExpression(value)) {
value = value.trim().replace(/(^-)|(\D+)/g, '$1');
value = parseInt(String(value), 10);
value = Number.parseInt(String(value), 10);
}
const inputType = type === INTEGER_VALUE_TYPE ? InputType.number : InputType.string;
setCachedValue(controlId, name, inputType, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function mergeNodes(
continue;
}
endNode.label = `${startNode.label}-${endNode.label}`;
const index = parentNode.children.findIndex((parentChild) => parentChild === startNode);
const index = parentNode.children.indexOf(startNode);
if (index !== -1) {
parentNode.children[index] = endNode;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy-tooling/src/base/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ async function validatePackageWithAdt(
return;
}
const packages = await adtService.listPackages({ phrase: inputPackage });
const isValidPackage = packages.findIndex((packageName: string) => packageName === inputPackage) >= 0;
const isValidPackage = packages.includes(inputPackage);

if (isValidPackage) {
output.summary.push({
Expand Down
Loading
Loading