Merge branch 'linter-lib-checks'

This commit is contained in:
Moritz Raabe
2020-07-01 09:31:53 +02:00
2 changed files with 32 additions and 1 deletions

2
rules

Submodule rules updated: e5db226844...a16242d0a5

View File

@@ -203,6 +203,31 @@ class UnusualMetaField(Lint):
return False
class LibRuleNotInLibDirectory(Lint):
name = 'lib rule not found in lib directory'
recommendation = 'Move the rule to the `lib` subdirectory of the rules path'
def check_rule(self, ctx, rule):
if is_nursery_rule(rule):
return False
if 'lib' not in rule.meta:
return False
return '/lib/' not in posixpath.normpath(rule.meta['capa/path'])
class LibRuleHasNamespace(Lint):
name = 'lib rule has a namespace'
recommendation = 'Remove the namespace from the rule'
def check_rule(self, ctx, rule):
if 'lib' not in rule.meta:
return False
return 'namespace' in rule.meta
class FeatureStringTooShort(Lint):
name = 'feature string too short'
recommendation = 'capa only extracts strings with length >= 4; will not match on "{:s}"'
@@ -270,6 +295,8 @@ META_LINTS = (
MissingExampleOffset(),
ExampleFileDNE(),
UnusualMetaField(),
LibRuleNotInLibDirectory(),
LibRuleHasNamespace(),
)
@@ -388,6 +415,10 @@ def collect_samples(path):
continue
if name.endswith('.i64'):
continue
if name.endswith('.frz'):
continue
if name.endswith('.fnames'):
continue
path = os.path.join(root, name)