diff --git a/.editorconfig b/.editorconfig index 873e5bb4f..be3c34776 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ charset = utf-8 indent_style = space indent_size = 4 -[package.json] +[{package.json,.eslintrc.json}] indent_size = 2 [Makefile] diff --git a/.eslintrc.json b/.eslintrc.json index fb6c153b2..d703429d4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,219 +1,13 @@ { - "extends": [ - "eslint:recommended", - "plugin:flowtype/recommended" - ], - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true, - "impliedStrict": true, - "modules": true - } - }, - "parser": "babel-eslint", - "plugins": [ - "header", - "mocha", - "flowtype" - ], - "env": { - "browser": true, - "node": true, - "jquery": true, - "es6": true - }, - "globals": { - "jest": true, - "describe": true, - "it": true, - "expect": true, - "before": true, - "beforeEach": true, - "after": true, - "afterEach": true - }, - "rules": { - "array-bracket-spacing": [2, "never"], - "array-callback-return": 2, - "arrow-body-style": 0, - "arrow-parens": [2, "always"], - "arrow-spacing": [2, { "before": true, "after": true }], - "block-scoped-var": 2, - "brace-style": [2, "1tbs", { "allowSingleLine": false }], - "camelcase": [2, {"properties": "never"}], - "class-methods-use-this": 0, - "comma-dangle": [2, "always-multiline"], - "comma-spacing": [2, {"before": false, "after": true}], - "comma-style": [2, "last"], - "complexity": [0, 10], - "computed-property-spacing": [2, "never"], - "consistent-return": 2, - "consistent-this": [2, "self"], - "constructor-super": 2, - "curly": [2, "all"], - "dot-location": [2, "object"], - "dot-notation": 2, - "eqeqeq": [2, "smart"], - "func-call-spacing": [2, "never"], - "func-names": 2, - "func-style": [2, "declaration", { "allowArrowFunctions": true }], - "generator-star-spacing": [0, {"before": false, "after": true}], - "global-require": 2, - "guard-for-in": 2, - "header/header": [2, "line", " Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.\n See LICENSE.txt for license information."], - "id-blacklist": 0, - "indent": [2, 4, {"SwitchCase": 0, "CallExpression": {"arguments": 1}}], - "jsx-quotes": [2, "prefer-single"], - "key-spacing": [2, {"beforeColon": false, "afterColon": true, "mode": "strict"}], - "keyword-spacing": [2, {"before": true, "after": true, "overrides": {}}], - "line-comment-position": 0, - "linebreak-style": 2, - "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true, "allowBlockEnd": true }], - "max-lines": [1, {"max": 450, "skipBlankLines": true, "skipComments": false}], - "max-nested-callbacks": [2, {"max":2}], - "max-statements-per-line": [2, {"max": 1}], - "multiline-ternary": [1, "never"], - "new-cap": 2, - "new-parens": 2, - "newline-before-return": 0, - "newline-per-chained-call": 0, - "no-alert": 2, - "no-array-constructor": 2, - "no-caller": 2, - "no-case-declarations": 2, - "no-class-assign": 2, - "no-cond-assign": [2, "except-parens"], - "no-confusing-arrow": 2, - "no-console": 2, - "no-const-assign": 2, - "no-constant-condition": 2, - "no-debugger": 2, - "no-div-regex": 2, - "no-dupe-args": 2, - "no-dupe-class-members": 2, - "no-dupe-keys": 2, - "no-duplicate-case": 2, - "no-duplicate-imports": [2, {"includeExports": true}], - "no-else-return": 2, - "no-empty": 2, - "no-empty-function": 2, - "no-empty-pattern": 2, - "no-eval": 2, - "no-ex-assign": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-extra-label": 2, - "no-extra-parens": 0, - "no-extra-semi": 2, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-func-assign": 2, - "no-global-assign": 2, - "no-implicit-coercion": 2, - "no-implicit-globals": 0, - "no-implied-eval": 2, - "no-inner-declarations": 0, - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-iterator": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-lonely-if": 2, - "no-loop-func": 2, - "no-magic-numbers": 0, - "no-mixed-operators": [2, {"allowSamePrecedence": false}], - "no-mixed-spaces-and-tabs": 2, - "no-multi-spaces": [2, { "exceptions": { "Property": false } }], - "no-multi-str": 0, - "no-multiple-empty-lines": [2, {"max": 1}], - "no-native-reassign": 2, - "no-negated-condition": 2, - "no-nested-ternary": 2, - "no-new": 2, - "no-new-func": 2, - "no-new-object": 2, - "no-new-symbol": 2, - "no-new-wrappers": 2, - "no-octal-escape": 2, - "no-param-reassign": 2, - "no-process-env": 2, - "no-process-exit": 2, - "no-proto": 2, - "no-redeclare": 2, - "no-return-assign": [2, "always"], - "no-script-url": 2, - "no-self-assign": [2, {"props": true}], - "no-self-compare": 2, - "no-sequences": 2, - "no-shadow": [2, {"hoist": "functions"}], - "no-shadow-restricted-names": 2, - "no-spaced-func": 2, - "no-tabs": 0, - "no-template-curly-in-string": 2, - "no-ternary": 0, - "no-this-before-super": 2, - "no-throw-literal": 0, - "no-trailing-spaces": [2, { "skipBlankLines": false }], - "no-undef-init": 2, - "no-undefined": 2, - "no-underscore-dangle": 2, - "no-unexpected-multiline": 2, - "no-unmodified-loop-condition": 2, - "no-unneeded-ternary": [2, {"defaultAssignment": false}], - "no-unreachable": 2, - "no-unsafe-finally": 2, - "no-unsafe-negation": 2, - "no-unused-expressions": 2, - "no-unused-vars": [2, {"vars": "all", "args": "after-used"}], - "no-use-before-define": [2, {"classes": false, "functions": false, "variables": false}], - "no-useless-computed-key": 2, - "no-useless-concat": 2, - "no-useless-constructor": 2, - "no-useless-escape": 2, - "no-useless-rename": 2, - "no-var": 0, - "no-void": 2, - "no-warning-comments": 1, - "no-whitespace-before-property": 2, - "no-with": 2, - "object-curly-newline": 0, - "object-curly-spacing": [2, "never"], - "object-property-newline": [2, {"allowMultiplePropertiesPerLine": true}], - "object-shorthand": [2, "always"], - "one-var": [2, "never"], - "one-var-declaration-per-line": 0, - "operator-linebreak": [2, "after"], - "padded-blocks": [2, "never"], - "prefer-arrow-callback": 2, - "prefer-const": 2, - "prefer-numeric-literals": 2, - "prefer-reflect": 2, - "prefer-rest-params": 2, - "prefer-spread": 2, - "prefer-template": 0, - "quote-props": [2, "as-needed"], - "quotes": [2, "single", "avoid-escape"], - "radix": 2, - "require-yield": 2, - "rest-spread-spacing": [2, "never"], - "semi": [2, "always"], - "semi-spacing": [2, {"before": false, "after": true}], - "sort-imports": 0, - "sort-keys": 0, - "space-before-blocks": [2, "always"], - "space-before-function-paren": [2, {"anonymous": "never", "named": "never", "asyncArrow": "always"}], - "space-in-parens": [2, "never"], - "space-infix-ops": 2, - "space-unary-ops": [2, { "words": true, "nonwords": false }], - "symbol-description": 2, - "template-curly-spacing": [2, "never"], - "valid-typeof": [2, {"requireStringLiterals": false}], - "vars-on-top": 0, - "wrap-iife": [2, "outside"], - "wrap-regex": 2, - "yoda": [2, "never", {"exceptRange": false, "onlyEquality": false}], - "mocha/no-exclusive-tests": 2 - } + "extends": [ + "./node_modules/eslint-config-mattermost/.eslintrc.json", + "plugin:flowtype/recommended" + ], + "plugins": [ + "mocha", + "flowtype" + ], + "rules": { + "mocha/no-exclusive-tests": 2 + } } diff --git a/package-lock.json b/package-lock.json index 402e6243d..1a498e1bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "mattermost-redux", - "version": "1.2.0", + "version": "5.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2823,6 +2823,11 @@ } } }, + "eslint-config-mattermost": { + "version": "github:mattermost/eslint-config-mattermost#3ee77526c9c963877f3141b9c9090a236392bf82", + "from": "github:mattermost/eslint-config-mattermost", + "dev": true + }, "eslint-plugin-flowtype": { "version": "2.46.3", "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.46.3.tgz", diff --git a/package.json b/package.json index 09917db69..94653c6d6 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "chai": "4.1.2", "deep-freeze": "0.0.1", "eslint": "4.19.1", + "eslint-config-mattermost": "github:mattermost/eslint-config-mattermost", "eslint-plugin-flowtype": "2.46.3", "eslint-plugin-mocha": "5.0.0", "fetch-mock": "6.4.2", diff --git a/src/actions/admin.js b/src/actions/admin.js index 5c0dc7cca..9932f0ad1 100644 --- a/src/actions/admin.js +++ b/src/actions/admin.js @@ -90,7 +90,7 @@ export function updateConfig(config: Object): ActionFunc { if (config.SupportSettings && typeof config.SupportSettings === 'object') { Reflect.deleteProperty(config.SupportSettings, 'CustomTermsOfServiceText'); } - return await dispatch(bindClientFunc( + return dispatch(bindClientFunc( Client4.updateConfig, AdminTypes.UPDATE_CONFIG_REQUEST, [AdminTypes.RECEIVED_CONFIG, AdminTypes.UPDATE_CONFIG_SUCCESS], diff --git a/src/actions/emojis.js b/src/actions/emojis.js index 3642a8187..b6ba3286a 100644 --- a/src/actions/emojis.js +++ b/src/actions/emojis.js @@ -115,7 +115,7 @@ export function getCustomEmojisInText(text: string): ActionFunc { const emojisToLoad = parseNeededCustomEmojisFromText(text, systemEmojis, customEmojisByName, nonExistentEmoji); - return await getCustomEmojisByName(Array.from(emojisToLoad))(dispatch, getState); + return getCustomEmojisByName(Array.from(emojisToLoad))(dispatch, getState); }; } @@ -193,7 +193,7 @@ export function getAllCustomEmojis(perPage: number = General.PAGE_SIZE_MAXIMUM): do { try { let emojis = []; - emojis = await Client4.getCustomEmojis(page, perPage, Emoji.SORT_BY_NAME); + emojis = await Client4.getCustomEmojis(page, perPage, Emoji.SORT_BY_NAME); // eslint-disable-line no-await-in-loop if (emojis.length < perPage) { hasMore = false; } else { diff --git a/src/actions/posts.js b/src/actions/posts.js index 7e989cec0..733b8e121 100644 --- a/src/actions/posts.js +++ b/src/actions/posts.js @@ -449,7 +449,7 @@ export function getCustomEmojiForReaction(name) { return {data: true}; } - return await dispatch(getCustomEmojiByName(name)); + return dispatch(getCustomEmojiByName(name)); }; } @@ -525,7 +525,7 @@ export function flagPost(postId) { Client4.trackEvent('action', 'action_posts_flag'); - return await savePreferences(currentUserId, [preference])(dispatch, getState); + return savePreferences(currentUserId, [preference])(dispatch, getState); }; } @@ -1134,7 +1134,7 @@ export function unflagPost(postId) { Client4.trackEvent('action', 'action_posts_unflag'); - return await deletePreferences(currentUserId, [preference])(dispatch, getState); + return deletePreferences(currentUserId, [preference])(dispatch, getState); }; } diff --git a/src/actions/roles.js b/src/actions/roles.js index dcc3113ba..028324f3a 100644 --- a/src/actions/roles.js +++ b/src/actions/roles.js @@ -93,7 +93,7 @@ export function loadRolesIfNeeded(roles: Array): ActionFunc { await setPendingRoles([])(dispatch, getState); } if (newRoles.size > 0) { - return await getRolesByNames(Array.from(newRoles))(dispatch, getState); + return getRolesByNames(Array.from(newRoles))(dispatch, getState); } return {data: state.entities.roles.roles}; }; diff --git a/src/actions/search.js b/src/actions/search.js index ea309ade4..721a49e6e 100644 --- a/src/actions/search.js +++ b/src/actions/search.js @@ -94,8 +94,8 @@ export function getMorePostsForSearch() { const {params, isEnd} = getState().entities.search.current[teamId]; if (!isEnd) { const newParams = Object.assign({}, params); - newParams.page = newParams.page + 1; - return await searchPostsWithParams(teamId, newParams)(dispatch, getState); + newParams.page += 1; + return searchPostsWithParams(teamId, newParams)(dispatch, getState); } return {}; }; diff --git a/src/actions/users.js b/src/actions/users.js index 698392744..08e7aecb3 100644 --- a/src/actions/users.js +++ b/src/actions/users.js @@ -106,7 +106,7 @@ export function login(loginId, password, mfaToken = '', ldapOnly = false) { return {error}; } - return await completeLogin(data)(dispatch, getState); + return completeLogin(data)(dispatch, getState); }; } @@ -130,7 +130,7 @@ export function loginById(id, password, mfaToken = '') { return {error}; } - return await completeLogin(data)(dispatch, getState); + return completeLogin(data)(dispatch, getState); }; } @@ -316,7 +316,7 @@ export function getMissingProfilesByIds(userIds) { if (missingIds.length > 0) { getStatusesByIds(missingIds)(dispatch, getState); - return await getProfilesByIds(missingIds)(dispatch, getState); + return getProfilesByIds(missingIds)(dispatch, getState); } return {data: []}; @@ -340,7 +340,7 @@ export function getMissingProfilesByUsernames(usernames) { }); if (missingUsernames.length > 0) { - return await getProfilesByUsernames(missingUsernames)(dispatch, getState); + return getProfilesByUsernames(missingUsernames)(dispatch, getState); } return {data: []}; diff --git a/src/client/client4.js b/src/client/client4.js index f04994096..8cbf48317 100644 --- a/src/client/client4.js +++ b/src/client/client4.js @@ -16,6 +16,8 @@ const HEADER_X_VERSION_ID = 'X-Version-Id'; const PER_PAGE_DEFAULT = 60; const LOGS_PER_PAGE_DEFAULT = 10000; +/* eslint-disable no-throw-literal */ + export default class Client4 { constructor() { this.logToConsole = false; diff --git a/src/client/websocket_client.js b/src/client/websocket_client.js index 0c8114f3a..0e3b27f48 100644 --- a/src/client/websocket_client.js +++ b/src/client/websocket_client.js @@ -51,13 +51,13 @@ class WebSocketClient { if (connectionUrl == null) { console.log('websocket must have connection url'); //eslint-disable-line no-console - reject('websocket must have connection url'); + reject(new Error('websocket must have connection url')); return; } if (!dispatch) { console.log('websocket must have a dispatch'); //eslint-disable-line no-console - reject('websocket must have a dispatch'); + reject(new Error('websocket must have a dispatch')); return; } @@ -90,7 +90,7 @@ class WebSocketClient { // If we're unable to set the origin header, the websocket won't connect, but the URL is likely malformed anyway const errorMessage = 'websocket failed to parse origin from ' + connectionUrl; console.warn(errorMessage); // eslint-disable-line no-console - reject(errorMessage); + reject(new Error(errorMessage)); return; } diff --git a/src/selectors/entities/teams.js b/src/selectors/entities/teams.js index 45e0eefbc..a9d9d853d 100644 --- a/src/selectors/entities/teams.js +++ b/src/selectors/entities/teams.js @@ -219,8 +219,8 @@ export const getChannelDrawerBadgeCount = createSelector( let messageCount = 0; Object.values(teamMembers).forEach((m) => { if (m.team_id !== currentTeamId) { - mentionCount = mentionCount + (m.mention_count || 0); - messageCount = messageCount + (m.msg_count || 0); + mentionCount += (m.mention_count || 0); + messageCount += (m.msg_count || 0); } }); diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index ffa0ad3c3..000000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rules": { - "no-console": 0, - "global-require": 0, - "func-names": 0, - "prefer-arrow-callback": 0, - "no-magic-numbers": 0, - "no-unreachable": 0, - "new-cap": 0, - "max-nested-callbacks": 0, - "no-undefined": 0 - } -} diff --git a/test/actions/websocket.test.js b/test/actions/websocket.test.js index 4942adea5..88df9b370 100644 --- a/test/actions/websocket.test.js +++ b/test/actions/websocket.test.js @@ -17,6 +17,8 @@ import {PostTypes, TeamTypes, UserTypes, ChannelTypes} from 'action_types'; import TestHelper from 'test/test_helper'; import configureStore from 'test/test_store'; +const webSocketConnector = TestHelper.isLiveServer() ? require('ws') : MockWebSocket; + describe('Actions.Websocket', () => { let store; let mockServer; @@ -26,8 +28,7 @@ describe('Actions.Websocket', () => { const connUrl = (Client4.getUrl() + '/api/v4/websocket').replace(/^http:/, 'ws:'); mockServer = new Server(connUrl); - const webSocketConnector = TestHelper.isLiveServer() ? require('ws') : MockWebSocket; - return await Actions.init( + return Actions.init( 'web', null, null, diff --git a/test/utils/helpers.test.js b/test/utils/helpers.test.js index c127ede37..2f27fae49 100644 --- a/test/utils/helpers.test.js +++ b/test/utils/helpers.test.js @@ -36,8 +36,8 @@ describe('Helpers', () => { }); }); -describe('Utils.isEmail', function() { - it('', function() { +describe('Utils.isEmail', () => { + it('', () => { for (const data of [ { email: 'prettyandsimple@example.com',