Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tslint rules enable #2604

Merged
merged 14 commits into from
Sep 29, 2023
Merged
40 changes: 21 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"unicorn/no-instanceof-array": "error",
"unicorn/no-static-only-class": "error",
"unicorn/consistent-destructuring": "off",
"unicorn/consistent-destructuring": "error",
"unicorn/better-regex": "error",
"unicorn/no-for-loop": "error",
"unicorn/prefer-array-some": "error",
Expand All @@ -40,29 +40,31 @@
"unicorn/no-useless-spread": "error",
"unicorn/no-useless-length-check": "error",
"unicorn/prefer-export-from": "error",
"import/no-dynamic-require": "warn",
"no-param-reassign": "warn",
"import/no-dynamic-require": "error",
"no-param-reassign": "error",
"sonarjs/prefer-immediate-return": "off",
"sonarjs/no-nested-template-literals": "off",
"sonarjs/max-switch-cases": "off",
"sonarjs/no-small-switch": "warn",
"sonarjs/max-switch-cases": "error",
"sonarjs/no-small-switch": "error",
"sonarjs/cognitive-complexity": ["error", 60],
"@typescript-eslint/no-var-requires": "off",
"global-require": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/ban-types": "off",
"global-require": "error",
"@typescript-eslint/naming-convention": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/no-explicit-any": "off",
"class-methods-use-this": "off",
"@typescript-eslint/return-await": "off",
"import/prefer-default-export": "off",
"sonarjs/no-ignored-return": "off",
"no-new": "off",
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-loop-func": "off",
"sonarjs/no-same-line-conditional": "off",
"no-restricted-syntax": "off",
"sonarjs/no-duplicate-string": "off",
"sonarjs/no-identical-functions": "off",
"@typescript-eslint/return-await": "error",
"import/prefer-default-export": "error",
"sonarjs/no-ignored-return": "error",
"no-new": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-loop-func": "error",
"sonarjs/no-same-line-conditional": "error",
"no-restricted-syntax": "error",
"sonarjs/no-duplicate-string": "error",
"sonarjs/no-identical-functions": "error",
"no-prototype-builtins": "off",
"@typescript-eslint/dot-notation": "off"
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/no-unused-vars": "error"
}
}
4 changes: 2 additions & 2 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-undef */

