-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_space_in_file_names.nim
75 lines (62 loc) · 2.25 KB
/
no_space_in_file_names.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
# This file is part of osh-tool.
# <https://github.com/hoijui/osh-tool>
#
# SPDX-FileCopyrightText: 2021 Robin Vobruba <[email protected]>
#
# 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(), "nsifn", "nospace", "no_space", "no_space_in_file_names"]
const ID = srcFileNameBase()
let R_SPACE = re".*\s.*"
type NoSpaceInFileNamesCheck = ref object of Check
type NoSpaceInFileNamesCheckGenerator = ref object of CheckGenerator
method name*(this: NoSpaceInFileNamesCheck): string =
return "No space in file names"
method description*(this: NoSpaceInFileNamesCheck): string =
return """Checks that no file-names in the project contain white-space."""
method why*(this: NoSpaceInFileNamesCheck): string =
return """This makes automatic processing of all the projects files
much easier and less error-prone."""
method sourcePath*(this: NoSpaceInFileNamesCheck): string =
return fs.srcFileName()
method requirements*(this: NoSpaceInFileNamesCheck): CheckReqs =
return {
CheckReq.FilesListRec,
}
method getSignificanceFactors*(this: NoSpaceInFileNamesCheck): CheckSignificance =
return CheckSignificance(
weight: 0.4,
openness: 0.6, # makes the repo easier to work wiht on hte command-line and with scripts
hardware: 0.0,
quality: 0.8,
machineReadability: 1.0,
)
method run*(this: NoSpaceInFileNamesCheck, state: var State): CheckResult =
let config = state.config.checks[ID]
let spacedFiles = filterPathsMatching(state.listFiles(), R_SPACE)
return (if spacedFiles.len == 0:
newCheckResult(config, CheckResultKind.Perfect)
else:
newCheckResult(
config,
CheckResultKind.Bad,
CheckIssueSeverity.Low,
some("Files with spaces in their names (Please consider renaming them):\n\n- " &
spacedFiles.join("\n- ")
)
)
)
method id*(this: NoSpaceInFileNamesCheckGenerator): string =
return ID
method generate*(this: NoSpaceInFileNamesCheckGenerator, config: CheckConfig = this.defaultConfig()): Check =
this.ensureNonConfig(config)
NoSpaceInFileNamesCheck()
proc createGenerator*(): CheckGenerator =
NoSpaceInFileNamesCheckGenerator()