8000 Housekeeping: Apply prettier and eslint by tjomson · Pull Request #692 · git-truck/git-truck · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Housekeeping: Apply prettier and eslint #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"pub-pre": "npm version prerelease && npm publish --tag next",
"pub-exp": "node ./scripts/publish-experimental.js",
"prepublishOnly": "npm run clean && npm run build",
"format": "eslint --cache --fix {src,scripts}/**/*.{ts,tsx,js,mjs} && prettier --loglevel warn --write {src,scripts}/**/*.{ts,tsx,js,mjs}",
"format": "eslint --cache --fix {src,scripts}/**/*.{ts,tsx,js,mjs} && prettier --log-level warn --write {src,scripts}/**/*.{ts,tsx,js,mjs}",
"lint": "eslint --cache --fix {src,scripts}/**/*.{ts,tsx,js,mjs}"
},
"devDependencies": {
Expand Down Expand Up @@ -118,6 +118,7 @@
"prettier": {
"semi": false,
"printWidth": 120,
"trailingComma": "none",
"plugins": [
"prettier-plugin-tailwindcss"
]
Expand All @@ -139,4 +140,4 @@
"url": "https://github.com/git-truck/git-truck/issues"
},
"homepage": "https://github.com/git-truck/git-truck#readme"
}
}
4 changes: 2 additions & 2 deletions scripts/benchmark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for (let i = 0; i < versionsToCompare.length; i++) {
const start = performance.now()
// Install module with specific version
const output = execSync(`npx git-truck@${version} -y -h`, {
stdio: "pipe",
stdio: "pipe"
})

invariant(
Expand Down Expand Up @@ -81,7 +81,7 @@ for (let i = 0; i < versionsToCompare.length; i++) {
times.push({
version,
"npx average time (in ms)": npxAverage,
"global install average time (in ms)": globalInstallAverage,
"global install average time (in ms)": globalInstallAverage
})
}

Expand Down
2 changes: 0 additions & 2 deletions scripts/publish-experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { execSync } = require("child_process")
const hasUncommittedChanges = execSync("git status --porcelain", { stdio: "pipe" })?.toString().trim().length > 0

async function main() {

if (hasUncommittedChanges) {
console.error("You have uncommitted changes. Please commit or stash them before publishing.")
process.exit(1)
Expand All @@ -18,7 +17,6 @@ async function main() {
const commitHash = execSync("git rev-parse --short HEAD", { stdio: "pipe" }).toString().trim()
const versionTag = `0.0.0-${commitHash}`


console.log(`Tagging version ${versionTag}...`)
execSync(`npm version ${versionTag} --no-git-tag-version`, { stdio: "pipe" })
console.log(`Tagged version ${versionTag}`)
Expand Down
36 changes: 18 additions & 18 deletions src/analyzer/analyze.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import type {
GitTreeObject,
AnalyzerData,
TruckUserConfig,
TruckConfig,
TruckConfig
} from "./model"
import { AnalyzerDataInterfaceVersion } from "./model"
import { log, setLogLevel } from "./log.server"
import { describeAsyncJob, formatMs, writeRepoToFile, getDirName } from "./util.server"
import { describeAsyncJob, writeRepoToFile, getDirName } from "./util.server"
import { GitCaller } from "./git-caller.server"
import { emptyGitCommitHash } from "./constants"
import { resolve, isAbsolute, sep } from "path"
Expand Down Expand Up @@ -41,13 +41,13 @@ export async function analyzeCommitLight(hash: string): Promise<GitCommitObjectL
name: groups["authorName"],
email: groups["authorEmail"],
timestamp: Number(groups["authorTimeStamp"]),
timezone: groups["authorTimeZone"],
timezone: groups["authorTimeZone"]
}
const committer = {
name: groups["committerName"],
email: groups["committerEmail"],
timestamp: Number(groups["committerTimeStamp"]),
timezone: groups["committerTimeZone"],
timezone: groups["committerTimeZone"]
}
const message = groups["message"]
const description = groups["description"]
Expand All @@ -63,7 +63,7 @@ export async function analyzeCommitLight(hash: string): Promise<GitCommitObjectL
committer,
message,
description,
coauthors,
coauthors
}
}

Expand All @@ -76,7 +76,7 @@ export async function analyzeCommit(repoName: string, hash: string): Promise<Git
const commitObject = {
...commit,
fileCount,
tree: rootTree,
tree: rootTree
}
return commitObject
}
Expand Down Expand Up @@ -105,7 +105,7 @@ async function analyzeTree(path: string, name: string, hash: string) {
type: groups["type"] as "blob" | "tree",
hash: groups["hash"],
size: groups["size"] === "-" ? undefined : Number(groups["size"]),
path: groups["path"],
path: groups["path"]
})
}

