Skip to content

Commit

Permalink
MM-61893 Replace usage of hasOwnProperty with Object.hasOwn (mattermo…
Browse files Browse the repository at this point in the history
…st#29428)

* MM-61893 Replace usage of hasOwnProperty with Object.hasOwn

* Update type guard in messageToElement

* Replace a couple more hasOwnProperty calls
  • Loading branch information
hmhealey authored Dec 3, 2024
1 parent 3ed209a commit 8533350
Show file tree
Hide file tree
Showing 38 changed files with 69 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/tests/support/api/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/tests/utils/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
Expand Down
34 changes: 17 additions & 17 deletions webapp/channels/build/emoji/make_emojis.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/status_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function loadStatusesForProfilesMap(users: Record<string, UserProfile> |

const statusesToLoad = [];
for (const userId in users) {
if ({}.hasOwnProperty.call(users, userId)) {
if (Object.hasOwn(users, userId)) {
statusesToLoad.push(userId);
}
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<FormattedMessage
id={(x as Message).id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ export default class DataPrefetch extends React.PureComponent<Props> {
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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -133,7 +133,7 @@ export default function ResultTable(props: Props) {
if (isGuest(user.roles)) {
guestBadge = <GuestTag/>;
}
} else if (invitation.hasOwnProperty('email')) {
} else if (Object.hasOwn(invitation, 'email')) {
const email = (invitation as InviteEmail).email;
reactKey = email;
className = 'email';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<PostMessageView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ModalController = ({
const modalOutput = [];

for (const modalId in modalState) {
if (modalState.hasOwnProperty(modalId)) {
if (Object.hasOwn(modalState, modalId)) {
const modal = modalState[modalId];
if (modal.open) {
const modalComponent = React.createElement(modal.dialogType, Object.assign({}, modal.dialogProps, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class PostMessageView extends React.PureComponent<Props, State> {

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 (
<PluginComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ProfilePopover = ({

const handleCloseModals = useCallback(() => {
for (const modal in modals?.modalState) {
if (!Object.prototype.hasOwnProperty.call(modals, modal)) {
if (!Object.hasOwn(modals, modal)) {
continue;
}
if (modals?.modalState[modal].open) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/components/rhs_card/rhs_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class RhsCard extends React.Component<Props, State> {
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 = <PluginComponent post={selected}/>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/components/system_notice/notices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class ThemeSetting extends React.PureComponent<Props, State> {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function teams(state: IDMappedObjects<Team> = {}, 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;
}
Expand Down Expand Up @@ -352,7 +352,7 @@ function membersInTeam(state: RelationOneToOne<Team, RelationOneToOne<UserProfil
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;
}
Expand Down Expand Up @@ -381,7 +381,7 @@ function stats(state: any = {}, 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function handleUploadFilesRequest(
let error = action.error;

if (error instanceof Error) {
error = error.hasOwnProperty('intl') ? {...error} : error.toString();
error = Object.hasOwn(error, 'intl') ? {...error} : error.toString();
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export const getMyChannels: (state: GlobalState) => Channel[] = createSelector(
getAllDirectChannels,
getMyChannelMemberships,
(channels: Channel[], directChannels: Channel[], myMembers: RelationOneToOne<Channel, ChannelMembership>): Channel[] => {
return [...channels, ...directChannels].filter((c) => myMembers.hasOwnProperty(c.id));
return [...channels, ...directChannels].filter((c) => Object.hasOwn(myMembers, c.id));
},
);

Expand All @@ -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<Channel, ChannelMembership>, 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));
},
);

Expand Down
Loading

0 comments on commit 8533350

Please sign in to comment.