Skip to content

Commit

Permalink
refactor: enforce consistent usages across codebase
Browse files Browse the repository at this point in the history
now however a symbol is defined, it must be used with the case case
so no more `fooBar` vs `foobar` vs `foo_bar` typos which make grepping
much more complicated
  • Loading branch information
miki725 committed Jan 28, 2025
1 parent 6bfaa4a commit 58fa4d9
Show file tree
Hide file tree
Showing 34 changed files with 92 additions and 84 deletions.
8 changes: 8 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ var

applyCommonLinkOptions()
staticLinkLibraries(libs, libDir, muslBase = localDir)

# https://nim-lang.org/docs/nimc.html
# > --styleCheck:usages
# > only enforce consistent spellings of identifiers, do not enforce the style on declarations
# https://github.com/nim-lang/Nim/blob/4680ab61c06782d142492d1fcdebf8e942373c09/changelogs/changelog_1_6_0.md#compiler-messages-error-messages-hints-warnings
# To be enabled, this has to be combined either with --styleCheck:error or --styleCheck:hint.
switch("styleCheck", "usages")
switch("styleCheck", "error")
4 changes: 2 additions & 2 deletions src/attestation/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ proc isValid*(self: AttestationKey): bool =
"-"]

let
cmd = runCmdGetEverything(cosign, signArgs, tosign)
cmd = runCmdGetEverything(cosign, signArgs, toSign)
err = cmd.getStdErr()
sig = cmd.getStdOut()

Expand All @@ -138,7 +138,7 @@ proc isValid*(self: AttestationKey): bool =
"--insecure-ignore-sct=true",
"--signature=" & sig,
"-"]
vfyOut = runCmdGetEverything(cosign, vfyArgs, tosign)
vfyOut = runCmdGetEverything(cosign, vfyArgs, toSign)

