-
Notifications
You must be signed in to change notification settings - Fork 0
/
license_exists.nim
86 lines (73 loc) · 2.67 KB
/
license_exists.nim
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
# This file is part of osh-tool.
# <https://github.com/hoijui/osh-tool>
#
# SPDX-FileCopyrightText: 2021-2023 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import options
import re
import strformat
import tables
import ../check
import ../check_config
import ../state
import ../util/fs
#const IDS = @[srcFileNameBase(), "le", "licex", "license_exists"]
const ID = srcFileNameBase()
let RS_LICENSE = "(?i)^.*(LICEN[SC]E|COPYING).*$"
let R_LICENSE = re(RS_LICENSE)
type LicenseExistsCheck = ref object of Check
type LicenseExistsCheckGenerator = ref object of CheckGenerator
method name*(this: LicenseExistsCheck): string =
return "LICENSE exists"
method description*(this: LicenseExistsCheck): string =
return fmt"""Checks that a LICENSE file exists in the projects root dir, \
using the regex `{RS_LICENSE}`.
Note that this is related to the REUSE lint check."""
method why*(this: LicenseExistsCheck): string =
return """Before REUSE, this was the standard (and only) way
to declare which license(s) are used within the project.
While REUSE is in all ways superior to this approach,
Many platforms and softwares still purely rely on this way
to automatically detect the license(s) of a project.
We thus recommend to keep the "main"
(according ot your subjective decission)
license of the project in such a file,
by first fixing REUSE for the project,
and then running a command similar to:
`cp LICENSES/CERN-OHL-S-2.0.txt LICENSE.txt`"""
method sourcePath*(this: LicenseExistsCheck): string =
return fs.srcFileName()
method requirements*(this: LicenseExistsCheck): CheckReqs =
return {
CheckReq.FilesListL1,
}
method getSignificanceFactors*(this: LicenseExistsCheck): CheckSignificance =
return CheckSignificance(
weight: 0.2,
openness: 1.0,
hardware: 0.0,
quality: 0.05,
machineReadability: 1.0,
)
method run*(this: LicenseExistsCheck, state: var State): CheckResult =
# TODO Add checks for REUSE bom, or check the output of `reuse --lint`
let config = state.config.checks[ID]
return (if filterPathsMatching(state.listFilesL1(), R_LICENSE).len > 0:
newCheckResult(config, CheckResultKind.Perfect)
else:
newCheckResult(
config,
CheckResultKind.Bad,
CheckIssueSeverity.High,
some("""No LICENSE (or COPYING) file found in the root directory.
Please consider adding a LICENSE(.md).""")
)
)
method id*(this: LicenseExistsCheckGenerator): string =
return ID
method generate*(this: LicenseExistsCheckGenerator, config: CheckConfig = this.defaultConfig()): Check =
this.ensureNonConfig(config)
LicenseExistsCheck()
proc createGenerator*(): CheckGenerator =
LicenseExistsCheckGenerator()