Skip to content

Commit 56ac492

Browse files
committed
chore: split checks into rules
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
1 parent 076b968 commit 56ac492

16 files changed

+875
-899
lines changed

src/crs_linter/cli.py

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dulwich.contrib.release_robot import get_current_version, get_recent_tags
1111
from semver import Version
1212

13-
from crs_linter.linter import Check
13+
from crs_linter.linter import Linter
1414
from crs_linter.logger import Logger
1515

1616

@@ -124,49 +124,6 @@ def get_crs_version(directory, version=None):
124124
return crs_version
125125

126126

127-
def check_indentation(filename, content):
128-
error = False
129-
130-
### make a diff to check the indentations
131-
try:
132-
with open(filename, "r") as fp:
133-
from_lines = fp.readlines()
134-
if filename.startswith("crs-setup.conf.example"):
135-
from_lines = remove_comments("".join(from_lines)).split("\n")
136-
from_lines = [l + "\n" for l in from_lines]
137-
except:
138-
logger.error(f"Can't open file for indentation check: {filename}")
139-
error = True
140-
141-
# virtual output
142-
writer = msc_pyparser.MSCWriter(content)
143-
writer.generate()
144-
output = []
145-
for l in writer.output:
146-
output += [l + "\n" for l in l.split("\n") if l != "\n"]
147-
148-
if len(from_lines) < len(output):
149-
from_lines.append("\n")
150-
elif len(from_lines) > len(output):
151-
output.append("\n")
152-
153-
diff = difflib.unified_diff(from_lines, output)
154-
if from_lines == output:
155-
logger.debug("Indentation check ok.")
156-
else:
157-
logger.debug("Indentation check found error(s)")
158-
error = True
159-
160-
for d in diff:
161-
d = d.strip("\n")
162-
r = re.match(r"^@@ -(\d+),(\d+) \+\d+,\d+ @@$", d)
163-
if r:
164-
line1, line2 = [int(i) for i in r.groups()]
165-
logger.error("an indentation error was found", file=filename, title="Indentation error", line=line1, end_line=line1 + line2)
166-
167-
return error
168-
169-
170127
def read_files(filenames):
171128
global logger
172129

@@ -218,7 +175,7 @@ def _version_in_argv(argv):
218175
def parse_args(argv):
219176
print(argv)
220177
parser = argparse.ArgumentParser(
221-
prog="crs-linter", description="CRS Rules Check tool"
178+
prog="crs-linter", description="CRS Rules Linter tool"
222179
)
223180
parser.add_argument(
224181
"-o",
@@ -258,7 +215,7 @@ def parse_args(argv):
258215
required=True,
259216
)
260217
parser.add_argument(
261-
"-v", "--version", dest="version", help="Check that the passed version string is used correctly.", required=False
218+
"-v", "--version", dest="version", help="Linter that the passed version string is used correctly.", required=False
262219
)
263220

264221
return parser.parse_args(argv)
@@ -284,7 +241,8 @@ def main():
284241
for f in parsed.keys():
285242
logger.start_group(f)
286243
logger.debug(f)
287-
c = Check(parsed[f], f, txvars)
244+
c = Linter(parsed[f], f, txvars)
245+
288246

289247
### check case usings
290248
c.check_ignore_case()

0 commit comments

Comments
 (0)