From c7ef3fe1d396cc513e46c6d06ed0d8aa0d4384f7 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 20 May 2020 11:27:27 -0400 Subject: [PATCH] MM-22155 ESLint configuration updates part 1 (#4311) * MM-22155 Disable no-undefined * MM-22155 Disable react-jsx-filename-extension * MM-22155 Disable no-magic-numbers * MM-22155 Re-enable camelcase * MM-22155 Re-enable no-nested-ternary * Update no-unused-vars to match other repos --- .eslintrc.json | 21 ++++++++--- app/actions/device/index.js | 2 +- app/actions/websocket.test.js | 4 +- app/components/post_body/post_body.js | 8 ++-- app/components/post_header/index.js | 2 +- app/mm-redux/actions/posts.test.js | 12 +++--- app/mm-redux/actions/teams.ts | 6 +-- app/mm-redux/client/fetch_etag.ts | 2 +- app/mm-redux/index.ts | 13 ------- app/mm-redux/selectors/entities/groups.ts | 4 +- app/mm-redux/selectors/entities/index.ts | 46 ----------------------- app/mm-redux/selectors/index.ts | 7 ---- app/mm-redux/utils/index.ts | 46 ----------------------- app/styles/index.js | 3 -- app/utils/file.js | 2 +- app/utils/teams.test.js | 2 +- 16 files changed, 37 insertions(+), 143 deletions(-) delete mode 100644 app/mm-redux/index.ts delete mode 100644 app/mm-redux/selectors/entities/index.ts delete mode 100644 app/mm-redux/selectors/index.ts delete mode 100644 app/mm-redux/utils/index.ts diff --git a/.eslintrc.json b/.eslintrc.json index 4dc53db69..49a4fd1ba 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,14 +23,23 @@ }, "rules": { "global-require": 0, - "react/display-name": [2, { "ignoreTranspilerName": false }], - "react/jsx-filename-extension": [2, {"extensions": [".js"]}], "no-undefined": 0, - "no-nested-ternary": 0, - "@typescript-eslint/camelcase": 0, - "@typescript-eslint/no-undefined": 0, + "react/display-name": [2, { "ignoreTranspilerName": false }], + "react/jsx-filename-extension": 0, + "@typescript-eslint/camelcase": [ + 2, + { + "properties": "never" + } + ], "@typescript-eslint/no-non-null-assertion": 0, - "@typescript-eslint/no-unused-vars": 2, + "@typescript-eslint/no-unused-vars": [ + 2, + { + "vars": "all", + "args": "after-used" + } + ], "@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-use-before-define": 0, "@typescript-eslint/no-var-requires": 0, diff --git a/app/actions/device/index.js b/app/actions/device/index.js index 4fc3cf4bc..e72f2641b 100644 --- a/app/actions/device/index.js +++ b/app/actions/device/index.js @@ -6,7 +6,7 @@ import {DeviceTypes} from 'app/constants'; export function connection(isOnline) { return async (dispatch, getState) => { const state = getState(); - if (isOnline !== undefined && isOnline !== state.device.connection) { //eslint-disable-line no-undefined + if (isOnline !== undefined && isOnline !== state.device.connection) { dispatch({ type: DeviceTypes.CONNECTION_CHANGED, data: isOnline, diff --git a/app/actions/websocket.test.js b/app/actions/websocket.test.js index de7074da9..a81e5339a 100644 --- a/app/actions/websocket.test.js +++ b/app/actions/websocket.test.js @@ -21,7 +21,7 @@ import EventEmitter from '@mm-redux/utils/event_emitter'; import * as Actions from '@actions/websocket'; import {WebsocketEvents} from '@constants'; -import initial_state from '@store/initial_state'; +import globalInitialState from '@store/initial_state'; import TestHelper from 'test/test_helper'; import configureStore from 'test/test_store'; @@ -415,7 +415,7 @@ describe('Actions.Websocket', () => { it('Websocket Handle Channel Member Updated', async () => { const channelMember = TestHelper.basicChannelMember; const mockStore = configureMockStore([thunk]); - const st = mockStore(initial_state); + const st = mockStore(globalInitialState); await st.dispatch(Actions.init({websocketUrl: Client4.getUrl().replace(/^http:/, 'ws:')})); channelMember.roles = 'channel_user channel_admin'; const rolesToLoad = channelMember.roles.split(' '); diff --git a/app/components/post_body/post_body.js b/app/components/post_body/post_body.js index 139328621..7459e1448 100644 --- a/app/components/post_body/post_body.js +++ b/app/components/post_body/post_body.js @@ -202,12 +202,12 @@ export default class PostBody extends PureComponent { } const postId = postProps.add_channel_member.post_id; - const noGroupsUsernames = postProps.add_channel_member?.not_in_groups_usernames; - let userIds = postProps.add_channel_member?.not_in_channel_user_ids; - let usernames = postProps.add_channel_member?.not_in_channel_usernames; + const noGroupsUsernames = postProps.add_channel_member?.not_in_groups_usernames; // eslint-disable-line camelcase + let userIds = postProps.add_channel_member?.not_in_channel_user_ids; // eslint-disable-line camelcase + let usernames = postProps.add_channel_member?.not_in_channel_usernames; // eslint-disable-line camelcase if (!userIds) { - userIds = postProps.add_channel_member?.user_ids; + userIds = postProps.add_channel_member?.user_ids; // eslint-disable-line camelcase } if (!usernames) { usernames = postProps.add_channel_member?.usernames; diff --git a/app/components/post_header/index.js b/app/components/post_header/index.js index d6f465a1e..a419c4ab6 100644 --- a/app/components/post_header/index.js +++ b/app/components/post_header/index.js @@ -25,7 +25,7 @@ function makeMapStateToProps() { const config = getConfig(state); const post = ownProps.post; const commentedOnPost = ownProps.commentedOnPost; - const commentedOnUserId = commentedOnPost?.user_id; + const commentedOnUserId = commentedOnPost?.user_id; // eslint-disable-line camelcase const commentedOnUser = commentedOnUserId ? getUser(state, commentedOnUserId) : null; const user = getUser(state, post.user_id) || {}; const currentUser = getCurrentUser(state); diff --git a/app/mm-redux/actions/posts.test.js b/app/mm-redux/actions/posts.test.js index 824f00b66..f1b2c263a 100644 --- a/app/mm-redux/actions/posts.test.js +++ b/app/mm-redux/actions/posts.test.js @@ -296,7 +296,7 @@ describe('Actions.Posts', () => { const state = store.getState(); const {stats} = state.entities.channels; - const pinned_post_count = stats.channel1.pinnedpost_count; + const pinnedPostCount = stats.channel1.pinnedpost_count; expect(state.entities.posts.posts).toEqual({ post1, @@ -310,7 +310,7 @@ describe('Actions.Posts', () => { expect(state.entities.posts.postsInThread).toEqual({ post1: ['post4'], }); - expect(pinned_post_count).toEqual(1); + expect(pinnedPostCount).toEqual(1); }); it('removePostWithReaction', async () => { @@ -1174,11 +1174,11 @@ describe('Actions.Posts', () => { const state = getState(); const {stats} = state.entities.channels; const post = state.entities.posts.posts[post1.id]; - const pinned_post_count = stats[TestHelper.basicChannel.id].pinnedpost_count; + const pinnedPostCount = stats[TestHelper.basicChannel.id].pinnedpost_count; assert.ok(post); assert.ok(post.is_pinned === true); - assert.ok(pinned_post_count === 1); + assert.ok(pinnedPostCount === 1); }); it('unpinPost', async () => { @@ -1218,11 +1218,11 @@ describe('Actions.Posts', () => { const state = getState(); const {stats} = state.entities.channels; const post = state.entities.posts.posts[post1.id]; - const pinned_post_count = stats[TestHelper.basicChannel.id].pinnedpost_count; + const pinnedPostCount = stats[TestHelper.basicChannel.id].pinnedpost_count; assert.ok(post); assert.ok(post.is_pinned === false); - assert.ok(pinned_post_count === 0); + assert.ok(pinnedPostCount === 0); }); it('addReaction', async () => { diff --git a/app/mm-redux/actions/teams.ts b/app/mm-redux/actions/teams.ts index ff0fdcfac..a88ee70f4 100644 --- a/app/mm-redux/actions/teams.ts +++ b/app/mm-redux/actions/teams.ts @@ -473,9 +473,9 @@ export function addUsersToTeamGracefully(teamId: string, userIds: Array) return {error}; } - const added_members = result ? result.filter((m) => !m.error) : []; - const profiles: Partial[] = added_members.map((m) => ({id: m.user_id})); - const members = added_members.map((m) => m.member); + const addedMembers = result ? result.filter((m) => !m.error) : []; + const profiles: Partial[] = addedMembers.map((m) => ({id: m.user_id})); + const members = addedMembers.map((m) => m.member); dispatch(batchActions([ { type: UserTypes.RECEIVED_PROFILES_LIST_IN_TEAM, diff --git a/app/mm-redux/client/fetch_etag.ts b/app/mm-redux/client/fetch_etag.ts index e54cca396..90eddba28 100644 --- a/app/mm-redux/client/fetch_etag.ts +++ b/app/mm-redux/client/fetch_etag.ts @@ -34,5 +34,5 @@ export default ((url?: string, options: Options = {headers: {}}) => { } // all other requests go straight to fetch - return Reflect.apply(fetch, undefined, [url, options]); //eslint-disable-line no-undefined + return Reflect.apply(fetch, undefined, [url, options]); }); diff --git a/app/mm-redux/index.ts b/app/mm-redux/index.ts deleted file mode 100644 index a37ea728a..000000000 --- a/app/mm-redux/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -import * as action_types from './action_types'; -import * as actions from './actions'; -import * as client from './client'; -import * as constants from './constants'; -import * as reducers from './reducers'; -import * as selectors from './selectors'; -import * as types from './types'; -import * as utils from './utils'; - -export {action_types, actions, client, constants, reducers, selectors, types, utils}; diff --git a/app/mm-redux/selectors/entities/groups.ts b/app/mm-redux/selectors/entities/groups.ts index ab525c7a8..d7fba9e35 100644 --- a/app/mm-redux/selectors/entities/groups.ts +++ b/app/mm-redux/selectors/entities/groups.ts @@ -45,9 +45,9 @@ export function getGroupMembers(state: GlobalState, id: string) { return groupMemberData.members; } -const teamGroupIDs = (state: GlobalState, teamID: string) => (state.entities.teams.groupsAssociatedToTeam[teamID] == null ? undefined : state.entities.teams.groupsAssociatedToTeam[teamID].ids == null ? undefined : state.entities.teams.groupsAssociatedToTeam[teamID].ids) || []; +const teamGroupIDs = (state: GlobalState, teamID: string) => state.entities.teams.groupsAssociatedToTeam[teamID]?.ids || []; -const channelGroupIDs = (state: GlobalState, channelID: string) => (state.entities.channels.groupsAssociatedToChannel[channelID] == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids) || []; +const channelGroupIDs = (state: GlobalState, channelID: string) => state.entities.channels.groupsAssociatedToChannel[channelID]?.ids || []; const getTeamGroupIDSet = reselect.createSelector( teamGroupIDs, diff --git a/app/mm-redux/selectors/entities/index.ts b/app/mm-redux/selectors/entities/index.ts deleted file mode 100644 index e477d1259..000000000 --- a/app/mm-redux/selectors/entities/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -import * as bots from './bots'; -import * as channels from './channels'; -import * as common from './common'; -import * as emojis from './emojis'; -import * as files from './files'; -import * as general from './general'; -import * as groups from './groups'; -import * as i18n from './i18n'; -import * as integrations from './integrations'; -import * as jobs from './jobs'; -import * as posts from './posts'; -import * as preferences from './preferences'; -import * as roles_helpers from './roles_helpers'; -import * as roles from './roles'; -import * as schemes from './schemes'; -import * as search from './search'; -import * as teams from './teams'; -import * as timezone from './timezone'; -import * as typing from './typing'; -import * as users from './users'; - -export { - bots, - channels, - common, - emojis, - files, - general, - groups, - i18n, - integrations, - jobs, - posts, - preferences, - roles_helpers, - roles, - schemes, - search, - teams, - timezone, - typing, - users, -}; diff --git a/app/mm-redux/selectors/index.ts b/app/mm-redux/selectors/index.ts deleted file mode 100644 index 2a2f93334..000000000 --- a/app/mm-redux/selectors/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -import * as entities from './entities'; -import * as errors from './errors'; - -export {errors, entities}; diff --git a/app/mm-redux/utils/index.ts b/app/mm-redux/utils/index.ts deleted file mode 100644 index 52f502ff8..000000000 --- a/app/mm-redux/utils/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -import * as channel_utils from './channel_utils'; -import * as deep_freeze from './deep_freeze'; -import * as delayed_action from './delayed_action'; -import * as emoji_utils from './emoji_utils'; -import * as event_emitter from './event_emitter'; -import * as file_utils from './file_utils'; -import * as gfycat_sdk from './gfycat_sdk'; -import * as helpers from './helpers'; -import * as i18n_utils from './i18n_utils'; -import * as integration_utils from './integration_utils'; -import * as key_mirror from './key_mirror'; -import * as notify_props from './notify_props'; -import * as post_list from './post_list'; -import * as post_utils from './post_utils'; -import * as preference_utils from './preference_utils'; -import * as sentry from './sentry'; -import * as team_utils from './team_utils'; -import * as theme_utils from './theme_utils'; -import * as timezone_utils from './timezone_utils'; -import * as user_utils from './user_utils'; - -export { - channel_utils, - deep_freeze, - delayed_action, - emoji_utils, - event_emitter, - file_utils, - gfycat_sdk, - helpers, - i18n_utils, - integration_utils, - key_mirror, - notify_props, - post_list, - post_utils, - preference_utils, - sentry, - team_utils, - theme_utils, - timezone_utils, - user_utils, -}; diff --git a/app/styles/index.js b/app/styles/index.js index eeec07217..cb06b567e 100644 --- a/app/styles/index.js +++ b/app/styles/index.js @@ -1,9 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable -no-magic-numbers */ - import {StyleSheet} from 'react-native'; export const GlobalStyles = StyleSheet.create({ diff --git a/app/utils/file.js b/app/utils/file.js index 6756a78fe..083770c93 100644 --- a/app/utils/file.js +++ b/app/utils/file.js @@ -207,7 +207,7 @@ export function getExtensionFromMime(type) { function populateMaps() { // source preference (least -> most) - const preference = ['nginx', 'apache', undefined, 'iana']; //eslint-disable-line no-undefined + const preference = ['nginx', 'apache', undefined, 'iana']; Object.keys(mimeDB).forEach((type) => { const mime = mimeDB[type]; diff --git a/app/utils/teams.test.js b/app/utils/teams.test.js index 18bf8a9d0..002b7ef61 100644 --- a/app/utils/teams.test.js +++ b/app/utils/teams.test.js @@ -31,6 +31,6 @@ describe('selectFirstAvailableTeam', () => { it('should return undefined is no team is found', () => { const defaultTeam = selectFirstAvailableTeam([]); - expect(defaultTeam).toBe(undefined); //eslint-disable-line no-undefined + expect(defaultTeam).toBe(undefined); }); });