From 15c19e70aba986e01b2cb0cb4a7bc3ffd36d08b0 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 8 Jan 2025 14:24:41 +0700 Subject: [PATCH 1/4] fix: Allow private_ prefix lint rule for variable naming --- .eslintrc.js | 4 ++++ src/libs/DebugUtils.ts | 1 - src/libs/OptionsListUtils.ts | 1 - src/libs/SidebarUtils.ts | 2 -- src/libs/actions/Policy/Policy.ts | 2 -- src/pages/home/ReportScreen.tsx | 1 - src/types/form/DebugReportForm.ts | 1 - src/types/onyx/Report.ts | 1 - src/types/onyx/ReportNameValuePairs.ts | 1 - src/types/onyx/SearchResults.ts | 1 - src/types/utils/whitelistedReportKeys.ts | 1 - tests/data/Invoice.ts | 1 - tests/ui/LHNItemsPresence.tsx | 2 -- tests/unit/DebugUtilsTest.ts | 2 -- tests/unit/OptionsListUtilsTest.ts | 1 - tests/unit/ReportUtilsTest.ts | 3 --- tests/unit/SidebarOrderTest.ts | 2 -- tests/unit/SidebarTest.ts | 2 -- tests/utils/collections/optionData.ts | 1 - 19 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fefad92ce29d..76db6b6560e9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -134,6 +134,10 @@ module.exports = { { selector: ['variable', 'property'], format: ['camelCase', 'UPPER_CASE', 'PascalCase'], + filter: { + regex: '^private_[a-z][a-zA-Z0-9]+$', + match: false, + }, }, { selector: 'function', diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 5824a79532bd..fc95f08148db 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -617,7 +617,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { fieldList: CONST.RED_BRICK_ROAD_PENDING_ACTION, permissions: CONST.RED_BRICK_ROAD_PENDING_ACTION, tripData: CONST.RED_BRICK_ROAD_PENDING_ACTION, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: CONST.RED_BRICK_ROAD_PENDING_ACTION, addWorkspaceRoom: CONST.RED_BRICK_ROAD_PENDING_ACTION, avatar: CONST.RED_BRICK_ROAD_PENDING_ACTION, diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 4d1988a53bde..81168d0c10e9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -670,7 +670,6 @@ function createOption( if (report) { result.isChatRoom = ReportUtils.isChatRoom(report); result.isDefaultRoom = ReportUtils.isDefaultRoom(report); - // eslint-disable-next-line @typescript-eslint/naming-convention result.private_isArchived = report.private_isArchived; result.isExpenseReport = ReportUtils.isExpenseReport(report); result.isInvoiceRoom = ReportUtils.isInvoiceRoom(report); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 626dc8d5ed68..c13042072fff 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -340,7 +340,6 @@ function getOptionData({ hasParentAccess: undefined, isIOUReportOwner: null, isChatRoom: false, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: undefined, shouldShowSubscript: false, isPolicyExpenseChat: false, @@ -363,7 +362,6 @@ function getOptionData({ result.isTaskReport = ReportUtils.isTaskReport(report); result.isInvoiceReport = ReportUtils.isInvoiceReport(report); result.parentReportAction = parentReportAction; - // eslint-disable-next-line @typescript-eslint/naming-convention result.private_isArchived = report?.private_isArchived; result.isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); result.isExpenseRequest = ReportUtils.isExpenseRequest(report); diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index f18fac18aca2..d72cf1c52837 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -346,7 +346,6 @@ function deleteWorkspace(policyID: string, policyName: string) { oldPolicyName: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.name ?? '', policyName: '', }), - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: currentTime, }, }); @@ -412,7 +411,6 @@ function deleteWorkspace(policyID: string, policyName: string) { statusNum, oldPolicyName, policyName: report?.policyName, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: null, }, }); diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 73fed14af87c..a3d07d384d56 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -221,7 +221,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro visibility: reportOnyx.visibility, oldPolicyName: reportOnyx.oldPolicyName, policyName: reportOnyx.policyName, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: reportOnyx.private_isArchived, lastMentionedTime: reportOnyx.lastMentionedTime, avatarUrl: reportOnyx.avatarUrl, diff --git a/src/types/form/DebugReportForm.ts b/src/types/form/DebugReportForm.ts index 203a75f39722..3d4ffec4bfa6 100644 --- a/src/types/form/DebugReportForm.ts +++ b/src/types/form/DebugReportForm.ts @@ -33,7 +33,6 @@ const INPUT_IDS = { POLICY_ID: 'policyID', POLICY_NAME: 'policyName', PRIVATE_NOTES: 'privateNotes', - // eslint-disable-next-line @typescript-eslint/naming-convention PRIVATE_IS_ARCHIVED: 'private_isArchived', REPORT_ID: 'reportID', REPORT_NAME: 'reportName', diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 1ce9a76306e9..f13090dffd6b 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -224,7 +224,6 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< }; /** Whether the report is archived */ - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived?: string; /** The report's welcome message */ diff --git a/src/types/onyx/ReportNameValuePairs.ts b/src/types/onyx/ReportNameValuePairs.ts index 8b5a50d8d5c8..9d2720c3b5f2 100644 --- a/src/types/onyx/ReportNameValuePairs.ts +++ b/src/types/onyx/ReportNameValuePairs.ts @@ -3,7 +3,6 @@ import type * as OnyxCommon from './OnyxCommon'; /** Model of additional report details */ type ReportNameValuePairs = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Whether the report is an archived room */ - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: boolean; }>; diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 513089ca60a8..e7690f10004b 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -150,7 +150,6 @@ type SearchReport = { unheldTotal?: number; /** Whether the report is archived */ - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived?: string; /** Whether the action is loading */ diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 8fa8aab7adc1..0c5a9ad2a95d 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -61,7 +61,6 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< endDate: unknown; tripID: unknown; }; - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: unknown; welcomeMessage: unknown; }, diff --git a/tests/data/Invoice.ts b/tests/data/Invoice.ts index c94c7ce816be..b2f12846d79c 100644 --- a/tests/data/Invoice.ts +++ b/tests/data/Invoice.ts @@ -265,7 +265,6 @@ const convertedInvoiceChat: OnyxTypes.Report = { policyAvatar: '', policyID: 'CC048FA711B35B1F', policyName: "53019's Workspace", - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: '', reportID: '7605647250932303', reportName: 'Chat Report', diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index a393ce691277..e183e958ea04 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -258,12 +258,10 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const archivedReport: Report = { ...createReport(false), - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; const reportNameValuePairs = { type: 'chat', - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: true, }; diff --git a/tests/unit/DebugUtilsTest.ts b/tests/unit/DebugUtilsTest.ts index ac15d041bc2f..3eefc46492ae 100644 --- a/tests/unit/DebugUtilsTest.ts +++ b/tests/unit/DebugUtilsTest.ts @@ -787,7 +787,6 @@ describe('DebugUtils', () => { await Onyx.set(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT); const reason = DebugUtils.getReasonForShowingRowInLHN({ ...baseReport, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: 'true', }); expect(reason).toBe('debug.reasonVisibleInLHN.isArchived'); @@ -1061,7 +1060,6 @@ describe('DebugUtils', () => { await Onyx.multiSet({ ...MOCK_REPORTS, [`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}2` as const]: { - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: false, }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1` as const]: MOCK_REPORT_ACTIONS, diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 6c0ad88619cb..f838952afce8 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -152,7 +152,6 @@ describe('OptionsListUtils', () => { // This indicates that the report is archived stateNum: 2, statusNum: 2, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }, }; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 259a470432b7..f1f62d711cd3 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -188,7 +188,6 @@ describe('ReportUtils', () => { ...baseAdminsRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; @@ -214,7 +213,6 @@ describe('ReportUtils', () => { ...baseUserCreatedRoom, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; @@ -260,7 +258,6 @@ describe('ReportUtils', () => { oldPolicyName: policy.name, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; diff --git a/tests/unit/SidebarOrderTest.ts b/tests/unit/SidebarOrderTest.ts index 55fd72173c65..d13d4415c2ce 100644 --- a/tests/unit/SidebarOrderTest.ts +++ b/tests/unit/SidebarOrderTest.ts @@ -832,7 +832,6 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; const report2 = LHNTestUtils.getFakeReport([1, 3]); @@ -984,7 +983,6 @@ describe('Sidebar', () => { statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, lastMessageText: 'test', - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), }; const report2 = { diff --git a/tests/unit/SidebarTest.ts b/tests/unit/SidebarTest.ts index a3ca6f4734e6..28d100062be3 100644 --- a/tests/unit/SidebarTest.ts +++ b/tests/unit/SidebarTest.ts @@ -47,7 +47,6 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; @@ -102,7 +101,6 @@ describe('Sidebar', () => { chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS_NUM.CLOSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: DateUtils.getDBTime(), lastMessageText: 'test', }; diff --git a/tests/utils/collections/optionData.ts b/tests/utils/collections/optionData.ts index adbb204cfc2d..28fa6ca87368 100644 --- a/tests/utils/collections/optionData.ts +++ b/tests/utils/collections/optionData.ts @@ -19,7 +19,6 @@ export default function createRandomOptionData(index: number): OptionData { policyName: randWord(), policyID: `policy_${index}`, accountID: randNumber(), - // eslint-disable-next-line @typescript-eslint/naming-convention private_isArchived: new Date().toISOString(), isPolicyExpenseChat: randBoolean(), chatType: rand(Object.values(CONST.REPORT.CHAT_TYPE)), From 7f38acc53b9e883dd237e0a0cf73cb9b01c62c84 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 8 Jan 2025 22:28:59 +0700 Subject: [PATCH 2/4] fix lint --- src/libs/OptionsListUtils.ts | 2 +- src/libs/SidebarUtils.ts | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 81168d0c10e9..77f0ea5188ef 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1158,7 +1158,7 @@ function getValidOptions( return ReportUtils.shouldReportBeInOptionList({ report, - currentReportId: topmostReportId, + currentReportId: topmostReportId ?? '', betas, policies, doesReportHaveViolations, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index c13042072fff..8ac64897fa5c 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -123,13 +123,13 @@ function getOrderedReportIDs( if ((Object.values(CONST.REPORT.UNSUPPORTED_TYPE) as string[]).includes(report?.type ?? '')) { return; } - const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID, report?.parentReportActionID); const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); const isHidden = ReportUtils.isHiddenForCurrentUser(report); const isFocused = report.reportID === currentReportId; const hasErrorsOtherThanFailedReceipt = ReportUtils.hasReportErrorsOtherThanFailedReceipt(report, doesReportHaveViolations, transactionViolations); const isReportInAccessible = report?.errorFields?.notFound; - if (ReportUtils.isOneTransactionThread(report.reportID, report.parentReportID ?? '0', parentReportAction)) { + if (ReportUtils.isOneTransactionThread(report.reportID, report.parentReportID, parentReportAction)) { return; } if (hasErrorsOtherThanFailedReceipt && !isReportInAccessible) { @@ -155,7 +155,7 @@ function getOrderedReportIDs( if ( ReportUtils.shouldReportBeInOptionList({ report, - currentReportId: currentReportId ?? '-1', + currentReportId: currentReportId ?? '', isInFocusMode, betas, policies: policies as OnyxCollection, @@ -200,13 +200,13 @@ function getOrderedReportIDs( }; const isPinned = report?.isPinned ?? false; - const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); + const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID, report?.parentReportActionID); const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID); if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { pinnedAndGBRReports.push(miniReport); } else if (report?.hasErrorsOtherThanFailedReceipt) { errorReports.push(miniReport); - } else if (hasValidDraftComment(report?.reportID ?? '-1')) { + } else if (hasValidDraftComment(report?.reportID)) { draftReports.push(miniReport); } else if (ReportUtils.isArchivedRoom(report, reportNameValuePairs)) { archivedReports.push(miniReport); @@ -239,7 +239,7 @@ function getOrderedReportIDs( // Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. // The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. - const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? '-1'); + const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? ''); Performance.markEnd(CONST.TIMING.GET_ORDERED_REPORT_IDS); return LHNReports; @@ -516,7 +516,7 @@ function getOptionData({ } if (!hasMultipleParticipants) { - result.accountID = personalDetail?.accountID ?? -1; + result.accountID = personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID; result.login = personalDetail?.login ?? ''; result.phoneNumber = personalDetail?.phoneNumber ?? ''; } @@ -527,7 +527,15 @@ function getOptionData({ result.subtitle = subtitle; result.participantsList = participantPersonalDetailList; - result.icons = ReportUtils.getIcons(report, personalDetails, personalDetail?.avatar, personalDetail?.login, personalDetail?.accountID ?? -1, policy, invoiceReceiverPolicy); + result.icons = ReportUtils.getIcons( + report, + personalDetails, + personalDetail?.avatar, + personalDetail?.login, + personalDetail?.accountID ?? CONST.DEFAULT_NUMBER_ID, + policy, + invoiceReceiverPolicy, + ); result.displayNamesWithTooltips = displayNamesWithTooltips; if (status) { From 1929db188b631ae8e4ff959ac6868074231ec087 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 8 Jan 2025 22:35:50 +0700 Subject: [PATCH 3/4] fix lint --- src/libs/SidebarUtils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 8ac64897fa5c..c80b76f62b4f 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -239,7 +239,12 @@ function getOrderedReportIDs( // Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. // The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. - const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report?.reportID ?? ''); + const LHNReports = [...pinnedAndGBRReports, ...errorReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => { + if (!report?.reportID) { + return ''; + } + return report?.reportID; + }); Performance.markEnd(CONST.TIMING.GET_ORDERED_REPORT_IDS); return LHNReports; @@ -383,7 +388,7 @@ function getOptionData({ result.iouReportID = report.iouReportID; result.keyForList = String(report.reportID); result.hasOutstandingChildRequest = report.hasOutstandingChildRequest; - result.parentReportID = report.parentReportID ?? '-1'; + result.parentReportID = report.parentReportID; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.notificationPreference = ReportUtils.getReportNotificationPreference(report); result.isAllowedToComment = ReportUtils.canUserPerformWriteAction(report); From c1eb41c6c291d3720593027c6c2ba9e4c8e07133 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 13 Jan 2025 10:29:04 +0700 Subject: [PATCH 4/4] fix lint --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b5a41eb7b585..1f8194b53a89 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1162,7 +1162,7 @@ function getValidOptions( return ReportUtils.shouldReportBeInOptionList({ report, - currentReportId: topmostReportId ?? '', + currentReportId: topmostReportId, betas, policies, doesReportHaveViolations,