From f2e9c5fa7cb423102461cf66f43ffc9657ef673a Mon Sep 17 00:00:00 2001 From: Michael Hutchison Date: Sun, 2 Aug 2020 13:18:36 +1000 Subject: [PATCH] Migrated to use ESLint instead of TSLint. Minor code style changes to conform to the new ESLint rules. --- .eslintrc.json | 74 +++++++++++++++++++++++++++++++++++ .vscode/extensions.json | 2 +- .vscodeignore | 4 +- package.json | 17 ++++---- src/commands.ts | 2 +- src/dataSource.ts | 2 +- src/diffDocProvider.ts | 2 +- src/extension.ts | 2 +- src/extensionState.ts | 2 +- src/gitGraphView.ts | 2 +- src/life-cycle/startup.ts | 2 +- src/life-cycle/uninstall.ts | 2 +- tests/diffDocProvider.test.ts | 2 +- tests/utils.test.ts | 2 +- tslint.json | 29 -------------- web/global.d.ts | 2 +- 16 files changed, 98 insertions(+), 50 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..b926f05d --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,74 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "eqeqeq": "error", + "indent": [ + "error", + "tab", + { + "SwitchCase": 1 + } + ], + "linebreak-style": [ + "error", + "windows" + ], + "no-console": "warn", + "no-redeclare": "error", + "no-shadow-restricted-names": "error", + "no-throw-literal": "error", + "no-unused-expressions": "error", + "quotes": [ + "error", + "single" + ], + "semi": "error", + "sort-imports": [ + "error", + { + "allowSeparatedGroups": true, + "ignoreDeclarationSort": true + } + ], + "@typescript-eslint/explicit-member-accessibility": [ + "error", + { + "overrides": { + "accessors": "off", + "constructors": "off" + } + } + ], + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "class", + "format": [ + "StrictPascalCase" + ] + }, + { + "selector": "function", + "format": [ + "camelCase" + ] + } + ] + }, + "overrides": [ + { + "files": "./src/askpass/askpassMain.ts", + "rules": { + "no-console": "off" + } + } + ] +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0a18b9c4..0c2c85be 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,6 @@ // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ - "ms-vscode.vscode-typescript-tslint-plugin" + "dbaeumer.vscode-eslint" ] } \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index 3c0c235e..399e5798 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -10,6 +10,6 @@ resources/demo.gif src/ tests/ web/ +.eslintrc.json .gitignore -jest.config.js -tslint.json \ No newline at end of file +jest.config.js \ No newline at end of file diff --git a/package.json b/package.json index 63cf2832..ab03372a 100644 --- a/package.json +++ b/package.json @@ -881,10 +881,11 @@ "vscode:prepublish": "npm run compile", "vscode:uninstall": "node ./out/life-cycle/uninstall.js", "clean": "node ./.vscode/clean.js", - "compile": "npm run clean && npm run compile-src && npm run compile-web", + "compile": "npm run lint && npm run clean && npm run compile-src && npm run compile-web", "compile-src": "tsc -p ./src && node ./.vscode/package-src.js", "compile-web": "tsc -p ./web && node ./.vscode/package-web.js", "compile-web-debug": "tsc -p ./web && node ./.vscode/package-web.js debug", + "lint": "eslint -c .eslintrc.json --ext .ts ./src ./tests ./web", "package": "npm run clean && vsce package", "package-and-install": "npm run package && node ./.vscode/install-package.js", "test": "jest --verbose", @@ -894,13 +895,15 @@ "iconv-lite": "0.5.0" }, "devDependencies": { - "@types/jest": "^25.2.1", - "@types/node": "^8.10.25", + "@types/jest": "25.2.3", + "@types/node": "8.10.62", "@types/vscode": "1.38.0", - "jest": "^25.4.0", - "ts-jest": "^25.4.0", - "tslint": "^5.12.1", + "@typescript-eslint/eslint-plugin": "3.7.1", + "@typescript-eslint/parser": "3.7.1", + "eslint": "7.6.0", + "jest": "25.5.4", + "ts-jest": "25.5.1", "typescript": "3.7.2", - "uglify-js": "^3.4.9" + "uglify-js": "3.10.0" } } diff --git a/src/commands.ts b/src/commands.ts index 5f6323f9..99670ee0 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -7,7 +7,7 @@ import { CodeReviewData, CodeReviews, ExtensionState } from './extensionState'; import { GitGraphView } from './gitGraphView'; import { Logger } from './logger'; import { RepoManager } from './repoManager'; -import { abbrevCommit, abbrevText, getPathFromUri, getRelativeTimeDiff, getRepoName, GitExecutable, isPathInWorkspace, resolveToSymbolicPath, showErrorMessage, showInformationMessage, UNABLE_TO_FIND_GIT_MSG } from './utils'; +import { GitExecutable, UNABLE_TO_FIND_GIT_MSG, abbrevCommit, abbrevText, getPathFromUri, getRelativeTimeDiff, getRepoName, isPathInWorkspace, resolveToSymbolicPath, showErrorMessage, showInformationMessage } from './utils'; /** * Manages the registration and execution of Git Graph Commands. diff --git a/src/dataSource.ts b/src/dataSource.ts index ee2a3f0d..64e8e59a 100644 --- a/src/dataSource.ts +++ b/src/dataSource.ts @@ -8,7 +8,7 @@ import { getConfig } from './config'; import { Event } from './event'; import { Logger } from './logger'; import { CommitOrdering, DateType, ErrorInfo, GitCommit, GitCommitDetails, GitCommitStash, GitConfigLocation, GitFileChange, GitFileStatus, GitPushBranchMode, GitRepoSettings, GitResetMode, GitSignatureStatus, GitStash, MergeActionOn, RebaseActionOn, SquashMessageFormat } from './types'; -import { abbrevCommit, constructIncompatibleGitVersionMessage, getPathFromStr, getPathFromUri, GitExecutable, isGitAtLeastVersion, openGitTerminal, realpath, resolveSpawnOutput, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED } from './utils'; +import { GitExecutable, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, abbrevCommit, constructIncompatibleGitVersionMessage, getPathFromStr, getPathFromUri, isGitAtLeastVersion, openGitTerminal, realpath, resolveSpawnOutput } from './utils'; const EOL_REGEX = /\r\n|\r|\n/g; const INVALID_BRANCH_REGEX = /^\(.* .*\)$/; diff --git a/src/diffDocProvider.ts b/src/diffDocProvider.ts index 7b93d632..5382bb18 100644 --- a/src/diffDocProvider.ts +++ b/src/diffDocProvider.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as vscode from 'vscode'; import { DataSource } from './dataSource'; import { GitFileStatus } from './types'; -import { getPathFromStr, showErrorMessage, UNCOMMITTED } from './utils'; +import { UNCOMMITTED, getPathFromStr, showErrorMessage } from './utils'; export const enum DiffSide { Old, diff --git a/src/extension.ts b/src/extension.ts index 97f61bf0..1f263644 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { onStartUp } from './life-cycle/startup'; import { Logger } from './logger'; import { RepoManager } from './repoManager'; import { StatusBarItem } from './statusBarItem'; -import { findGit, getGitExecutable, GitExecutable, showErrorMessage, showInformationMessage, UNABLE_TO_FIND_GIT_MSG } from './utils'; +import { GitExecutable, UNABLE_TO_FIND_GIT_MSG, findGit, getGitExecutable, showErrorMessage, showInformationMessage } from './utils'; /** * Activate Git Graph. diff --git a/src/extensionState.ts b/src/extensionState.ts index 956e6e95..530a7b02 100644 --- a/src/extensionState.ts +++ b/src/extensionState.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { Avatar, AvatarCache } from './avatarManager'; import { Event } from './event'; import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowTags } from './types'; -import { getPathFromStr, GitExecutable } from './utils'; +import { GitExecutable, getPathFromStr } from './utils'; const AVATAR_STORAGE_FOLDER = '/avatars'; const AVATAR_CACHE = 'avatarCache'; diff --git a/src/gitGraphView.ts b/src/gitGraphView.ts index 21467f56..7c301477 100644 --- a/src/gitGraphView.ts +++ b/src/gitGraphView.ts @@ -8,7 +8,7 @@ import { Logger } from './logger'; import { RepoFileWatcher } from './repoFileWatcher'; import { RepoManager } from './repoManager'; import { ErrorInfo, GitConfigLocation, GitGraphViewInitialState, GitPushBranchMode, GitRepoSet, LoadGitGraphViewTo, RefLabelAlignment, RequestMessage, ResponseMessage, TabIconColourTheme } from './types'; -import { archive, copyFilePathToClipboard, copyToClipboard, createPullRequest, getNonce, getRepoName, openExtensionSettings, openFile, showErrorMessage, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, viewDiff, viewFileAtRevision, viewScm } from './utils'; +import { UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, archive, copyFilePathToClipboard, copyToClipboard, createPullRequest, getNonce, getRepoName, openExtensionSettings, openFile, showErrorMessage, viewDiff, viewFileAtRevision, viewScm } from './utils'; /** * Manages the Git Graph View. diff --git a/src/life-cycle/startup.ts b/src/life-cycle/startup.ts index 855662e0..3f4a274e 100644 --- a/src/life-cycle/startup.ts +++ b/src/life-cycle/startup.ts @@ -10,7 +10,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; -import { generateNonce, getDataDirectory, getLifeCycleStateInDirectory, LifeCycleStage, LifeCycleState, saveLifeCycleStateInDirectory, sendQueue } from './utils'; +import { LifeCycleStage, LifeCycleState, generateNonce, getDataDirectory, getLifeCycleStateInDirectory, saveLifeCycleStateInDirectory, sendQueue } from './utils'; /** * Run on startup to detect if Git Graph has been installed or updated, and if so generate an event. diff --git a/src/life-cycle/uninstall.ts b/src/life-cycle/uninstall.ts index 31f1747d..f7b0656c 100644 --- a/src/life-cycle/uninstall.ts +++ b/src/life-cycle/uninstall.ts @@ -7,7 +7,7 @@ * - Full details are available at: https://api.mhutchie.com/vscode-git-graph/about */ -import { generateNonce, getDataDirectory, getLifeCycleStateInDirectory, LifeCycleStage, sendQueue } from './utils'; +import { LifeCycleStage, generateNonce, getDataDirectory, getLifeCycleStateInDirectory, sendQueue } from './utils'; (async function () { try { diff --git a/tests/diffDocProvider.test.ts b/tests/diffDocProvider.test.ts index 0d6239c1..bc7d4255 100644 --- a/tests/diffDocProvider.test.ts +++ b/tests/diffDocProvider.test.ts @@ -6,7 +6,7 @@ jest.mock('../src/logger'); import * as path from 'path'; import { ConfigurationChangeEvent } from 'vscode'; import { DataSource } from '../src/dataSource'; -import { decodeDiffDocUri, DiffDocProvider, DiffSide, encodeDiffDocUri } from '../src/diffDocProvider'; +import { DiffDocProvider, DiffSide, decodeDiffDocUri, encodeDiffDocUri } from '../src/diffDocProvider'; import { EventEmitter } from '../src/event'; import { Logger } from '../src/logger'; import { GitFileStatus } from '../src/types'; diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 2465a81f..885b1a2c 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -15,7 +15,7 @@ import { EventEmitter } from '../src/event'; import { ExtensionState } from '../src/extensionState'; import { Logger } from '../src/logger'; import { GitFileStatus, PullRequestProvider } from '../src/types'; -import { abbrevCommit, abbrevText, archive, constructIncompatibleGitVersionMessage, copyFilePathToClipboard, copyToClipboard, createPullRequest, evalPromises, findGit, getGitExecutable, getNonce, getPathFromStr, getPathFromUri, getRelativeTimeDiff, getRepoName, GitExecutable, isGitAtLeastVersion, isPathInWorkspace, openExtensionSettings, openFile, openGitTerminal, pathWithTrailingSlash, realpath, resolveSpawnOutput, resolveToSymbolicPath, showErrorMessage, showInformationMessage, UNCOMMITTED, viewDiff, viewFileAtRevision, viewScm } from '../src/utils'; +import { GitExecutable, UNCOMMITTED, abbrevCommit, abbrevText, archive, constructIncompatibleGitVersionMessage, copyFilePathToClipboard, copyToClipboard, createPullRequest, evalPromises, findGit, getGitExecutable, getNonce, getPathFromStr, getPathFromUri, getRelativeTimeDiff, getRepoName, isGitAtLeastVersion, isPathInWorkspace, openExtensionSettings, openFile, openGitTerminal, pathWithTrailingSlash, realpath, resolveSpawnOutput, resolveToSymbolicPath, showErrorMessage, showInformationMessage, viewDiff, viewFileAtRevision, viewScm } from '../src/utils'; let extensionContext = vscode.mocks.extensionContext; let terminal = vscode.mocks.terminal; diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 390b89a6..00000000 --- a/tslint.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "rules": { - "no-string-throw": true, - "no-unused-expression": true, - "no-duplicate-variable": true, - "class-name": true, - "indent": [ - true, - "tabs" - ], - "linebreak-style": [ - true, - "CRLF" - ], - "member-access": true, - "no-console": true, - "ordered-imports": true, - "quotemark": [ - true, - "single" - ], - "semicolon": [ - true, - "always" - ], - "triple-equals": true - }, - "defaultSeverity": "warning" -} \ No newline at end of file diff --git a/web/global.d.ts b/web/global.d.ts index 7fade828..5a27732e 100644 --- a/web/global.d.ts +++ b/web/global.d.ts @@ -1,4 +1,4 @@ -import * as GG from "../out/types"; // Import types from back-end (requires `npm run compile-src`) +import * as GG from '../out/types'; // Import types from back-end (requires `npm run compile-src`) declare global {