From 8533350a91cda74d3d999595e25451200c59e4eb Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 3 Dec 2024 16:53:23 -0500 Subject: [PATCH] MM-61893 Replace usage of hasOwnProperty with Object.hasOwn (#29428) * MM-61893 Replace usage of hasOwnProperty with Object.hasOwn * Update type guard in messageToElement * Replace a couple more hasOwnProperty calls --- .../channels/plugins/upgrade_spec.js | 4 +-- e2e-tests/cypress/tests/support/api/system.js | 2 +- e2e-tests/cypress/tests/utils/benchmark.js | 2 +- e2e-tests/cypress/utils/file.js | 2 +- webapp/channels/build/emoji/make_emojis.mjs | 34 +++++++++---------- webapp/channels/src/actions/status_actions.ts | 2 +- .../src/actions/websocket_actions.jsx | 2 +- .../workspace_limits_panel.tsx | 2 +- .../data_prefetch/data_prefetch.tsx | 4 +-- .../invitation_modal/result_table.tsx | 4 +-- .../message_with_additional_content.tsx | 2 +- .../modal_controller/modal_controller.tsx | 2 +- .../post_message_view/post_message_view.tsx | 2 +- .../profile_popover/profile_popover.tsx | 2 +- .../src/components/rhs_card/rhs_card.tsx | 2 +- .../search_results/search_results.tsx | 4 +-- .../src/components/system_notice/notices.tsx | 2 +- .../premade_theme_chooser.tsx | 2 +- .../user_settings_theme.tsx | 2 +- .../src/actions/teams.test.ts | 2 +- .../mattermost-redux/src/actions/users.ts | 2 +- .../src/reducers/entities/scheduled_posts.ts | 8 ++--- .../src/reducers/entities/teams.ts | 6 ++-- .../src/reducers/requests/files.ts | 2 +- .../src/selectors/entities/channels.ts | 4 +-- .../src/selectors/entities/groups.ts | 6 ++-- .../src/selectors/entities/roles.ts | 4 +-- .../src/selectors/entities/users.ts | 2 +- .../mattermost-redux/src/utils/deep_freeze.ts | 4 +-- .../src/utils/integration_utils.ts | 2 +- .../mattermost-redux/src/utils/key_mirror.ts | 2 +- .../mattermost-redux/test/merge_objects.ts | 2 +- webapp/channels/src/plugins/index.js | 2 +- .../src/plugins/pluggable/pluggable.tsx | 2 +- .../src/reducers/views/marketplace.ts | 4 +-- .../src/utils/policy_roles_adapter.ts | 2 +- webapp/channels/src/utils/text_formatting.tsx | 2 +- .../eslint-plugin/configs/.eslintrc.json | 2 +- 38 files changed, 69 insertions(+), 69 deletions(-) diff --git a/e2e-tests/cypress/tests/integration/channels/plugins/upgrade_spec.js b/e2e-tests/cypress/tests/integration/channels/plugins/upgrade_spec.js index 47d021b63e2..9944a07dc0d 100644 --- a/e2e-tests/cypress/tests/integration/channels/plugins/upgrade_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/plugins/upgrade_spec.js @@ -152,11 +152,11 @@ function waitForServerStatus(pluginId, version, state = {}) { const checkFn = () => { cy.log(`Waiting for ${pluginId}`); return cy.apiGetPluginStatus(pluginId, version).then((status) => { - if (state.hasOwnProperty('isActive')) { + if (Object.hasOwn(state, 'isActive')) { return state.isActive === status.isActive; } - if (state.hasOwnProperty('isInstalled')) { + if (Object.hasOwn(state, 'isInstalled')) { return state.isInstalled === status.isInstalled; } diff --git a/e2e-tests/cypress/tests/support/api/system.js b/e2e-tests/cypress/tests/support/api/system.js index 9ed52194165..7e92df7d7f5 100644 --- a/e2e-tests/cypress/tests/support/api/system.js +++ b/e2e-tests/cypress/tests/support/api/system.js @@ -146,7 +146,7 @@ const expectConfigToBeUpdatable = (currentConfig, newConfig) => { if (setting) { Object.keys(newSubSetting).forEach((newSubKey) => { - const isAvailable = setting.hasOwnProperty(newSubKey); + const isAvailable = Object.hasOwn(setting, newSubKey); const name = `${newMainKey}.${newSubKey}`; expect(isAvailable, isAvailable ? `${name} setting can be updated.` : errorMessage(name)).to.equal(true); }); diff --git a/e2e-tests/cypress/tests/utils/benchmark.js b/e2e-tests/cypress/tests/utils/benchmark.js index b0305894d32..aa1ccb5012e 100644 --- a/e2e-tests/cypress/tests/utils/benchmark.js +++ b/e2e-tests/cypress/tests/utils/benchmark.js @@ -15,7 +15,7 @@ function getTestName() { const testTitles = []; function extractTitles(obj) { - if (obj.hasOwnProperty('parent')) { + if (Object.hasOwn(obj, 'parent')) { testTitles.push(obj.title); const nextObj = obj.parent; extractTitles(nextObj); diff --git a/e2e-tests/cypress/utils/file.js b/e2e-tests/cypress/utils/file.js index b29f1dc91a8..7de33bbce96 100644 --- a/e2e-tests/cypress/utils/file.js +++ b/e2e-tests/cypress/utils/file.js @@ -149,7 +149,7 @@ function removeFromFiles(files = {}, filesToRemove = []) { const removedFiles = intersection(Object.keys(testFilesObject), filesToRemove); removedFiles.forEach((file) => { - if (testFilesObject.hasOwnProperty(file)) { + if (Object.hasOwn(testFilesObject, file)) { delete testFilesObject[file]; } }); diff --git a/webapp/channels/build/emoji/make_emojis.mjs b/webapp/channels/build/emoji/make_emojis.mjs index 99a535a9ef4..85f65989bda 100755 --- a/webapp/channels/build/emoji/make_emojis.mjs +++ b/webapp/channels/build/emoji/make_emojis.mjs @@ -269,71 +269,71 @@ fullEmoji.forEach((emoji, index) => { }); function trimPropertiesFromEmoji(emoji) { - if (emoji.hasOwnProperty('non_qualified')) { + if (Object.hasOwn(emoji, 'non_qualified')) { Reflect.deleteProperty(emoji, 'non_qualified'); } - if (emoji.hasOwnProperty('docomo')) { + if (Object.hasOwn(emoji, 'docomo')) { Reflect.deleteProperty(emoji, 'docomo'); } - if (emoji.hasOwnProperty('au')) { + if (Object.hasOwn(emoji, 'au')) { Reflect.deleteProperty(emoji, 'au'); } - if (emoji.hasOwnProperty('softbank')) { + if (Object.hasOwn(emoji, 'softbank')) { Reflect.deleteProperty(emoji, 'softbank'); } - if (emoji.hasOwnProperty('google')) { + if (Object.hasOwn(emoji, 'google')) { Reflect.deleteProperty(emoji, 'google'); } - if (emoji.hasOwnProperty('sheet_x')) { + if (Object.hasOwn(emoji, 'sheet_x')) { Reflect.deleteProperty(emoji, 'sheet_x'); } - if (emoji.hasOwnProperty('sheet_y')) { + if (Object.hasOwn(emoji, 'sheet_y')) { Reflect.deleteProperty(emoji, 'sheet_y'); } - if (emoji.hasOwnProperty('added_in')) { + if (Object.hasOwn(emoji, 'added_in')) { Reflect.deleteProperty(emoji, 'added_in'); } - if (emoji.hasOwnProperty('has_img_apple')) { + if (Object.hasOwn(emoji, 'has_img_apple')) { Reflect.deleteProperty(emoji, 'has_img_apple'); } - if (emoji.hasOwnProperty('has_img_google')) { + if (Object.hasOwn(emoji, 'has_img_google')) { Reflect.deleteProperty(emoji, 'has_img_google'); } - if (emoji.hasOwnProperty('has_img_twitter')) { + if (Object.hasOwn(emoji, 'has_img_twitter')) { Reflect.deleteProperty(emoji, 'has_img_twitter'); } - if (emoji.hasOwnProperty('has_img_facebook')) { + if (Object.hasOwn(emoji, 'has_img_facebook')) { Reflect.deleteProperty(emoji, 'has_img_facebook'); } - if (emoji.hasOwnProperty('source_index')) { + if (Object.hasOwn(emoji, 'source_index')) { Reflect.deleteProperty(emoji, 'source_index'); } - if (emoji.hasOwnProperty('sort_order')) { + if (Object.hasOwn(emoji, 'sort_order')) { Reflect.deleteProperty(emoji, 'sort_order'); } - if (emoji.hasOwnProperty('subcategory')) { + if (Object.hasOwn(emoji, 'subcategory')) { Reflect.deleteProperty(emoji, 'subcategory'); } - if (emoji.hasOwnProperty('image')) { + if (Object.hasOwn(emoji, 'image')) { Reflect.deleteProperty(emoji, 'image'); } - if (emoji.hasOwnProperty('fileName')) { + if (Object.hasOwn(emoji, 'fileName')) { Reflect.deleteProperty(emoji, 'fileName'); } diff --git a/webapp/channels/src/actions/status_actions.ts b/webapp/channels/src/actions/status_actions.ts index 3935d3f413c..50acf2fad71 100644 --- a/webapp/channels/src/actions/status_actions.ts +++ b/webapp/channels/src/actions/status_actions.ts @@ -89,7 +89,7 @@ export function loadStatusesForProfilesMap(users: Record | const statusesToLoad = []; for (const userId in users) { - if ({}.hasOwnProperty.call(users, userId)) { + if (Object.hasOwn(users, userId)) { statusesToLoad.push(userId); } } diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index 7dfb6306ed0..57e3ff5fd03 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -636,7 +636,7 @@ export function handleEvent(msg) { return; } - if (pluginEvents.hasOwnProperty(msg.event) && typeof pluginEvents[msg.event] === 'function') { + if (Object.hasOwn(pluginEvents, msg.event) && typeof pluginEvents[msg.event] === 'function') { pluginEvents[msg.event](msg); } }); diff --git a/webapp/channels/src/components/cloud_usage_modal/workspace_limits_panel.tsx b/webapp/channels/src/components/cloud_usage_modal/workspace_limits_panel.tsx index 00c32ba0416..0fb3a4bdbb3 100644 --- a/webapp/channels/src/components/cloud_usage_modal/workspace_limits_panel.tsx +++ b/webapp/channels/src/components/cloud_usage_modal/workspace_limits_panel.tsx @@ -12,7 +12,7 @@ import {asGBString, inK} from 'utils/limits'; import LimitLine from './limit_line'; export function messageToElement(x: Message | React.ReactNode): React.ReactNode { - if (Object.prototype.hasOwnProperty.call(x, 'defaultMessage')) { + if (x && typeof x === 'object' && Object.hasOwn(x, 'defaultMessage')) { return ( { private prefetchData = () => { const {prefetchRequestStatus, prefetchQueueObj} = this.props; for (const priority in prefetchQueueObj) { - if (!prefetchQueueObj.hasOwnProperty(priority)) { + if (!Object.hasOwn(prefetchQueueObj, priority)) { continue; } const priorityQueue = prefetchQueueObj[priority]; for (const channelId of priorityQueue) { - if (!prefetchRequestStatus.hasOwnProperty(channelId)) { + if (!Object.hasOwn(prefetchRequestStatus, channelId)) { queue.add(async () => this.prefetchPosts(channelId)); } } diff --git a/webapp/channels/src/components/invitation_modal/result_table.tsx b/webapp/channels/src/components/invitation_modal/result_table.tsx index da634689660..55fc3e2b1cf 100644 --- a/webapp/channels/src/components/invitation_modal/result_table.tsx +++ b/webapp/channels/src/components/invitation_modal/result_table.tsx @@ -114,7 +114,7 @@ export default function ResultTable(props: Props) { let botBadge; let reactKey = ''; - if (invitation.hasOwnProperty('user')) { + if (Object.hasOwn(invitation, 'user')) { className = 'name'; const user = (invitation as InviteUser).user; reactKey = user.id; @@ -133,7 +133,7 @@ export default function ResultTable(props: Props) { if (isGuest(user.roles)) { guestBadge = ; } - } else if (invitation.hasOwnProperty('email')) { + } else if (Object.hasOwn(invitation, 'email')) { const email = (invitation as InviteEmail).email; reactKey = email; className = 'email'; diff --git a/webapp/channels/src/components/message_with_additional_content.tsx b/webapp/channels/src/components/message_with_additional_content.tsx index 585cb9735d3..0ddf79ca532 100644 --- a/webapp/channels/src/components/message_with_additional_content.tsx +++ b/webapp/channels/src/components/message_with_additional_content.tsx @@ -22,7 +22,7 @@ type Props = { } export default function MessageWithAdditionalContent({post, isEmbedVisible, pluginPostTypes, isRHS, compactDisplay}: Props) { - const hasPlugin = post.type && pluginPostTypes?.hasOwnProperty(post.type); + const hasPlugin = post.type && pluginPostTypes && Object.hasOwn(pluginPostTypes, post.type); let msg; const messageWrapper = ( { const postType = typeof post.props?.type === 'string' ? post.props.type : post.type; - if (pluginPostTypes && pluginPostTypes.hasOwnProperty(postType)) { + if (pluginPostTypes && Object.hasOwn(pluginPostTypes, postType)) { const PluginComponent = pluginPostTypes[postType].component; return ( { for (const modal in modals?.modalState) { - if (!Object.prototype.hasOwnProperty.call(modals, modal)) { + if (!Object.hasOwn(modals, modal)) { continue; } if (modals?.modalState[modal].open) { diff --git a/webapp/channels/src/components/rhs_card/rhs_card.tsx b/webapp/channels/src/components/rhs_card/rhs_card.tsx index 0f2b6cdc585..54187020102 100644 --- a/webapp/channels/src/components/rhs_card/rhs_card.tsx +++ b/webapp/channels/src/components/rhs_card/rhs_card.tsx @@ -122,7 +122,7 @@ export default class RhsCard extends React.Component { const {selected, pluginPostCardTypes, teamUrl} = this.props; const postType = selected.type; let content: ReactNode = null; - if (pluginPostCardTypes?.hasOwnProperty(postType)) { + if (pluginPostCardTypes && Object.hasOwn(pluginPostCardTypes, postType)) { const PluginComponent = pluginPostCardTypes[postType].component; content = ; } diff --git a/webapp/channels/src/components/search_results/search_results.tsx b/webapp/channels/src/components/search_results/search_results.tsx index 34abaa25197..52ff8002c8a 100644 --- a/webapp/channels/src/components/search_results/search_results.tsx +++ b/webapp/channels/src/components/search_results/search_results.tsx @@ -439,11 +439,11 @@ SearchResults.defaultProps = defaultProps; export const arePropsEqual = (props: Props, nextProps: Props): boolean => { // Shallow compare for all props except 'results' and 'fileResults' for (const key in nextProps) { - if (!Object.prototype.hasOwnProperty.call(nextProps, key) || key === 'results') { + if (!Object.hasOwn(nextProps, key) || key === 'results') { continue; } - if (!Object.prototype.hasOwnProperty.call(nextProps, key) || key === 'fileResults') { + if (!Object.hasOwn(nextProps, key) || key === 'fileResults') { continue; } diff --git a/webapp/channels/src/components/system_notice/notices.tsx b/webapp/channels/src/components/system_notice/notices.tsx index d4415fad292..c3331113c97 100644 --- a/webapp/channels/src/components/system_notice/notices.tsx +++ b/webapp/channels/src/components/system_notice/notices.tsx @@ -127,7 +127,7 @@ const notices: Notice[] = [ const USERS_THRESHOLD = 10000; // If we don't have the analytics yet, don't show - if (!analytics?.hasOwnProperty('TOTAL_USERS')) { + if (!analytics || Object.hasOwn(analytics, 'TOTAL_USERS')) { return false; } diff --git a/webapp/channels/src/components/user_settings/display/user_settings_theme/premade_theme_chooser/premade_theme_chooser.tsx b/webapp/channels/src/components/user_settings/display/user_settings_theme/premade_theme_chooser/premade_theme_chooser.tsx index 783819bab67..4bc77c3e4dc 100644 --- a/webapp/channels/src/components/user_settings/display/user_settings_theme/premade_theme_chooser/premade_theme_chooser.tsx +++ b/webapp/channels/src/components/user_settings/display/user_settings_theme/premade_theme_chooser/premade_theme_chooser.tsx @@ -22,7 +22,7 @@ const PremadeThemeChooser = ({theme, updateTheme, allowedThemes = []}: Props) => const hasAllowedThemes = allowedThemes.length > 1 || (allowedThemes[0] && allowedThemes[0].trim().length > 0); for (const k in Preferences.THEMES) { - if (Preferences.THEMES.hasOwnProperty(k)) { + if (Object.hasOwn(Preferences.THEMES, k)) { if (hasAllowedThemes && allowedThemes.indexOf(k) < 0) { continue; } diff --git a/webapp/channels/src/components/user_settings/display/user_settings_theme/user_settings_theme.tsx b/webapp/channels/src/components/user_settings/display/user_settings_theme/user_settings_theme.tsx index 88593c1d5c3..c9a6226e589 100644 --- a/webapp/channels/src/components/user_settings/display/user_settings_theme/user_settings_theme.tsx +++ b/webapp/channels/src/components/user_settings/display/user_settings_theme/user_settings_theme.tsx @@ -118,7 +118,7 @@ export default class ThemeSetting extends React.PureComponent { let themeChanged = this.state.theme.length === theme.length; if (!themeChanged) { for (const field in theme) { - if (theme.hasOwnProperty(field)) { + if (Object.hasOwn(theme, field)) { if (this.state.theme[field] !== theme[field]) { themeChanged = true; break; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts index ac95caac905..95d9a2f72e1 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts @@ -355,7 +355,7 @@ describe('Actions.Teams', () => { const member = members[TestHelper.basicTeam!.id]; expect(member).toBeTruthy(); - expect(Object.prototype.hasOwnProperty.call(member, 'mention_count')).toBeTruthy(); + expect(Object.hasOwn(member, 'mention_count')).toBeTruthy(); }); it('getTeamMembersForUser', async () => { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts index 6a4df7a39b9..4a38c6e3c3e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts @@ -405,7 +405,7 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFuncAsy const actions: AnyAction[] = []; for (const channelId in channelProfiles) { - if (channelProfiles.hasOwnProperty(channelId)) { + if (Object.hasOwn(channelProfiles, channelId)) { const profiles = channelProfiles[channelId]; actions.push( diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/scheduled_posts.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/scheduled_posts.ts index 2295a0e6944..c61608b4f1b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/scheduled_posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/scheduled_posts.ts @@ -15,7 +15,7 @@ function byId(state: ScheduledPostsState['byId'] = {}, action: AnyAction) { const newState = {...state}; Object.keys(scheduledPostsByTeamId).forEach((teamId: string) => { - if (scheduledPostsByTeamId.hasOwnProperty(teamId)) { + if (Object.hasOwn(scheduledPostsByTeamId, teamId)) { scheduledPostsByTeamId[teamId].forEach((scheduledPost: ScheduledPost) => { newState[scheduledPost.id] = scheduledPost; }); @@ -58,7 +58,7 @@ function byTeamId(state: ScheduledPostsState['byTeamId'] = {}, action: AnyAction const newState = {...state}; Object.keys(scheduledPostsByTeamId).forEach((teamId: string) => { - if (scheduledPostsByTeamId.hasOwnProperty(teamId)) { + if (Object.hasOwn(scheduledPostsByTeamId, teamId)) { newState[teamId] = scheduledPostsByTeamId[teamId].map((scheduledPost: ScheduledPost) => scheduledPost.id); } }); @@ -118,7 +118,7 @@ function errorsByTeamId(state: ScheduledPostsState['errorsByTeamId'] = {}, actio const newState = {...state}; Object.keys(scheduledPostsByTeamId).forEach((teamId: string) => { - if (scheduledPostsByTeamId.hasOwnProperty(teamId)) { + if (Object.hasOwn(scheduledPostsByTeamId, teamId)) { const teamScheduledPosts = scheduledPostsByTeamId[teamId] as ScheduledPost[]; newState[teamId] = teamScheduledPosts.filter((scheduledPost) => scheduledPost.error_code).map((scheduledPost) => scheduledPost.id); } @@ -179,7 +179,7 @@ function byChannelOrThreadId(state: ScheduledPostsState['byChannelOrThreadId'] = const newState = {...state}; Object.keys(scheduledPostsByTeamId).forEach((teamId: string) => { - if (scheduledPostsByTeamId.hasOwnProperty(teamId)) { + if (Object.hasOwn(scheduledPostsByTeamId, teamId)) { scheduledPostsByTeamId[teamId].forEach((scheduledPost: ScheduledPost) => { const id = scheduledPost.root_id || scheduledPost.channel_id; diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/teams.ts index 43527826c83..e19045c501b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/teams.ts @@ -47,7 +47,7 @@ function teams(state: IDMappedObjects = {}, action: AnyAction) { case TeamTypes.RECEIVED_TEAM_DELETED: { const nextState = {...state}; const teamId = action.data.id; - if (nextState.hasOwnProperty(teamId)) { + if (Object.hasOwn(nextState, teamId)) { Reflect.deleteProperty(nextState, teamId); return nextState; } @@ -352,7 +352,7 @@ function membersInTeam(state: RelationOneToOne Channel[] = createSelector( getAllDirectChannels, getMyChannelMemberships, (channels: Channel[], directChannels: Channel[], myMembers: RelationOneToOne): Channel[] => { - return [...channels, ...directChannels].filter((c) => myMembers.hasOwnProperty(c.id)); + return [...channels, ...directChannels].filter((c) => Object.hasOwn(myMembers, c.id)); }, ); @@ -555,7 +555,7 @@ export const getOtherChannels: (state: GlobalState, archived?: boolean | null) = getMyChannelMemberships, (state: GlobalState, archived: boolean | undefined | null = true) => archived, (channels: Channel[], myMembers: RelationOneToOne, archived?: boolean | null): Channel[] => { - return channels.filter((c) => !myMembers.hasOwnProperty(c.id) && c.type === General.OPEN_CHANNEL && (archived ? true : c.delete_at === 0)); + return channels.filter((c) => !Object.hasOwn(myMembers, c.id) && c.type === General.OPEN_CHANNEL && (archived ? true : c.delete_at === 0)); }, ); diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/groups.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/groups.ts index 87c93c9e79d..44c7cd9c1ec 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/groups.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/groups.ts @@ -41,7 +41,7 @@ export const getAllGroupsByName: (state: GlobalState) => Record = const groupsByName: Record = {}; for (const id in groups) { - if (groups.hasOwnProperty(id)) { + if (Object.hasOwn(groups, id)) { const group = groups[id]; groupsByName[group.name] = group; } @@ -140,7 +140,7 @@ export const getAssociatedGroupsByName: (state: GlobalState, teamID: string, cha const groupsByName: Record = {}; for (const id in groups) { - if (groups.hasOwnProperty(id)) { + if (Object.hasOwn(groups, id)) { const group = groups[id]; groupsByName[group.name] = group; } @@ -271,7 +271,7 @@ export const getAllGroupsForReferenceByName: (state: GlobalState) => Record = {}; for (const id in groups) { - if (groups.hasOwnProperty(id)) { + if (Object.hasOwn(groups, id)) { const group = groups[id]; groupsByName[group.name] = group; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/roles.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/roles.ts index ea0a709e063..5a0f8c2e953 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/roles.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/roles.ts @@ -40,7 +40,7 @@ export const getMyGroupRoles: (state: GlobalState) => Record const roles: Record> = {}; if (groupMemberships) { for (const key in groupMemberships) { - if (groupMemberships.hasOwnProperty(key) && groupMemberships[key].roles) { + if (Object.hasOwn(groupMemberships, key) && groupMemberships[key].roles) { roles[key] = new Set(groupMemberships[key].roles.split(' ')); } } @@ -98,7 +98,7 @@ export const getMyTeamRoles: (state: GlobalState) => Record> const roles: Record> = {}; if (teamsMemberships) { for (const key in teamsMemberships) { - if (teamsMemberships.hasOwnProperty(key) && teamsMemberships[key].roles) { + if (Object.hasOwn(teamsMemberships, key) && teamsMemberships[key].roles) { roles[key] = new Set(teamsMemberships[key].roles.split(' ')); } } diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/users.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/users.ts index 1c046813d28..69de654f674 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/users.ts @@ -104,7 +104,7 @@ export const getUsersByUsername: (a: GlobalState) => Record const usersByUsername: Record = {}; for (const id in users) { - if (users.hasOwnProperty(id)) { + if (Object.hasOwn(users, id)) { const user = users[id]; usersByUsername[user.username] = user; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/deep_freeze.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/deep_freeze.ts index 1c2593fae6a..67209265862 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/deep_freeze.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/deep_freeze.ts @@ -36,7 +36,7 @@ export default function deepFreezeAndThrowOnMutation(object: any): any { } for (const key in object) { - if (object.hasOwnProperty(key)) { + if (Object.hasOwn(object, key)) { object.__defineGetter__(key, identity.bind(null, object[key])); // eslint-disable-line no-underscore-dangle object.__defineSetter__(key, throwOnImmutableMutation.bind(null, key)); // eslint-disable-line no-underscore-dangle } @@ -46,7 +46,7 @@ export default function deepFreezeAndThrowOnMutation(object: any): any { Object.seal(object); for (const key in object) { - if (object.hasOwnProperty(key)) { + if (Object.hasOwn(object, key)) { deepFreezeAndThrowOnMutation(object[key]); } } diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/integration_utils.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/integration_utils.ts index e0751d793df..a4e8724662b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/integration_utils.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/integration_utils.ts @@ -72,7 +72,7 @@ export function checkDialogElementForError(elem: DialogElement, value: any): Dia export function checkIfErrorsMatchElements(errors: Record = {}, elements: DialogElement[] = []) { for (const name in errors) { - if (!errors.hasOwnProperty(name)) { + if (!Object.hasOwn(errors, name)) { continue; } for (const elem of elements) { diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/key_mirror.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/key_mirror.ts index 92c2bbf8111..84b585e2030 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/key_mirror.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/key_mirror.ts @@ -34,7 +34,7 @@ export default function keyMirror>(obj: T): { const ret: any = {}; for (const key in obj) { - if (!obj.hasOwnProperty(key)) { + if (!Object.hasOwn(obj, key)) { continue; } diff --git a/webapp/channels/src/packages/mattermost-redux/test/merge_objects.ts b/webapp/channels/src/packages/mattermost-redux/test/merge_objects.ts index c810de66a87..6efaf767a5f 100644 --- a/webapp/channels/src/packages/mattermost-redux/test/merge_objects.ts +++ b/webapp/channels/src/packages/mattermost-redux/test/merge_objects.ts @@ -38,7 +38,7 @@ export default function mergeObjects(a: Record, b: Record { - if (!newManifests.hasOwnProperty(id)) { + if (!Object.hasOwn(newManifests, id)) { const oldManifest = oldManifests[id]; removePlugin(oldManifest); } diff --git a/webapp/channels/src/plugins/pluggable/pluggable.tsx b/webapp/channels/src/plugins/pluggable/pluggable.tsx index 3e0523e432a..dd4a12475e8 100644 --- a/webapp/channels/src/plugins/pluggable/pluggable.tsx +++ b/webapp/channels/src/plugins/pluggable/pluggable.tsx @@ -64,7 +64,7 @@ export default function Pluggable(props: Props): JSX.Element | null { ...otherProps } = props; - if (!pluggableName || !Object.hasOwnProperty.call(components, pluggableName)) { + if (!pluggableName || !Object.hasOwn(components, pluggableName)) { return null; } diff --git a/webapp/channels/src/reducers/views/marketplace.ts b/webapp/channels/src/reducers/views/marketplace.ts index 480c5527aa2..31798e2e578 100644 --- a/webapp/channels/src/reducers/views/marketplace.ts +++ b/webapp/channels/src/reducers/views/marketplace.ts @@ -65,7 +65,7 @@ function installing(state: {[id: string]: boolean} = {}, action: AnyAction): {[i case ActionTypes.INSTALLING_MARKETPLACE_ITEM_SUCCEEDED: case ActionTypes.INSTALLING_MARKETPLACE_ITEM_FAILED: { - if (!Object.prototype.hasOwnProperty.call(state, action.id)) { + if (!Object.hasOwn(state, action.id)) { return state; } @@ -100,7 +100,7 @@ function errors(state: {[id: string]: string} = {}, action: AnyAction): {[id: st case ActionTypes.INSTALLING_MARKETPLACE_ITEM_SUCCEEDED: case ActionTypes.INSTALLING_MARKETPLACE_ITEM: { - if (!Object.prototype.hasOwnProperty.call(state, action.id)) { + if (!Object.hasOwn(state, action.id)) { return state; } diff --git a/webapp/channels/src/utils/policy_roles_adapter.ts b/webapp/channels/src/utils/policy_roles_adapter.ts index bfe538ccac7..487fbc4f79c 100644 --- a/webapp/channels/src/utils/policy_roles_adapter.ts +++ b/webapp/channels/src/utils/policy_roles_adapter.ts @@ -139,7 +139,7 @@ function roleNamesInMapping() { function* mappingPartIterator(mappingPart: Record, roles: Record) { for (const value in mappingPart) { - if (mappingPart.hasOwnProperty(value)) { + if (Object.hasOwn(mappingPart, value)) { const roleRules = mappingPart[value]; const hasUnmetCondition = roleRules.some((item: MappingValueTypes) => { diff --git a/webapp/channels/src/utils/text_formatting.tsx b/webapp/channels/src/utils/text_formatting.tsx index 7884ae20e8f..e1b52872537 100644 --- a/webapp/channels/src/utils/text_formatting.tsx +++ b/webapp/channels/src/utils/text_formatting.tsx @@ -565,7 +565,7 @@ export function autolinkChannelMentions( team?: Team, ) { function channelMentionExists(c: string) { - return channelNamesMap.hasOwnProperty(c); + return Object.hasOwn(channelNamesMap, c); } function addToken(channelName: string, teamName: string, mention: string, displayName: string) { const index = tokens.size; diff --git a/webapp/platform/eslint-plugin/configs/.eslintrc.json b/webapp/platform/eslint-plugin/configs/.eslintrc.json index ced8373a544..dfce6adb01a 100644 --- a/webapp/platform/eslint-plugin/configs/.eslintrc.json +++ b/webapp/platform/eslint-plugin/configs/.eslintrc.json @@ -370,7 +370,7 @@ "no-process-env": 2, "no-process-exit": 2, "no-proto": 2, - "no-prototype-builtins": 1, + "no-prototype-builtins": 2, "no-restricted-imports": [ "error", {