mirror of
https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git
synced 2025-09-07 06:55:45 +00:00
Add an indent checker, fix some lines that break it
This is pretty dumb and breaks on valid code, but it's okay enough for our purposes I think. If I made it any more complex I'd want to start looking for a third party parser. Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
parent
f0b9bd3e94
commit
0d0c79eecc
@ -21,7 +21,8 @@ sub post_fail_hook {
|
||||
if (check_screen "anaconda_error_report", 10) {
|
||||
assert_and_click "anaconda_error_report";
|
||||
$has_traceback = 1;
|
||||
} elsif (check_screen "anaconda_text_error", 10) { # also for text install
|
||||
} elsif (check_screen "anaconda_text_error", 10) {
|
||||
# also for text install
|
||||
type_string "1\n";
|
||||
$has_traceback = 1;
|
||||
}
|
||||
@ -128,7 +129,8 @@ sub root_console {
|
||||
# 0 means use console_login's default, non-zero values
|
||||
# passed to console_login
|
||||
timeout => 0,
|
||||
@_);
|
||||
@_
|
||||
);
|
||||
if (get_var("SERIAL_CONSOLE")) {
|
||||
# select first virtio terminal, we rely on anaconda having run
|
||||
# a root shell on it for us
|
||||
|
@ -18,7 +18,8 @@ sub root_console {
|
||||
my %args = (
|
||||
tty => 1, # what TTY to login to
|
||||
timeout => 0, # passed through to console_login
|
||||
@_);
|
||||
@_
|
||||
);
|
||||
if (get_var("SERIAL_CONSOLE")) {
|
||||
# select the first virtio terminal, for now we assume we can
|
||||
# always use that (we may have to make this smarter in future)
|
||||
|
@ -150,7 +150,8 @@ sub console_login {
|
||||
password => get_var("ROOT_PASSWORD", "weakpassword"),
|
||||
# default is 10 seconds, set below, 0 means 'default'
|
||||
timeout => 0,
|
||||
@_);
|
||||
@_
|
||||
);
|
||||
$args{timeout} ||= 10;
|
||||
|
||||
# Since we do not test many serial console tests, and we probably
|
||||
|
57
perllint.py
57
perllint.py
@ -24,14 +24,17 @@ if any line contains a tab, ends with whitespace characters (which
|
||||
includes lines containing *only* whitespace characters), or starts
|
||||
with a number of spaces that is not divisible by four. If run with
|
||||
--write, it will strip trailing whitespace (including turning lines
|
||||
that contain only whitespace into blank lines). It does not currently
|
||||
attempt to replace tabs or correct leading whitespace.
|
||||
that contain only whitespace into blank lines) and correct indentation
|
||||
(including removing tabs in indentation). It does not do anything
|
||||
with tabs found outside of leading indentation.
|
||||
"""
|
||||
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
HEREDOCRE = re.compile(r"<<['\"]?(\w*)['\"]?;\s*$")
|
||||
|
||||
def run(write):
|
||||
"""
|
||||
@ -57,12 +60,19 @@ def check_file(filename, write):
|
||||
with open(filename, "r", encoding="UTF-8") as readfh:
|
||||
lines = readfh.readlines()
|
||||
newlines = []
|
||||
indent = 0
|
||||
# indicator whether we're in a heredoc block
|
||||
heredoc = None
|
||||
for (num, line) in enumerate(lines, 1):
|
||||
# tab check
|
||||
if "\t" in line:
|
||||
print(f"Line {num} of file {filename} contains a tab!")
|
||||
failed = True
|
||||
|
||||
# if we're in a heredoc, skip all checks, and see if we
|
||||
# ended it
|
||||
if heredoc:
|
||||
if line.strip(" \t").rstrip(" \t\n") == heredoc:
|
||||
heredoc = None
|
||||
# write the line back to newlines
|
||||
if write:
|
||||
newlines.append(line)
|
||||
continue
|
||||
# trailing whitespace check and replace
|
||||
newline = line.rstrip("\n").rstrip(" \t") + "\n"
|
||||
if newline != line:
|
||||
@ -74,16 +84,45 @@ def check_file(filename, write):
|
||||
line = newline
|
||||
|
||||
# correct number of starting spaces check
|
||||
# skip non-indented comment lines
|
||||
if line.startswith("# "):
|
||||
# write the line back to newlines
|
||||
if write:
|
||||
newlines.append(line)
|
||||
continue
|
||||
# first update indent if line closes a block
|
||||
if line.strip(" \t").startswith("}") or line.strip(" \t").startswith(")"):
|
||||
indent -= 4
|
||||
spaces = 0
|
||||
for char in line:
|
||||
if char != " ":
|
||||
break
|
||||
spaces += 1
|
||||
if spaces > 0 and spaces % 4 != 0:
|
||||
if spaces != indent and line != "\n":
|
||||
print(
|
||||
f"Line {num} of file {filename} starts with an invalid number of spaces!"
|
||||
f"Line {num} of file {filename} starts with an invalid number of spaces! Expected {indent} got {spaces}"
|
||||
)
|
||||
failed = True
|
||||
if write:
|
||||
line = line.lstrip()
|
||||
if line.startswith("\t"):
|
||||
print(f"Line {num} of file {filename} has a tab in leading whitespace!")
|
||||
line = line.strip(" \t")
|
||||
line = " " * indent + line
|
||||
# now update indent if line opens a block (and isn't a comment)
|
||||
if not line.strip(" \t").startswith("#"):
|
||||
if line.rstrip(" \t\n").endswith("{") or line.rstrip(" \t\n").endswith("("):
|
||||
indent += 4
|
||||
|
||||
# tab check
|
||||
if "\t" in line:
|
||||
print(f"Line {num} of file {filename} contains a tab!")
|
||||
failed = True
|
||||
|
||||
# did the line start a heredoc?
|
||||
herematch = HEREDOCRE.search(line)
|
||||
if herematch:
|
||||
heredoc = herematch.group(1)
|
||||
|
||||
# write the line back to newlines
|
||||
if write:
|
||||
|
Loading…
Reference in New Issue
Block a user