Expand All @@ -114,7 +114,7 @@ async function analyzeTree(path: string, name: string, hash: string) {
path,
name,
hash,
children: [],
children: []
} as GitTreeObject

for (const child of lsTreeEntries) {
Expand All @@ -133,7 +133,7 @@ async function analyzeTree(path: string, name: string, hash: string) {
path: newPath,
name: newName,
hash: child.hash,
children: [],
children: []
}

currTree.children.push(newTree)
Expand All @@ -147,7 +147,7 @@ async function analyzeTree(path: string, name: string, hash: string) {
path: newPath,
name: newName,
sizeInBytes: child.size as number,
blameAuthors: {},
blameAuthors: {}
}
// Don't block the current loop, just add the job to the queue and await it later
// jobs.push((async () => (blob.blameAuthors = await GitCaller.getInstance().parseBlame(blob.path)))())
Expand Down Expand Up @@ -212,7 +212,7 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
job: () => git.findBranchHead(branch),
beforeMsg: "Finding branch head",
afterMsg: "Found branch head",
errorMsg: "Error finding branch head",
errorMsg: "Error finding branch head"
})
const repoName = getDirName(repoDir)

Expand All @@ -228,13 +228,13 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
repo: repoName,
branch: branchName,
branchHead: branchHead,
invalidateCache: args.invalidateCache,
invalidateCache: args.invalidateCache
})

if (cachedData) {
data = {
...cachedData,
hiddenFiles,
hiddenFiles
}
} else {
log.info(
Expand All @@ -258,7 +258,7 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
job: () => analyzeCommit(repoName, branchHead),
beforeMsg: "Analyzing commit tree",
afterMsg: "Commit tree analyzed",
errorMsg: "Error analyzing commit tree",
errorMsg: "Error analyzing commit tree"
})

if (repoTreeError) throw repoTreeError
Expand All @@ -267,7 +267,7 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
job: () => hydrateData(repoTree),
beforeMsg: "Hydrating commit tree",
afterMsg: "Commit tree hydrated",
errorMsg: "Error hydrating commit tree",
errorMsg: "Error hydrating commit tree"
})

if (hydratedRepoTreeError) throw hydratedRepoTreeError
Expand Down Expand Up @@ -303,11 +303,11 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
job: () =>
writeRepoToFile(outPath, {
...data,
cached: true,
cached: true
} as AnalyzerData),
beforeMsg: "Writing data to file",
afterMsg: `Wrote data to ${resolve(outPath)}`,
errorMsg: `Error writing data to file ${outPath}`,
errorMsg: `Error writing data to file ${outPath}`
})
}
}
Expand All @@ -325,7 +325,7 @@ export async function analyze(args: TruckConfig): Promise<AnalyzerData> {
beforeMsg: "",
afterMsg: `Ready in`,
errorMsg: "",
ms: stop - start,
ms: stop - start
})

return data
Expand Down
6 changes: 3 additions & 3 deletions src/analyzer/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe("getCoAuthors", () => {
const expected = [
{
name: "Bob Bobby",
email: "bob@example.com",
email: "bob@example.com"
},
{
name: "Alice Lmao",
email: "alice@example.com",
},
email: "alice@example.com"
}
]
const actual = getCoAuthors(sampleDescription)
expect(actual).toStrictEqual(expected)
Expand Down
10 changes: 5 additions & 5 deletions src/analyzer/args.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { log } from "./log.server"
export function parseArgs(rawArgs: string[] = process.argv.slice(2)) {
return yargsParser(rawArgs, {
configuration: {
"duplicate-arguments-array": false,
},
"duplicate-arguments-array": false
}
})
}

Expand All @@ -21,7 +21,7 @@ export function getArgsWithDefaults(): TruckConfig {
hiddenFiles: [] as string[],
unionedAuthors: [] as string[][],
invalidateCache: false,
...args,
...args
}