if vfyOut.getExit() != 0:
error("Could not validate; public key is invalid.")
Expand Down
8 changes: 4 additions & 4 deletions src/attestation_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ proc verifyBySigStore(chalk: ChalkObj, key: AttestationKey, image: DockerImage):
trace("cosign " & args.join(" "))
let
allOut = runCmdGetEverything(cosign, args)
res = allout.getStdout()
err = allout.getStderr()
code = allout.getExit()
res = allOut.getStdout()
err = allOut.getStderr()
code = allOut.getExit()
if code == 0:
let
blob = parseJson(res)
Expand Down Expand Up @@ -288,7 +288,7 @@ proc signBySigStore*(chalk: ChalkObj): ChalkDict =
trace("cosign " & args.join(" ") & "\n" & toto)
let
allOut = runCmdGetEverything(cosign, args, toto)
code = allout.getExit()
code = allOut.getExit()
if code != 0:
raise newException(
ValueError,
Expand Down
2 changes: 1 addition & 1 deletion src/chalk_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ var
subscribedKeys* = Table[string, bool]()
systemErrors* = seq[string](@[])
selfChalk* = ChalkObj(nil)
selfID* = none(string)
selfId* = none(string)
canSelfInject* = true
doingTestRun* = false
nativeCodecsOnly* = false
Expand Down
8 changes: 4 additions & 4 deletions src/chalkjson.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ let
jFalse: ChalkJsonNode = ChalkJsonNode(kind: CJBool, boolval: false)
jTrue: ChalkJsonNode = ChalkJsonNode(kind: CJBool, boolval: true)

proc jSonNull(s: Stream): ChalkJsonNode =
proc jsonNull(s: Stream): ChalkJsonNode =
literalCheck(s, jNullStr)
return jNullLit

proc jSonFalse(s: Stream): ChalkJsonNode =
proc jsonFalse(s: Stream): ChalkJsonNode =
literalCheck(s, jFalseStr)
return jFalse

proc jSonTrue(s: Stream): ChalkJsonNode =
proc jsonTrue(s: Stream): ChalkJsonNode =
literalCheck(s, jTrueStr)
return jTrue

Expand Down Expand Up @@ -429,7 +429,7 @@ proc jsonValue(s: Stream): ChalkJsonNode =

proc chalkParseJson*(s: Stream): ChalkJsonNode =
s.jsonWS()
result = s.jSonValue()
result = s.jsonValue()
# Per the spec, we should advance the stream white space after the
# extracted value. However, we don't do this at the top level just
# in case any space after the end of the element has semantic value
Expand Down
6 changes: 3 additions & 3 deletions src/collect.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ proc collectChalkTimeArtifactInfo*(obj: ChalkObj, override = false) =
if plugin == obj.myCodec:
trace("Filling in codec info")
if "CHALK_ID" notin data:
data["CHALK_ID"] = pack(obj.callGetChalkID())
data["CHALK_ID"] = pack(obj.callGetChalkId())
let preHashOpt = obj.callGetUnchalkedHash()
if preHashOpt.isSome():
data["HASH"] = pack(preHashOpt.get())
Expand Down Expand Up @@ -403,7 +403,7 @@ iterator artifacts*(argv: seq[string], notTmp=true): ChalkObj =

if not inSubscan() and not obj.forceIgnore and
obj.name notin getUnmarked():
obj.collectRuntimeArtifactInfo()
obj.collectRunTimeArtifactInfo()

if not inSubscan():
if getCommandName() != "extract":
Expand All @@ -426,5 +426,5 @@ iterator artifacts*(argv: seq[string], notTmp=true): ChalkObj =
if chalk.extract == nil:
info(chalk.name & ": Artifact is unchalked.")
trace("Collecting artifact runtime info")
chalk.collectRuntimeArtifactInfo()
chalk.collectRunTimeArtifactInfo()
yield chalk
2 changes: 1 addition & 1 deletion src/commands/cmd_docker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ proc runCmdDocker*(args: seq[string]) =

if getDockerExeLocation() == "":
error("docker command is missing. chalk requires docker binary installed to wrap docker commands.")
ctx.dockerFailSafe()
ctx.dockerFailsafe()

ctx.withDockerFailsafe():
case ctx.extractDockerCommand()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_extract.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ proc processDockerChalk(item: ChalkObj) =
trace("Processing artifact: " & item.name)
item.addToAllChalks()
trace("Collecting artifact runtime info")
item.collectRuntimeArtifactInfo()
item.collectRunTimeArtifactInfo()
if item.extract == nil:
info(item.name & ": Artifact is unchalked.")

Expand Down
18 changes: 9 additions & 9 deletions src/commands/cmd_help.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ proc resolveHelpFileName(docName: string): string =

proc searchEmbeddedDocs(terms: seq[string]): Rope =
# Terminal only.
for key, doc in helpfiles:
for key, doc in helpFiles:
var matchedTerms: seq[string] = @[]

for term in terms:
Expand All @@ -155,8 +155,8 @@ proc searchEmbeddedDocs(terms: seq[string]): Rope =
result = h4("No matches in other documents.")

proc getEmbeddedDoc(key: string): Rope =
if key in helpfiles:
result += text(helpfiles[key])
if key in helpFiles:
result += text(helpFiles[key])
if result == Rope(nil):
result = h4("No document " & key & ".")

Expand Down Expand Up @@ -535,10 +535,10 @@ proc runChalkHelp*(cmdName = "help") {.noreturn.} =
for item in toCheck:
if item in helpFiles:
toOut += text(helpFiles[item])
gotit = true
gotIt = true
break

if gotIt == false:
if not gotIt:
# If we see an unknown argument at any position, stop what
# we were doing and run a full-text search on all passed
# arguments.
Expand Down Expand Up @@ -588,12 +588,12 @@ proc buildSinkConfigData(): seq[seq[Rope]] =
else: subLists[config].add(topic)

for key, config in sinkConfigs:
if config notin sublists:
sublists[config] = @[]
if config notin subLists:
subLists[config] = @[]
result.add(@[text(key), text(config.mySink.getName()),
text(paramFmt(config.params)),
text(filterFmt(config.filters)),
text(sublists[config].join(", "))])
text(subLists[config].join(", "))])

proc getConfigValues(): Rope =
var
Expand Down Expand Up @@ -633,7 +633,7 @@ proc getConfigValues(): Rope =
headings = confHdrs, sectionPath = item)


