def dump_check_for_all_file_types(): """Implement the --dump-checks command-line switch. :rtype: None """ from asclib import get_system_config_default_filename from asclib.config import Config config = Config(get_system_config_default_filename(), 'nothing', None, 2006) gnat_config = Config(get_system_config_default_filename(), 'gnat', None, 2006) from asclib.checkers.typific.ada import AdaFileChecker AdaFileChecker('a.ads', config).dump_checks('STD_ADA', print_header=True) AdaFileChecker('a-a.ads', gnat_config).dump_checks('RT_SPEC') AdaFileChecker('a-a.adb', gnat_config).dump_checks('RT_BODY') AdaFileChecker('bla.adb', gnat_config).dump_checks('COMPILER_CORE') from asclib.checkers.typific.c import CFileChecker CFileChecker('c.h', config).dump_checks('C') from asclib.checkers.typific.java import JavaFileChecker JavaFileChecker('j.java', config).dump_checks('JAVA') from asclib.checkers.typific.texi import TexiFileChecker TexiFileChecker('h.texi', config).dump_checks('TEXI') from asclib.checkers.typific.sh import ShFileChecker ShFileChecker('s', config).dump_checks('SH') from asclib.checkers.typific.bash import BashFileChecker BashFileChecker('b', config).dump_checks('BASH') from asclib.checkers.typific.csh import CshFileChecker CshFileChecker('c', config).dump_checks('CSH') from asclib.checkers.typific.python import PythonFileChecker PythonFileChecker('p.py', config).dump_checks('PYTHON') from asclib.checkers.typific.perl import PerlFileChecker PerlFileChecker('p.pl', config).dump_checks('PERL') from asclib.checkers.typific.javascript import JavascriptFileChecker JavascriptFileChecker('j.js', config).dump_checks('JAVASCRIPT') from asclib.checkers.typific.acceleo import AcceleoFileChecker AcceleoFileChecker('a.mtl', config).dump_checks('ACCELEO') from asclib.checkers.typific.m import MFileChecker MFileChecker('a.m', config).dump_checks('.M FILES') from asclib.checkers.typific.rst import RstFileChecker RstFileChecker('a.rst', config).dump_checks('REST', print_footer=True)
def style_checker(argv=None): """Run the style checker with the given command-line arguments. :param argv: Same as in parse_cmdline. :type argv: list[str] | None """ args = parse_cmdline(argv) asclib.logging.logging_level = args.verbose_level if not args.filenames: # No filename provided, which means the user wants us to # read the list of filesnames from standard input. args.filenames = [ filename for filename in sys.stdin.read().splitlines() if filename ] config = Config( args.system_config, args.module_name, args.module_config, args.forced_year ) n_files_with_errors = 0 for filename in args.filenames: try: # Before even trying to launch the style checker, first verify # that the file exists, and if it doesn't then report the error, # and look at the next file to check... if not os.path.isfile(filename): raise FileCheckerError( "Error: `%s' is not a valid filename." % filename ) checker = get_file_checker(filename, config) if checker is None: # No checks for this kind of file. continue checker.check_file() except FileCheckerError as e: n_files_with_errors += 1 if n_files_with_errors > args.max_files_with_errors: log_error("[other files with style violations were found]") break else: log_error(e.args) return n_files_with_errors == 0
def test_comment_re_with_no_end_dollar(self): """test first_line_comment with regexp not ending with '$'. At the moment, there is no language where that is the case, so we need to resort to Unit Testing. """ self.enable_unit_test() from asclib import get_system_config_default_filename from asclib.config import Config from asclib.checkers.typific.c import CFileChecker from asclib.checkers import FileCheckerError CFileChecker.typific_info.comment_line_re = r'/\**' CFileChecker.rulific_decision_map['first_line_comment'] = True config = Config(get_system_config_default_filename(), 'supermod', None, 2006) c_checker = CFileChecker('hello-no-first-line-comment.c', config) with self.assertRaises(FileCheckerError) as cm: c_checker.check_file() expected_output = '''\ hello-no-first-line-comment.c:1: First line must start with a comment (regexp: /\**)''' self.assertOutputEqual(expected_output, str(cm.exception))
def dump_check_for_all_file_types(): """Implement the --dump-checks command-line switch. :rtype: None """ from asclib import get_system_config_default_filename from asclib.config import Config config = Config(get_system_config_default_filename(), "nothing", None, 2006) gnat_config = Config(get_system_config_default_filename(), "gnat", None, 2006) from asclib.checkers.typific.ada import AdaFileChecker AdaFileChecker("a.ads", config).dump_checks("STD_ADA", print_header=True) AdaFileChecker("a-a.ads", gnat_config).dump_checks("RT_SPEC") AdaFileChecker("a-a.adb", gnat_config).dump_checks("RT_BODY") AdaFileChecker("bla.adb", gnat_config).dump_checks("COMPILER_CORE") from asclib.checkers.typific.c import CFileChecker CFileChecker("c.h", config).dump_checks("C") from asclib.checkers.typific.java import JavaFileChecker JavaFileChecker("j.java", config).dump_checks("JAVA") from asclib.checkers.typific.texi import TexiFileChecker TexiFileChecker("h.texi", config).dump_checks("TEXI") from asclib.checkers.typific.sh import ShFileChecker ShFileChecker("s", config).dump_checks("SH") from asclib.checkers.typific.bash import BashFileChecker BashFileChecker("b", config).dump_checks("BASH") from asclib.checkers.typific.csh import CshFileChecker CshFileChecker("c", config).dump_checks("CSH") from asclib.checkers.typific.python import PythonFileChecker PythonFileChecker("p.py", config).dump_checks("PYTHON") from asclib.checkers.typific.perl import PerlFileChecker PerlFileChecker("p.pl", config).dump_checks("PERL") from asclib.checkers.typific.acceleo import AcceleoFileChecker AcceleoFileChecker("a.mtl", config).dump_checks("ACCELEO") from asclib.checkers.typific.m import MFileChecker MFileChecker("a.m", config).dump_checks(".M FILES") from asclib.checkers.typific.rst import RstFileChecker RstFileChecker("a.rst", config).dump_checks("REST", print_footer=True)