const _ = require('lodash');
const lodash = require('lodash');
const http = require('http');
const https = require('https');
const axios = require('axios');
Expand Down Expand Up @@ -227,7 +227,7 @@ const getPayloadData = (body) => {
let payload;
let payloadFormat;
Object.entries(body).forEach(([key, value]) => {
if (!_.isEmpty(value)) {
if (!lodash.isEmpty(value)) {
payload = value;
payloadFormat = key;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/utils/networkUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable eqeqeq */
const _ = require('lodash');
const lodash = require('lodash');
const { isEmpty } = require('lodash');
const {
isHttpStatusRetryable,
Expand Down Expand Up @@ -100,7 +100,7 @@
if (
!isDefinedAndNotNull(responseBody) ||
!isDefinedAndNotNull(status) ||
!_.isNumber(status) ||
!lodash.isNumber(status) ||

Check warning on line 103 in src/adapters/utils/networkUtils.js

View check run for this annotation

Codecov / codecov/patch

src/adapters/utils/networkUtils.js#L103

Added line #L103 was not covered by tests
status === 0
) {
throw new AbortedError(
Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v1/dcm_floodlight/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
const get = require('get-value');
const _ = require('lodash');
const lodash = require('lodash');
const {
removeUndefinedAndNullValues,
isDefinedAndNotNull,
Expand Down Expand Up @@ -44,7 +44,7 @@ const transformCustomVariable = (customFloodlightVariable, message) => {

if (
// the value is not null
!_.isNil(itemValue) &&
!lodash.isNil(itemValue) &&
// the value is string and doesn't have any blacklisted characters
!(
typeof itemValue === 'string' && BLACKLISTED_CHARACTERS.some((k) => itemValue.includes(k))
Expand Down
1 change: 1 addition & 0 deletions src/cdk/v1/new_relic/transform.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
const { isBoolean } = require('lodash');
const { Utils } = require('rudder-transformer-cdk');

Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/dcm_floodlight/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const lodash = require('lodash');
const { getValueFromPropertiesOrTraits, getHashFromArray } = require('../../../../v0/util');
const { GENERIC_TRUE_VALUES, GENERIC_FALSE_VALUES } = require('../../../../constants');
const { InstrumentationError } = require('../../../../v0/util/errorTypes');
Expand Down Expand Up @@ -35,7 +35,7 @@ const transformCustomVariable = (customFloodlightVariable, message) => {

if (
// the value is not null
!_.isNil(itemValue) &&
!lodash.isNil(itemValue) &&
// the value is string and doesn't have any blacklisted characters
!(
typeof itemValue === 'string' && BLACKLISTED_CHARACTERS.some((k) => itemValue.includes(k))
Expand Down
9 changes: 5 additions & 4 deletions src/cdk/v2/destinations/eloqua/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const stringifyValues = (data) => {
Object.keys(data).forEach((key) => {
if (typeof data[key] !== 'string') {
data[key] = JSON.stringify(data[key]);
const output = data;
Object.keys(output).forEach((key) => {
if (typeof output[key] !== 'string') {
output[key] = JSON.stringify(output[key]);
}
});
return data;
return output;
};
module.exports = {
stringifyValues,
Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/launchdarkly_audience/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const lodash = require('lodash');
const { ACTION_TYPES, IDENTIFIER_KEY, MAX_IDENTIFIERS } = require('./config');

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ const batchIdentifiersList = (listData) => {
...audienceList.remove.map((item) => ({ ...item, type: 'remove' })),
];

const chunkedData = _.chunk(combinedList, MAX_IDENTIFIERS);
const chunkedData = lodash.chunk(combinedList, MAX_IDENTIFIERS);

// Group the chunks by action type (add/remove)
const groupedData = chunkedData.map((chunk) => {
Expand Down
15 changes: 8 additions & 7 deletions src/cdk/v2/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ExecutionBindings,
StepOutput,
} from '@rudderstack/workflow-engine';
import { FixMe } from '../../util/types';

import tags from '../../v0/util/tags';

Expand All @@ -25,7 +26,7 @@
return {
outputs: {},
context,
setContext: (key: string, value: any) => {
setContext: (key: string, value: FixMe) => {

Check warning on line 29 in src/cdk/v2/handler.ts

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/handler.ts#L29

Added line #L29 was not covered by tests
context[key] = value;
},
};
Expand All @@ -34,7 +35,7 @@
export async function getWorkflowEngine(
destName: string,
feature: string,
bindings: Record<string, any> = {},
bindings: Record<string, FixMe> = {},
) {
const destRootDir = getRootPathForDestination(destName);
const workflowPath = await getWorkflowPath(destRootDir, feature);
Expand All @@ -52,7 +53,7 @@
export function getCachedWorkflowEngine(
destName: string,
feature: string,
bindings: Record<string, any> = {},
bindings: Record<string, unknown> = {},
): WorkflowEngine {
// Create a new instance of the engine for the destination if needed
// TODO: Use cache to avoid long living engine objects
Expand All @@ -63,7 +64,7 @@
return workflowEnginePromiseMap[destName][feature];
}

export async function executeWorkflow(workflowEngine: WorkflowEngine, parsedEvent: any) {
export async function executeWorkflow(workflowEngine: WorkflowEngine, parsedEvent: FixMe) {
try {
const result = await workflowEngine.execute(parsedEvent);
// TODO: Handle remaining output scenarios
Expand All @@ -75,9 +76,9 @@

export async function processCdkV2Workflow(
destType: string,
parsedEvent: any,
parsedEvent: FixMe,
feature: string,
bindings: Record<string, any> = {},
bindings: Record<string, FixMe> = {},
) {
try {
const workflowEngine = await getCachedWorkflowEngine(destType, feature, bindings);
Expand All @@ -90,7 +91,7 @@
export function executeStep(
workflowEngine: WorkflowEngine,
stepName: string,
input: any,
input: FixMe,
bindings?: ExecutionBindings,
): Promise<StepOutput> {
return workflowEngine
Expand Down
11 changes: 4 additions & 7 deletions src/cdk/v2/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'path';
import fs from 'fs/promises';
import {
WorkflowExecutionError,
WorkflowCreationError,
StatusError,
} from '@rudderstack/workflow-engine';
import { WorkflowExecutionError, WorkflowCreationError } from '@rudderstack/workflow-engine';
import logger from '../../logger';
import { generateErrorObject } from '../../v0/util';
import { PlatformError } from '../../v0/util/errorTypes';
import tags from '../../v0/util/tags';
import { CatchErr } from '../../util/types';

const CDK_V2_ROOT_DIR = __dirname;

Expand Down Expand Up @@ -83,15 +80,15 @@ export function getWorkflowEngineErrorMessage(err) {
* @param {*} defTags default stat tags
* @returns Error type object
*/
export function getErrorInfo(err: any, isProd: boolean, defTags) {
export function getErrorInfo(err: CatchErr, isProd: boolean, defTags) {
// Handle various CDK error types
const message = isProd ? getWorkflowEngineErrorMessage(err) : err.message;

if (err instanceof WorkflowExecutionError) {
logger.error(`Error occurred during workflow step execution: ${message}`, err);

// Determine the error instance
let errInstance: any = err;
let errInstance: CatchErr = err;
if (err.originalError) {
errInstance = err.originalError;
errInstance.message = message;
Expand Down
Loading