return tempArgs
Expand All @@ -44,8 +44,8 @@ export async function getTruckConfigWithArgs(repo: string): Promise<[TruckConfig
return [
{
...args,
...config,
...config
},
config,
config
]
}
2 changes: 1 addition & 1 deletion src/analyzer/coauthors.server.ts
6851
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getCoAuthors(description: string) {
while (next.value !== undefined) {
coauthors.push({
name: next.value.groups["name"].trimEnd(),
email: next.value.groups["email"],
email: next.value.groups["email"]
})
next = coauthormatches.next()
}
Expand Down
27 changes: 13 additions & 14 deletions src/analyzer/git-caller.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum ANALYZER_CACHE_MISS_REASONS {
OTHER_REPO = "The cache was not created for this repo",
NOT_CACHED = "No cache was found",
BRANCH_HEAD_CHANGED = "Branch head changed",
DATA_VERSION_MISMATCH = "Outdated cache",
DATA_VERSION_MISMATCH = "Outdated cache"
}

export type RawGitObjectType = "blob" | "tree" | "commit" | "tag"
Expand Down Expand Up @@ -94,8 +94,8 @@ export class GitCaller {
async gitShow(commits: string[]) {
if (!this.branch) throw Error("branch not set")
const args = [
"show",
"--no-patch",
"show",
"--no-patch",
'--format="author <|%an|> date <|%at|> message <|%s|> body <|%b|> hash <|%H|>"',
...commits
]
Expand Down Expand Up @@ -141,12 +141,12 @@ export class GitCaller {
repo: getDirName(repoPath),
branch: headName,
branchHead: head,
invalidateCache,
invalidateCache
})
return {
headName,
head,
isAnalyzed: result !== null,
isAnalyzed: result !== null
}
})
)
Expand All @@ -164,7 +164,7 @@ export class GitCaller {
reasons: [],
currentHead: await GitCaller._getRepositoryHead(repoPath),
refs,
analyzedHeads,
analyzedHeads
}

try {
Expand All @@ -175,7 +175,7 @@ export class GitCaller {
repo: repoDir,
branch,
branchHead,
invalidateCache,
invalidateCache
})
repo.data = data
repo.reasons = reasons
Expand All @@ -195,7 +195,7 @@ export class GitCaller {
job: () => GitCaller.isGitRepo(argPath),
beforeMsg: "Checking if path is a git repo...",
afterMsg: "Done checking if path is a git repo",
errorMsg: "Error checking if path is a git repo",
errorMsg: "Error checking if path is a git repo"
})

const baseDir = resolve(pathIsRepo ? getBaseDirFromPath(argPath) : argPath)
Expand All @@ -214,7 +214,7 @@ export class GitCaller {
),
beforeMsg: "Scanning for repositories...",
afterMsg: "Done scanning for repositories",
errorMsg: "Error scanning for repositories",
errorMsg: "Error scanning for repositories"
})) as [PromiseSettledResult<Repository>[], null]

const >
Expand All @@ -233,7 +233,7 @@ export class GitCaller {
static parseRefs(refsAsMultilineString: string): GitRefs {
const gitRefs: GitRefs = {
Branches: {},
Tags: {},
Tags: {}
}

const regex = /^(?<hash>.*) refs\/(?<ref_type>.*?)\/(?<path>.*)$/gm
Expand Down Expand Up @@ -278,10 +278,9 @@ export class GitCaller {
this.branch,
"--numstat",
// "--cc", // include file changes for merge commits
'--format="author <|%an|> date <|%at|> message <|%s|> body <|%b|> hash <|%H|>"',
'--format="author <|%an|> date <|%at|> message <|%s|> body <|%b|> hash <|%H|>"'
]


const result = (await runProcess(this.repo, "git", args)) as string
return result.trim()
}
Expand All @@ -290,7 +289,7 @@ export class GitCaller {
repo,
branch,
branchHead,
invalidateCache = false,
invalidateCache = false
}: {
repo: string
branch: string
Expand Down Expand Up @@ -320,7 +319,7 @@ export class GitCaller {
const cacheConditions = {
branchHeadMatches,
dataVersionMatches,
repoMatches,
repoMatches
}

// Only return cached data if every criteria is met
Expand Down
Loading
0