-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathno_generated_files.nim
More file actions
91 lines (76 loc) · 3.05 KB
/
Copy pathno_generated_files.nim
File metadata and controls
91 lines (76 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# This file is part of osh-tool.
# <https://github.com/hoijui/osh-tool>
#
# SPDX-FileCopyrightText: 2021-2023 Robin Vobruba <hoijui.quaero@gmail.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from strutils import join
import options
import re
import tables
import ../check
import ../check_config
import ../state
import ../util/fs
#const IDS = @[srcFileNameBase(), "ngf", "nogenf", "no_generated_files"]
const ID = srcFileNameBase()
let R_GENERATABLE= re"^.*[.](jpg|jpeg|gif|png|bmp|pdf|stl|zip|jar)$" # TODO Add much more, and maybe move this list to a CSV file
type NoGeneratedFilesCheck = ref object of Check
type NoGeneratedFilesCheckGenerator = ref object of CheckGenerator
method name*(this: NoGeneratedFilesCheck): string =
return "No generated files"
method description*(this: NoGeneratedFilesCheck): string =
return """Checks that no generated files are part of the project. \
These are usually files that are created using a software \
that is manually configured and executed by a human. \
Try instead, to find a way to automate this process, \
and to not store the resulting files in the repository."""
method why*(this: NoGeneratedFilesCheck): string =
return """1. The projects storage requirements go down - \
usually by a lot
2. There are no outdated generated files,
because of either of these two reasons:
- One only gets the files hwen generating them right when required, or
- They are regenerated in CI/build-bot and uploaded/hosted on the project pages
whenever there is a change (e.g. a git push to to the repo)
NOTE: This is one of the more controversial checks,
as it often requires writing new software.
That is sometimes a simple script,
and sometimes complex software requiring many person-months of development."""
method sourcePath*(this: NoGeneratedFilesCheck): string =
return fs.srcFileName()
method requirements*(this: NoGeneratedFilesCheck): CheckReqs =
return {
CheckReq.FilesListRecNonGen,
}
method getSignificanceFactors*(this: NoGeneratedFilesCheck): CheckSignificance =
return CheckSignificance(
weight: 0.5,
openness: 0.6, # because the repo could be less heavy and thus easier to host/share/exchange
hardware: 0.0,
quality: 0.5,
machineReadability: 0.3,
)
method run*(this: NoGeneratedFilesCheck, state: var State): CheckResult =
let config = state.config.checks[ID]
let foundFiles = filterPathsMatchingFileName(state.listFilesNonGenerated(), R_GENERATABLE)
return (if foundFiles.len == 0:
newCheckResult(config, CheckResultKind.Perfect)
else:
newCheckResult(
config,
CheckResultKind.Bad,
CheckIssueSeverity.Low,
some(
"Possibly generatable files found. Please consider removing them:\n\n- " &
foundFiles.join("\n- ")
)
)
)
method id*(this: NoGeneratedFilesCheckGenerator): string =
return ID
method generate*(this: NoGeneratedFilesCheckGenerator, config: CheckConfig = this.defaultConfig()): Check =
this.ensureNonConfig(config)
NoGeneratedFilesCheck()
proc createGenerator*(): CheckGenerator =
NoGeneratedFilesCheckGenerator()