refactor(core): Remove linting exceptions in nodes-base (#4794)

*  enabled array-type

*  await-thenable on

*  ban-types on

*  default-param-last on

*  dot-notation on

*  member-delimiter-style on

*  no-duplicate-imports on

*  no-empty-interface on

*  no-floating-promises on

*  no-for-in-array on

*  no-invalid-void-type on

*  no-loop-func on

*  no-shadow on

*  ban-ts-comment re enabled

*  @typescript-eslint/lines-between-class-members on

* address my own comment

* @typescript-eslint/return-await on

* @typescript-eslint/promise-function-async on

* @typescript-eslint/no-unnecessary-boolean-literal-compare on

* @typescript-eslint/no-unnecessary-type-assertion on

* prefer-const on

* @typescript-eslint/prefer-optional-chain on

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Michael Kret
2022-12-02 22:54:28 +02:00
committed by GitHub
parent 8101c05d6f
commit 61e26804ba
796 changed files with 3735 additions and 2847 deletions

View File

@@ -158,6 +158,52 @@ export class RenameKeys implements INodeType {
let renameKeys: IRenameKey[];
let value: any;
const renameKey = (key: IRenameKey) => {
if (key.currentKey === '' || key.newKey === '' || key.currentKey === key.newKey) {
// Ignore all which do not have all the values set or if the new key is equal to the current key
return;
}
value = get(item.json, key.currentKey);
if (value === undefined) {
return;
}
set(newItem.json, key.newKey, value);
unset(newItem.json, key.currentKey);
};
const regexReplaceKey = (replacement: IDataObject) => {
const { searchRegex, replaceRegex, options } = replacement;
const { depth, caseInsensitive } = options as IDataObject;
const flags = (caseInsensitive as boolean) ? 'i' : undefined;
const regex = new RegExp(searchRegex as string, flags);
const renameObjectKeys = (obj: IDataObject, objDepth: number) => {
for (const key in obj) {
if (Array.isArray(obj)) {
// Don't rename array object references
if (objDepth !== 0) {
renameObjectKeys(obj[key] as IDataObject, objDepth - 1);
}
} else if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object' && objDepth !== 0) {
renameObjectKeys(obj[key] as IDataObject, objDepth - 1);
}
if (key.match(regex)) {
const newKey = key.replace(regex, replaceRegex as string);
if (newKey !== key) {
obj[newKey] = obj[key];
delete obj[key];
}
}
}
}
return obj;
};
newItem.json = renameObjectKeys(newItem.json, depth as number);
};
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
renameKeys = this.getNodeParameter('keys.key', itemIndex, []) as IRenameKey[];
const regexReplacements = this.getNodeParameter(
@@ -182,56 +228,9 @@ export class RenameKeys implements INodeType {
newItem.binary = item.binary;
}
renameKeys.forEach((renameKey) => {
if (
renameKey.currentKey === '' ||
renameKey.newKey === '' ||
renameKey.currentKey === renameKey.newKey
) {
// Ignore all which do not have all the values set or if the new key is equal to the current key
return;
}
value = get(item.json, renameKey.currentKey as string);
if (value === undefined) {
return;
}
set(newItem.json, renameKey.newKey, value);
renameKeys.forEach(renameKey);
unset(newItem.json, renameKey.currentKey as string);
});
regexReplacements.forEach((replacement) => {
const { searchRegex, replaceRegex, options } = replacement;
const { depth, caseInsensitive } = options as IDataObject;
const flags = (caseInsensitive as boolean) ? 'i' : undefined;
const regex = new RegExp(searchRegex as string, flags);
const renameObjectKeys = (obj: IDataObject, depth: number) => {
for (const key in obj) {
if (Array.isArray(obj)) {
// Don't rename array object references
if (depth !== 0) {
renameObjectKeys(obj[key] as IDataObject, depth - 1);
}
} else if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object' && depth !== 0) {
renameObjectKeys(obj[key] as IDataObject, depth - 1);
}
if (key.match(regex)) {
const newKey = key.replace(regex, replaceRegex as string);
if (newKey !== key) {
obj[newKey] = obj[key];
delete obj[key];
}
}
}
}
return obj;
};
newItem.json = renameObjectKeys(newItem.json, depth as number);
});
regexReplacements.forEach(regexReplaceKey);
returnData.push(newItem);
}