tests(check): add support for '#aa:lint ignore' inline directive to disable linting.
This commit is contained in:
parent
f6914a8730
commit
b2910ae593
2 changed files with 19 additions and 1 deletions
|
|
@ -106,6 +106,9 @@ func Run(file *paths.Path, profile string) (string, error) {
|
||||||
opt := NewOption(file, match)
|
opt := NewOption(file, match)
|
||||||
drtv, ok := Directives[opt.Name]
|
drtv, ok := Directives[opt.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if opt.Name == "lint" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
return "", fmt.Errorf("unknown directive '%s' in %s", opt.Name, opt.File)
|
return "", fmt.Errorf("unknown directive '%s' in %s", opt.Name, opt.File)
|
||||||
}
|
}
|
||||||
profile, err = drtv.Apply(opt, profile)
|
profile, err = drtv.Apply(opt, profile)
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,24 @@ _wait() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readonly _IGNORE_LINT="#aa:lint ignore"
|
||||||
|
_ignore_lint() {
|
||||||
|
local line="$1"
|
||||||
|
if [[ "$line" == *"$_IGNORE_LINT"* ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
_check() {
|
_check() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local line_number=0
|
local line_number=0
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
line_number=$((line_number + 1))
|
line_number=$((line_number + 1))
|
||||||
|
if _ignore_lint "$line"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# Rules checks
|
# Rules checks
|
||||||
_check_abstractions
|
_check_abstractions
|
||||||
|
|
@ -339,7 +351,10 @@ check_sbin() {
|
||||||
jobs=0
|
jobs=0
|
||||||
for name in "${sbin[@]}"; do
|
for name in "${sbin[@]}"; do
|
||||||
(
|
(
|
||||||
mapfile -t files < <(grep --line-number --recursive -E "(^|[[:space:]])@{bin}/$name([[:space:]]|$)" apparmor.d | cut -d: -f1,2)
|
mapfile -t files < <(
|
||||||
|
grep --line-number --recursive -P "(^|[[:space:]])@{bin}/$name([[:space:]]|$)(?!.*$_IGNORE_LINT)" apparmor.d |
|
||||||
|
cut -d: -f1,2
|
||||||
|
)
|
||||||
for file in "${files[@]}"; do
|
for file in "${files[@]}"; do
|
||||||
_err compatibility "$file" "contains '@{bin}/$name' instead of '@{sbin}/$name'"
|
_err compatibility "$file" "contains '@{bin}/$name' instead of '@{sbin}/$name'"
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue