From 6d02c5a5280bfc0b1f4b50fdb739b6a3a4ba23b8 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:46:12 -0400 Subject: [PATCH] Some further ESLint cleanup, remove some unnecessary scripts and lines (#2984) --- .eslintignore | 6 +- .eslintrc.json | 83 +++++++++++++--------- .gitignore | 4 +- .vscode/settings.json | 2 +- babel.config.js | 2 +- e2e/.eslintrc.json | 18 ----- e2e/modules/environment.js | 1 - i18n/i18n.ts | 3 +- package.json | 2 +- scripts/.eslintrc.json | 5 -- scripts/extract_dict.js | 24 ------- scripts/manipulate_windows_zip.js | 33 --------- src/main/views/viewManager.test.js | 3 - src/main/windows/callsWidgetWindow.test.js | 2 - src/renderer/components/MainPage.tsx | 2 - webpack.config.base.js | 6 -- webpack.config.main.js | 6 -- webpack.config.performance.test.js | 6 -- webpack.config.preload.js | 6 -- webpack.config.renderer.js | 6 -- webpack.config.test.js | 6 -- 21 files changed, 60 insertions(+), 166 deletions(-) delete mode 100644 e2e/.eslintrc.json delete mode 100644 scripts/.eslintrc.json delete mode 100644 scripts/extract_dict.js delete mode 100644 scripts/manipulate_windows_zip.js diff --git a/.eslintignore b/.eslintignore index 66d14433..76add878 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,2 @@ -**/*_bundle.js -node_modules/ -release/ -src/node_modules/ +node_modules +dist \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index d410df0e..c5f1f087 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -27,10 +27,45 @@ "no-process-env": 0, "no-var": 2, "react/no-find-dom-node": 2, - "multiline-ternary": 0, - "max-lines": ["warn", 650], "no-underscore-dangle": ["warn"], - "@mattermost/use-external-link": 0 + "@mattermost/use-external-link": 0, + "import/order": [ + 2, + { + "newlines-between": "always", + "groups": [ + "builtin", + "external", + "internal", + "sibling", + "parent", + "index" + ], + "pathGroups": [ + { + "pattern": "@mattermost/**", + "group": "external", + "position": "after" + }, + { + "pattern": "(app|common|main|renderer){,/**}", + "group": "external", + "position": "after" + }, + { + "pattern": "types{,/**}", + "group": "internal", + "position": "after" + } + ], + "alphabetize": { + "order": "asc", + "caseInsensitive": true + }, + "distinctGroup": true, + "pathGroupsExcludedImportTypes": ["builtin"] + } + ] }, "overrides": [ { @@ -43,6 +78,16 @@ "no-console": 0 } }, + { + "files": [ + "scripts/**/*", + "babel.config.js", + "webpack.config.*.js" + ], + "rules": { + "import/no-commonjs": 0 + } + }, { "files": [ "e2e/**/*", @@ -52,13 +97,14 @@ "jest": true }, "rules": { - "babel/no-unused-expressions": "off", //TODO: rework tests to use correct notation + "no-unused-expressions": 0, //TODO: rework tests to use correct notation "func-names": 0, "global-require": 0, "new-cap": 0, "prefer-arrow-callback": 0, "no-import-assign": 0, - "no-only-tests/no-only-tests": "warn" + "no-only-tests/no-only-tests": 1, + "import/no-commonjs": 0 } }, { @@ -72,58 +118,31 @@ "webpack.config.base.js", "babel.config.js", "README.md", - "scripts/watch_main_and_preload.js", - "scripts/extract_dict.js", - "scripts/manipulate_windows_zip.js", "scripts/check_build_config.js", "LICENSE.txt", - "src/utils/util.ts", "src/main/contextMenu.ts", - "src/renderer/updater.tsx", "src/main/badge.ts", - "src/common/deepmerge.ts", "src/common/config/index.ts", "src/common/config/buildConfig.ts", "src/common/config/pastDefaultPreferences.ts", "src/common/config/upgradePreferences.ts", "src/common/config/RegistryConfig.ts", - "src/common/osVersion.ts", "src/common/config/defaultPreferences.ts", "src/common/JsonFileManager.ts", "src/main/certificateStore.ts", - "src/main/mainWindow.ts", "src/main/allowProtocolDialog.ts", - "src/main/permissionRequestHandler.ts", - "src/main/squirrelStartup.ts", - "src/main/autoLaunch.ts", - "src/main/PermissionManager.ts", "src/main/AutoLauncher.ts", - "src/main/AppStateManager.ts", "src/main/menus/tray.ts", "src/main/CriticalErrorHandler.ts", - "src/main/cookieManager.ts", "src/main/utils.ts", - "src/main/downloadURL.ts", - "src/main/SpellChecker.ts", "src/main/menus/app.ts", - "src/main/preload/externalAPI.js", "src/renderer/components/RemoveServerModal.tsx", "src/renderer/components/MainPage.tsx", - "src/renderer/components/HoveringURL.tsx", "src/renderer/components/AutoSaveIndicator.tsx", - "src/renderer/components/MattermostView.tsx", "src/renderer/components/TabBar.tsx", "src/renderer/components/DestructiveConfirmModal.tsx", "src/renderer/components/ErrorView.tsx", - "src/renderer/components/UpdaterPage.tsx", - "src/renderer/components/PermissionRequestDialog.tsx", - "src/renderer/components/Finder.tsx", "src/renderer/components/SettingsPage.tsx", - "src/renderer/components/TeamListItem.tsx", - "src/renderer/components/UpdaterPage/UpdaterPage.stories.tsx", - "src/renderer/components/Button/Button.stories.tsx", - "src/renderer/components/TeamList.tsx", - "src/renderer/components/LoginModal.tsx", "src/renderer/components/NewServerModal.tsx", "src/renderer/settings.tsx", "src/renderer/index.tsx" diff --git a/.gitignore b/.gitignore index eae3922b..e06bdfad 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ fastlane/README.md fastlane/report.xml *.provisionprofile -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +.eslintcache \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 13e1d666..e462d21f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "i18n" ], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "always", }, "cSpell.words": [ "appimage", diff --git a/babel.config.js b/babel.config.js index 1608f588..da5b7989 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,7 +2,7 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -module.exports = (api) => { // eslint-disable-line import/no-commonjs +module.exports = (api) => { api.cache.forever(); return { presets: [ diff --git a/e2e/.eslintrc.json b/e2e/.eslintrc.json deleted file mode 100644 index edad852d..00000000 --- a/e2e/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "env": { - "mocha": true - }, - "globals": { - "open_window": true - }, - "rules": { - "import/no-commonjs": 0, - "func-names": 0, - "global-require": 0, - "max-nested-callbacks": 0, - "no-eval": 0, - "no-magic-numbers": 0, - "no-unused-expressions": 0, - "prefer-arrow-callback": 0 - } -} diff --git a/e2e/modules/environment.js b/e2e/modules/environment.js index cffdda36..5e9165b7 100644 --- a/e2e/modules/environment.js +++ b/e2e/modules/environment.js @@ -306,7 +306,6 @@ module.exports = { // execute the test only when `condition` is true shouldTest(it, condition) { - // eslint-disable-next-line no-only-tests/no-only-tests return condition ? it : it.skip; }, isOneOf(platforms) { diff --git a/i18n/i18n.ts b/i18n/i18n.ts index d63b4c01..5dab1a8b 100644 --- a/i18n/i18n.ts +++ b/i18n/i18n.ts @@ -1,7 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable import/order */ import bg from './bg.json'; import de from './de.json'; import en from './en.json'; @@ -22,8 +21,8 @@ import sv from './sv.json'; import tr from './tr.json'; import uk from './uk.json'; import vi from './vi.json'; -import zhTW from './zh-TW.json'; import zhCN from './zh-CN.json'; +import zhTW from './zh-TW.json'; export type Language = { value: string; diff --git a/package.json b/package.json index df4c1c3c..201d7d4f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "check-types": "tsc", "prune": "ts-prune", "i18n-extract": "mmjstool -- i18n extract-desktop", - "lint:js": "eslint --ignore-path .gitignore --ignore-pattern node_modules --ext .js --ext .jsx --ext .ts --ext .tsx .", + "lint:js": "eslint --ext .js,.jsx,.tsx,.ts --cache .", "lint:js-quiet": "npm run lint:js -- --quiet", "fix:js": "npm run lint:js-quiet -- --fix", "test": "run-s lint:js test:unit test:e2e", diff --git a/scripts/.eslintrc.json b/scripts/.eslintrc.json deleted file mode 100644 index a3eec10c..00000000 --- a/scripts/.eslintrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "import/no-commonjs": 0 - } -} diff --git a/scripts/extract_dict.js b/scripts/extract_dict.js deleted file mode 100644 index 6714d08b..00000000 --- a/scripts/extract_dict.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015-2016 Yuya Ochiai -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -// This file uses process.exit(). -/* eslint-disable no-process-exit */ - -const {spawn} = require('child_process'); - -const {path7za} = require('7zip-bin'); - -const cwd = process.argv[2]; - -spawn(path7za, ['e', '-y', '*.zip'], { - cwd, - stdio: 'inherit', -}).on('error', (err) => { - console.error(err); - process.exit(1); -}).on('close', (code) => { - process.exit(code); -}); - -/* eslint-enable no-process-exit */ diff --git a/scripts/manipulate_windows_zip.js b/scripts/manipulate_windows_zip.js deleted file mode 100644 index 5ac4a1cc..00000000 --- a/scripts/manipulate_windows_zip.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015-2016 Yuya Ochiai -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. -'use strict'; - -const spawnSync = require('child_process').spawnSync; -const path = require('path'); - -const path7za = require('7zip-bin').path7za; - -const pkg = require('../package.json'); -const appVersion = pkg.version; -const name = pkg.name; - -function disableInstallUpdate(zipPath) { - const zipFullPath = path.resolve(__dirname, '..', zipPath); - const appUpdaterConfigFile = 'app-updater-config.json'; - - const addResult = spawnSync(path7za, ['a', zipFullPath, appUpdaterConfigFile], {cwd: 'resources/windows'}); - if (addResult.status !== 0) { - throw new Error(`7za a returned non-zero exit code for ${zipPath}`); - } - - const renameResult = spawnSync(path7za, ['rn', zipFullPath, appUpdaterConfigFile, `resources/${appUpdaterConfigFile}`]); - if (renameResult.status !== 0) { - throw new Error(`7za rn returned non-zero exit code for ${zipPath}`); - } -} - -console.log('Manipulating 64-bit zip...'); -disableInstallUpdate(`release/${name}-${appVersion}-win-x64.zip`); -console.log('Manipulating 32-bit zip...'); -disableInstallUpdate(`release/${name}-${appVersion}-win-ia32.zip`); diff --git a/src/main/views/viewManager.test.js b/src/main/views/viewManager.test.js index 2ee5ccc4..f220f542 100644 --- a/src/main/views/viewManager.test.js +++ b/src/main/views/viewManager.test.js @@ -1,9 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable max-lines */ -'use strict'; - import {dialog} from 'electron'; import ServerViewState from 'app/serverViewState'; diff --git a/src/main/windows/callsWidgetWindow.test.js b/src/main/windows/callsWidgetWindow.test.js index c383be91..69b60a71 100644 --- a/src/main/windows/callsWidgetWindow.test.js +++ b/src/main/windows/callsWidgetWindow.test.js @@ -1,8 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable max-lines */ - import {BrowserWindow, desktopCapturer, systemPreferences, ipcMain} from 'electron'; import ServerViewState from 'app/serverViewState'; diff --git a/src/renderer/components/MainPage.tsx b/src/renderer/components/MainPage.tsx index cad5e99d..21cdbca2 100644 --- a/src/renderer/components/MainPage.tsx +++ b/src/renderer/components/MainPage.tsx @@ -2,8 +2,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -/* eslint-disable max-lines */ - import classNames from 'classnames'; import React, {Fragment} from 'react'; import type {DropResult} from 'react-beautiful-dnd'; diff --git a/webpack.config.base.js b/webpack.config.base.js index bcd2b107..8af456db 100644 --- a/webpack.config.base.js +++ b/webpack.config.base.js @@ -2,10 +2,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -// This file uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const childProcess = require('child_process'); const path = require('path'); @@ -58,5 +54,3 @@ module.exports = { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], }, }; - -/* eslint-enable import/no-commonjs */ diff --git a/webpack.config.main.js b/webpack.config.main.js index 693a2bba..585771fd 100644 --- a/webpack.config.main.js +++ b/webpack.config.main.js @@ -2,10 +2,6 @@ // See LICENSE.txt for license information. // Copyright (c) 2015-2016 Yuya Ochiai -// This files uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const CopyPlugin = require('copy-webpack-plugin'); const {merge} = require('webpack-merge'); @@ -42,5 +38,3 @@ module.exports = merge(base, { }, target: 'electron-main', }); - -/* eslint-enable import/no-commonjs */ diff --git a/webpack.config.performance.test.js b/webpack.config.performance.test.js index 85df589b..8f7d5de4 100644 --- a/webpack.config.performance.test.js +++ b/webpack.config.performance.test.js @@ -1,10 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -// This file uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const glob = require('glob'); const {merge} = require('webpack-merge'); @@ -15,5 +11,3 @@ module.exports = merge(test, { e2e: glob.sync('./e2e/performance/**/*.test.js'), }, }); - -/* eslint-enable import/no-commonjs */ diff --git a/webpack.config.preload.js b/webpack.config.preload.js index 6dc49700..fe87328d 100644 --- a/webpack.config.preload.js +++ b/webpack.config.preload.js @@ -2,10 +2,6 @@ // See LICENSE.txt for license information. // Copyright (c) 2015-2016 Yuya Ochiai -// This files uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const {merge} = require('webpack-merge'); const base = require('./webpack.config.base'); @@ -24,5 +20,3 @@ module.exports = merge(base, { }, target: 'electron-preload', }); - -/* eslint-enable import/no-commonjs */ diff --git a/webpack.config.renderer.js b/webpack.config.renderer.js index 24fab39a..97b565ac 100644 --- a/webpack.config.renderer.js +++ b/webpack.config.renderer.js @@ -2,10 +2,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -// This file uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); @@ -175,5 +171,3 @@ module.exports = merge(base, { }, target: 'web', }); - -/* eslint-enable import/no-commonjs */ diff --git a/webpack.config.test.js b/webpack.config.test.js index 2a88ca1c..680d1a7a 100644 --- a/webpack.config.test.js +++ b/webpack.config.test.js @@ -1,10 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -// This file uses CommonJS. -/* eslint-disable import/no-commonjs */ -'use strict'; - const path = require('path'); const glob = require('glob'); @@ -38,5 +34,3 @@ module.exports = merge(base, { }, target: 'electron-main', }); - -/* eslint-enable import/no-commonjs */