From e142a99b671cfdd12f0404877cf2d8fbe26daa9d Mon Sep 17 00:00:00 2001 From: Maggie Moss Date: Fri, 28 Jul 2023 12:45:15 -0700 Subject: [PATCH] Mark files ignored in configuration as ignored in pyre report Summary: Noticed while testing different configurations in the tools that unless a file has an explicit ignore comment, it will be marked as the default for the configuration (unsafe or strict) even if it has been explicitly ignored in the configuration. This checks for ignored files from the configuration and applies the appropriate module status Reviewed By: kinto0 Differential Revision: D47851218 fbshipit-source-id: e336338ce39fc92a447480748c03d13e3479845a --- client/commands/report.py | 22 +++++++++++++++------- client/coverage_data.py | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/commands/report.py b/client/commands/report.py index 27431cce57b..321af17dcc7 100644 --- a/client/commands/report.py +++ b/client/commands/report.py @@ -96,8 +96,9 @@ def collect( module: libcst.MetadataWrapper, path: ModulePath, strict_by_default: bool, + ignored: bool, ) -> ModuleData: - mode = coverage_data.collect_mode(module, strict_by_default) + mode = coverage_data.collect_mode(module, strict_by_default, ignored) suppressions = coverage_data.collect_suppressions(module) functions = coverage_data.collect_functions(module) return ModuleData( @@ -118,6 +119,7 @@ class CollectFromPathArgs: path: ModulePath strict_by_default: bool + ignored: bool @staticmethod def collect_from_path( @@ -131,6 +133,7 @@ def collect_from_path( module, path=args.path, strict_by_default=args.strict_by_default, + ignored=args.ignored, ) @staticmethod @@ -138,14 +141,16 @@ def collect_from_paths( module_paths: Sequence[ModulePath], strict_by_default: bool, number_of_workers: int, + ignored_modules: Sequence[ModulePath], ) -> List[ModuleData]: - tasks = [ - ModuleData.CollectFromPathArgs( - path=path, - strict_by_default=strict_by_default, + tasks = [] + for path in module_paths: + ignored = path in ignored_modules + tasks.append( + ModuleData.CollectFromPathArgs( + path=path, strict_by_default=strict_by_default, ignored=ignored + ) ) - for path in module_paths - ] with multiprocessing.Pool(number_of_workers) as pool: return [ module_data @@ -169,10 +174,13 @@ def run( configuration=configuration, paths=paths, ) + ignored_paths = [Path(path) for path in configuration.get_ignore_all_errors()] data = ModuleData.collect_from_paths( module_paths, strict_by_default=configuration.is_strict(), number_of_workers=configuration.get_number_of_workers(), + ignored_modules=get_module_paths(configuration, ignored_paths), ) + print_data_as_json(data) return commands.ExitCode.SUCCESS diff --git a/client/coverage_data.py b/client/coverage_data.py index 0e7557a6b5d..2be082e32f1 100644 --- a/client/coverage_data.py +++ b/client/coverage_data.py @@ -437,11 +437,13 @@ def visit_Comment(self, node: libcst.Comment) -> None: def collect_mode( module: libcst.MetadataWrapper, strict_by_default: bool, + ignored: bool = False, # means the module was ignored in the pyre configuration ) -> ModuleModeInfo: visitor = ModuleModeCollector(strict_by_default) module.visit(visitor) + mode = ModuleMode.IGNORE_ALL if ignored else visitor.mode return ModuleModeInfo( - mode=visitor.mode, + mode=mode, explicit_comment_line=visitor.explicit_comment_line, )