mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
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:
@@ -755,14 +755,14 @@ return 0;`,
|
||||
const include = this.getNodeParameter('include', i) as string;
|
||||
|
||||
let arrayToSplit;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
arrayToSplit = get(items[i].json, fieldToSplitOut);
|
||||
} else {
|
||||
arrayToSplit = items[i].json[fieldToSplitOut as string];
|
||||
arrayToSplit = items[i].json[fieldToSplitOut];
|
||||
}
|
||||
|
||||
if (arrayToSplit === undefined) {
|
||||
if (fieldToSplitOut.includes('.') && disableDotNotation === true) {
|
||||
if (fieldToSplitOut.includes('.') && disableDotNotation) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Couldn't find the field '${fieldToSplitOut}' in the input data`,
|
||||
@@ -806,12 +806,12 @@ return 0;`,
|
||||
return prev;
|
||||
}
|
||||
let value;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
value = get(items[i].json, field);
|
||||
} else {
|
||||
value = items[i].json[field as string];
|
||||
value = items[i].json[field];
|
||||
}
|
||||
prev = { ...prev, [field as string]: value };
|
||||
prev = { ...prev, [field]: value };
|
||||
return prev;
|
||||
}, {}),
|
||||
};
|
||||
@@ -821,12 +821,12 @@ return 0;`,
|
||||
newItem = {
|
||||
...keys.reduce((prev, field) => {
|
||||
let value;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
value = get(items[i].json, field);
|
||||
} else {
|
||||
value = items[i].json[field as string];
|
||||
value = items[i].json[field];
|
||||
}
|
||||
prev = { ...prev, [field as string]: value };
|
||||
prev = { ...prev, [field]: value };
|
||||
return prev;
|
||||
}, {}),
|
||||
};
|
||||
@@ -843,7 +843,7 @@ return 0;`,
|
||||
} else {
|
||||
newItem = {
|
||||
...newItem,
|
||||
[(destinationFieldName as string) || (fieldToSplitOut as string)]: element,
|
||||
[destinationFieldName || fieldToSplitOut]: element,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -888,7 +888,7 @@ return 0;`,
|
||||
description: 'Please add a field to aggregate',
|
||||
});
|
||||
}
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
if (get(item.json, fieldToAggregate) !== undefined) {
|
||||
found = true;
|
||||
}
|
||||
@@ -896,7 +896,7 @@ return 0;`,
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (found === false && disableDotNotation && fieldToAggregate.includes('.')) {
|
||||
if (!found && disableDotNotation && fieldToAggregate.includes('.')) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Couldn't find the field '${fieldToAggregate}' in the input data`,
|
||||
@@ -904,7 +904,7 @@ return 0;`,
|
||||
description: `If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options`,
|
||||
},
|
||||
);
|
||||
} else if (found === false && keepMissing === false) {
|
||||
} else if (!found && !keepMissing) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Couldn't find the field '${fieldToAggregate}' in the input data`,
|
||||
@@ -912,8 +912,7 @@ return 0;`,
|
||||
}
|
||||
}
|
||||
|
||||
let newItem: INodeExecutionData;
|
||||
newItem = {
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: Array.from({ length }, (_, i) => i).map((index) => {
|
||||
return {
|
||||
@@ -939,7 +938,7 @@ return 0;`,
|
||||
}
|
||||
|
||||
const getFieldToAggregate = () =>
|
||||
disableDotNotation === false && fieldToAggregate.includes('.')
|
||||
!disableDotNotation && fieldToAggregate.includes('.')
|
||||
? fieldToAggregate.split('.').pop()
|
||||
: fieldToAggregate;
|
||||
|
||||
@@ -950,12 +949,12 @@ return 0;`,
|
||||
if (fieldToAggregate !== '') {
|
||||
values[_outputFieldName] = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
let value = get(items[i].json, fieldToAggregate);
|
||||
|
||||
if (!keepMissing) {
|
||||
if (Array.isArray(value)) {
|
||||
value = value.filter((value) => value !== null);
|
||||
value = value.filter((entry) => entry !== null);
|
||||
} else if (value === null || value === undefined) {
|
||||
continue;
|
||||
}
|
||||
@@ -971,7 +970,7 @@ return 0;`,
|
||||
|
||||
if (!keepMissing) {
|
||||
if (Array.isArray(value)) {
|
||||
value = value.filter((value) => value !== null);
|
||||
value = value.filter((entry) => entry !== null);
|
||||
} else if (value === null || value === undefined) {
|
||||
continue;
|
||||
}
|
||||
@@ -988,7 +987,7 @@ return 0;`,
|
||||
}
|
||||
|
||||
for (const key of Object.keys(values)) {
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
set(newItem.json, key, values[key]);
|
||||
} else {
|
||||
newItem.json[key] = values[key];
|
||||
@@ -1074,7 +1073,7 @@ return 0;`,
|
||||
'No fields specified. Please add a field to exclude from comparison',
|
||||
);
|
||||
}
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
keys = Object.keys(flattenKeys(items[0].json));
|
||||
}
|
||||
keys = keys.filter((key) => !fieldsToExclude.includes(key));
|
||||
@@ -1089,7 +1088,7 @@ return 0;`,
|
||||
'No fields specified. Please add a field to compare on',
|
||||
);
|
||||
}
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
keys = Object.keys(flattenKeys(items[0].json));
|
||||
}
|
||||
keys = fieldsToCompare.map((key) => key.trim());
|
||||
@@ -1100,7 +1099,7 @@ return 0;`,
|
||||
const newItems = items.map(
|
||||
(item, index) =>
|
||||
({
|
||||
json: { ...item['json'], __INDEX: index },
|
||||
json: { ...item.json, __INDEX: index },
|
||||
pairedItem: { item: index },
|
||||
} as INodeExecutionData),
|
||||
);
|
||||
@@ -1110,14 +1109,14 @@ return 0;`,
|
||||
|
||||
for (const key of keys) {
|
||||
let equal;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
equal = isEqual(get(a.json, key), get(b.json, key));
|
||||
} else {
|
||||
equal = isEqual(a.json[key], b.json[key]);
|
||||
}
|
||||
if (!equal) {
|
||||
let lessThan;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
lessThan = lt(get(a.json, key), get(b.json, key));
|
||||
} else {
|
||||
lessThan = lt(a.json[key], b.json[key]);
|
||||
@@ -1203,7 +1202,7 @@ return 0;`,
|
||||
order: 'ascending' | 'descending';
|
||||
}>;
|
||||
|
||||
if (!sortFields || !sortFields.length) {
|
||||
if (!sortFields?.length) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'No sorting specified. Please add a field to sort by',
|
||||
@@ -1213,7 +1212,7 @@ return 0;`,
|
||||
for (const { fieldName } of sortFields) {
|
||||
let found = false;
|
||||
for (const item of items) {
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
if (get(item.json, fieldName) !== undefined) {
|
||||
found = true;
|
||||
}
|
||||
@@ -1221,7 +1220,7 @@ return 0;`,
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (found === false && disableDotNotation && fieldName.includes('.')) {
|
||||
if (!found && disableDotNotation && fieldName.includes('.')) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Couldn't find the field '${fieldName}' in the input data`,
|
||||
@@ -1229,7 +1228,7 @@ return 0;`,
|
||||
description: `If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options`,
|
||||
},
|
||||
);
|
||||
} else if (found === false) {
|
||||
} else if (!found) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Couldn't find the field '${fieldName}' in the input data`,
|
||||
@@ -1246,7 +1245,7 @@ return 0;`,
|
||||
let result = 0;
|
||||
for (const field of sortFieldsWithDirection) {
|
||||
let equal;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
const _a =
|
||||
typeof get(a.json, field.name) === 'string'
|
||||
? (get(a.json, field.name) as string).toLowerCase()
|
||||
@@ -1258,19 +1257,19 @@ return 0;`,
|
||||
equal = isEqual(_a, _b);
|
||||
} else {
|
||||
const _a =
|
||||
typeof a.json[field.name as string] === 'string'
|
||||
? (a.json[field.name as string] as string).toLowerCase()
|
||||
: a.json[field.name as string];
|
||||
typeof a.json[field.name] === 'string'
|
||||
? (a.json[field.name] as string).toLowerCase()
|
||||
: a.json[field.name];
|
||||
const _b =
|
||||
typeof b.json[field.name as string] === 'string'
|
||||
? (b.json[field.name as string] as string).toLowerCase()
|
||||
: b.json[field.name as string];
|
||||
typeof b.json[field.name] === 'string'
|
||||
? (b.json[field.name] as string).toLowerCase()
|
||||
: b.json[field.name];
|
||||
equal = isEqual(_a, _b);
|
||||
}
|
||||
|
||||
if (!equal) {
|
||||
let lessThan;
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
const _a =
|
||||
typeof get(a.json, field.name) === 'string'
|
||||
? (get(a.json, field.name) as string).toLowerCase()
|
||||
@@ -1282,13 +1281,13 @@ return 0;`,
|
||||
lessThan = lt(_a, _b);
|
||||
} else {
|
||||
const _a =
|
||||
typeof a.json[field.name as string] === 'string'
|
||||
? (a.json[field.name as string] as string).toLowerCase()
|
||||
: a.json[field.name as string];
|
||||
typeof a.json[field.name] === 'string'
|
||||
? (a.json[field.name] as string).toLowerCase()
|
||||
: a.json[field.name];
|
||||
const _b =
|
||||
typeof b.json[field.name as string] === 'string'
|
||||
? (b.json[field.name as string] as string).toLowerCase()
|
||||
: b.json[field.name as string];
|
||||
typeof b.json[field.name] === 'string'
|
||||
? (b.json[field.name] as string).toLowerCase()
|
||||
: b.json[field.name];
|
||||
lessThan = lt(_a, _b);
|
||||
}
|
||||
if (lessThan) {
|
||||
@@ -1305,7 +1304,7 @@ return 0;`,
|
||||
const code = this.getNodeParameter('code', 0) as string;
|
||||
const regexCheck = /\breturn\b/g.exec(code);
|
||||
|
||||
if (regexCheck && regexCheck.length) {
|
||||
if (regexCheck?.length) {
|
||||
const sandbox = {
|
||||
newItems,
|
||||
};
|
||||
@@ -1367,13 +1366,13 @@ const compareItems = (
|
||||
) => {
|
||||
let result = true;
|
||||
for (const key of keys) {
|
||||
if (disableDotNotation === false) {
|
||||
if (!disableDotNotation) {
|
||||
if (!isEqual(get(obj.json, key), get(obj2.json, key))) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!isEqual(obj.json[key as string], obj2.json[key as string])) {
|
||||
if (!isEqual(obj.json[key], obj2.json[key])) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
@@ -1382,10 +1381,10 @@ const compareItems = (
|
||||
return result;
|
||||
};
|
||||
|
||||
const flattenKeys = (obj: {}, path: string[] = []): {} => {
|
||||
const flattenKeys = (obj: IDataObject, path: string[] = []): IDataObject => {
|
||||
return !isObject(obj)
|
||||
? { [path.join('.')]: obj }
|
||||
: reduce(obj, (cum, next, key) => merge(cum, flattenKeys(next, [...path, key])), {});
|
||||
: reduce(obj, (cum, next, key) => merge(cum, flattenKeys(next as IDataObject, [...path, key])), {}); //prettier-ignore
|
||||
};
|
||||
|
||||
const shuffleArray = (array: any[]) => {
|
||||
|
||||
Reference in New Issue
Block a user