result += outconfData.quickTable("Metadata template configuration",
result += outConfData.quickTable("Metadata template configuration",
class = "help")
result += custRepData.quickTable("Additional reports configured",
class = "help")
Expand Down
2 changes: 1 addition & 1 deletion src/con4mfuncs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ object must already be defined at the time of the call to subscribe()
@["chalk"]
),
("unsubscribe(string, string) -> bool",
BuiltInFn(topicUnSubscribe),
BuiltInFn(topicUnsubscribe),
"""
For the topic name given in the first parameter, unsubscribes the sink
configuration named in the second parameter, if subscribed.
Expand Down
2 changes: 1 addition & 1 deletion src/confload.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ proc loadAllConfigs*() =
let optConf = stack.configState.findOptionalConf()
if optConf.isSome():
let fName = optConf.get()
withFileStream(fname, mode = fmRead, strict = true):
withFileStream(fName, mode = fmRead, strict = true):
stack.
addConfLoad(fName, stream).
addCallback(loadLocalStructs)
Expand Down
2 changes: 1 addition & 1 deletion src/docker/build.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ proc processDockerFile(ctx: DockerInvocation) =

else:
if ctx.dockerFileLoc == "":
let toResolve = joinPath(ctx.foundcontext, "Dockerfile")
let toResolve = joinPath(ctx.foundContext, "Dockerfile")
ctx.dockerFileLoc = resolvePath(toResolve)

try:
Expand Down
8 changes: 4 additions & 4 deletions src/docker/dockerfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ method repr(x: FromInfo, ctx: DockerParse): string =
for name, flag in x.flags:
let valid = if flag.valid: "valid" else: "NOT valid"
result &= "(flag " & flag.name & " is " & valid & "; val = "
result &= ctx.evalSubstitutions(flag.argToks, errors) & ") "
result &= ctx.evalSubstitutions(flag.argtoks, errors) & ") "
if x.image.isNone():
result &= "image = none??; "
else:
Expand Down Expand Up @@ -197,11 +197,11 @@ proc lexVarSub(ctx: DockerParse, d: DockerStatement, s: seq[Rune], i: var int):
# Drops down below
else:
result.error = "Unterminated ${"
result.endIx = i
result.endix = i
return
else:
result.error = "Unterminated ${"
result.endIx = i
result.endix = i
return

i += 1
Expand Down Expand Up @@ -239,7 +239,7 @@ proc lexQuoted(ctx: DockerParse, d: DockerStatement, s: seq[Rune], q: Rune, i: v
if s[i] == Rune('$'):
result.contents.add(val)
val = ""
result.varSubs.add(ctx.lexVarsub(d, s, i))
result.varSubs.add(ctx.lexVarSub(d, s, i))
continue
val &= $(s[i])
i += 1
Expand Down
2 changes: 1 addition & 1 deletion src/docker/entrypoint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ proc rewriteEntryPoint*(ctx: DockerInvocation,
# when ENTRYPOINT is an empty string, doing a build with
# buildx leaves empty string as an arg in exec
# https://github.com/moby/buildkit/pull/1874
if entrypoint.str != "" or hasBuildx():
if entrypoint.str != "" or hasBuildX():
shell.json & %(@[entrypoint.str])
else:
%(@[])
Expand Down
4 changes: 2 additions & 2 deletions src/docker/exe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ proc getDockerServerVersion*(): Version =
dumpExOnDebug()
return dockerServerVersion

proc hasBuildx*(): bool =
proc hasBuildX*(): bool =
return getBuildXVersion() > parseVersion("0")

var dockerInfo = ""
Expand Down Expand Up @@ -247,7 +247,7 @@ proc supportsCopyChmod*(): bool =
# > the --chmod option requires BuildKit.
# > Refer to https://docs.docker.com/go/buildkit/ to learn how to
# > build images with BuildKit enabled
return hasBuildx()
return hasBuildX()

proc supportsInspectJsonFlag*(): bool =
# https://github.com/docker/cli/pull/2936
Expand Down
4 changes: 2 additions & 2 deletions src/docker/extract.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ proc extractMarkFromInToto(self: ChalkObj, json: JsonNode): string =
matchesDigest = false
digests = newSeq[string]()
for image in self.repos.manifests:
if digest.extractDockerhash() == image.digest:
if digest.extractDockerHash() == image.digest:
matchesDigest = true
digests.add(image.digest)
break
Expand All @@ -160,7 +160,7 @@ proc extractMarkFromSigStoreCosign(self: ChalkObj): string =
let
allOut = runCmdGetEverything(cosign, args)
res = allOut.getStdout()
code = allout.getExit()
code = allOut.getExit()
if code != 0:
err = allOut.getStdErr().splitLines()[0]
continue
Expand Down
4 changes: 2 additions & 2 deletions src/docker/git.nim
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ proc setGitHEAD(git: DockerGitContext) =
of GitHeadType.branch:
git.setGitHEADToName(HEADS)
of GitHeadType.other:
git.setGitHeadToname("")
git.setGitHEADToName("")
of GitHeadType.tag:
# git tags are treated as detached commits on checkout
git.setGitHEADToCommit()
Expand All @@ -320,7 +320,7 @@ proc fetch(git: DockerGitContext) =
for spec in git.head.refs:
args.add(spec & ":" & spec)
discard git.run(args)
git.setGitHead()
git.setGitHEAD()

proc checkout*(git: DockerGitContext): string =
git.tmpWorkTree = getNewTempDir(tmpFileSuffix = ".context")
Expand Down
2 changes: 1 addition & 1 deletion src/docker/image.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ proc fetchImageEntrypoint*(image: DockerImage, platform: DockerPlatform): Docker
return (nil, nil, nil)
let
imageInfo = fetchImageOrManifestConfig(image, platform)
entrypoint = fromJson[EntrypointInfo](imageInfo{"Entrypoint"})
entrypoint = fromJson[EntryPointInfo](imageInfo{"Entrypoint"})
cmd = fromJson[CmdInfo](imageInfo{"Cmd"})
shell = fromJson[ShellInfo](imageInfo{"Shell"})
return (entrypoint, cmd, shell)
Expand Down
2 changes: 1 addition & 1 deletion src/docker/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ proc newDockerDigestedJson*(data: string,
): DockerDigestedJson =
return DockerDigestedJson(
json: parseJson(data),
digest: "sha256:" & extractDockerhash(digest),
digest: "sha256:" & extractDockerHash(digest),
size: len(data),
mediaType: mediaType,
kind: kind,
Expand Down
2 changes: 1 addition & 1 deletion src/docker/registry.nim
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ iterator iterBuildxSpecificRegistryConfigs(self: DockerImage,
)

iterator iterBuildxRegistryConfigs(self: DockerImage, useCase: RegistryUseCase): RegistryConfig =
if hasBuildx():
if hasBuildX():
if useCase == RegistryUseCase.ReadOnly:
for node, config in dockerInvocation.iterBuilderNodesConfigs():
try:
Expand Down
6 changes: 3 additions & 3 deletions src/plugin_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,12 @@ proc newCodec*(
scan: ScanCb = ScanCb(nil),
ctHostCallback: ChalkTimeHostCb = ChalkTimeHostCb(nil),
ctArtCallback: ChalkTimeArtifactCb = ChalkTimeArtifactCb(nil),
rtArtCallback: RunTimeArtifactCb = RuntimeArtifactCb(defaultRtArtInfo),
rtHostCallback: RunTimeHostCb = RunTimeHostcb(nil),
rtArtCallback: RunTimeArtifactCb = RunTimeArtifactCb(defaultRtArtInfo),
rtHostCallback: RunTimeHostCb = RunTimeHostCb(nil),
getUnchalkedHash: UnchalkedHashCb = UnchalkedHashCb(defUnchalkedHash),
getEndingHash: EndingHashCb = EndingHashCb(defEndingHash),
getChalkId: ChalkIdCb = ChalkIdCb(defaultChalkId),
handleWrite: HandleWriteCb = HandleWritecb(defaultCodecWrite),
handleWrite: HandleWriteCb = HandleWriteCb(defaultCodecWrite),
nativeObjPlatforms: seq[string] = @[],
cache: RootRef = RootRef(nil),
commentStart: string = "#",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codecElf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ proc loadCodecElf*() =
handleWrite = HandleWriteCb(elfHandleWrite),
getUnchalkedHash = UnchalkedHashCb(elfGetUnchalkedHash),
ctArtCallback = ChalkTimeArtifactCb(elfGetChalkTimeArtifactInfo),
rtArtCallback = RunTimeArtifactCb(elfgetRunTimeArtifactInfo))
rtArtCallback = RunTimeArtifactCb(elfGetRunTimeArtifactInfo))
2 changes: 1 addition & 1 deletion src/plugins/codecFallbackElf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ proc loadCodecFallbackElf*() =
scan = ScanCb(fbScan),
getUnchalkedHash = UnchalkedHashCb(fbGetUnchalkedHash),
ctArtCallback = ChalkTimeArtifactCb(fbGetChalkTimeArtifactInfo),
rtArtCallback = RunTimeArtifactCb(fbgetRunTimeArtifactInfo))
rtArtCallback = RunTimeArtifactCb(fbGetRunTimeArtifactInfo))
2 changes: 1 addition & 1 deletion src/plugins/codecMacOs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ proc macHandleWrite*(self: Plugin, chalk: ChalkObj, enc: Option[string])
else:
toWrite &= encode(cache.contents)
toWrite &= "\n"
for line in postFixLines:
for line in postfixLines:
toWrite &= line & "\n"

toWrite &= chalk.cachedPreHash & "\n"
Expand Down
Loading

0 comments on commit 58fa4d9

Please sign in to comment.