From 5049a4173aa8e9cb500a7689e7cdf4cd2d5ffb0d Mon Sep 17 00:00:00 2001 From: PapaMuziko Date: Wed, 21 Dec 2016 16:21:31 -0800 Subject: [PATCH] Add option to --allow-global-variables --- betty-style.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/betty-style.pl b/betty-style.pl index f5d7a74..4c84741 100755 --- a/betty-style.pl +++ b/betty-style.pl @@ -52,6 +52,7 @@ my $max_func_length = 40; my $max_funcs = 5; my $safe_guard = 1; +my $allow_global_variables = 0; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; @@ -131,6 +132,7 @@ sub help { (default: 5) Set it to -1 for infinite --no-safe-guard Don't check for header files protection + --allow-global-variables Allow global variable definition -h, --help, --version Display this help and exit @@ -231,7 +233,8 @@ sub list_types { 'max-line-length=i' => \$max_line_length, 'max-func-length=i' => \$max_func_length, 'max-funcs=i' => \$max_funcs, - 'safe-guard!' => \$safe_guard + 'safe-guard!' => \$safe_guard, + 'allow-global-variables!' => \$allow_global_variables, ) or help(1); help(0) if ($help); @@ -3565,12 +3568,14 @@ sub process { } # Check for global variables (not allowed). - if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ || - $line =~ /^\+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || - $line =~ /^\+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || - $line =~ /^\+$declaration_macros/) { - ERROR("GLOBAL_DECLARATION", - "global variables are not allowed\n" . $herecurr); + if ($allow_global_variables == 0) { + if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*(?:\s*=\s*.*)?;/ || + $line =~ /^\+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || + $line =~ /^\+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + $line =~ /^\+$declaration_macros/) { + ERROR("GLOBAL_DECLARATION", + "global variables are not allowed\n" . $herecurr); + } } # check for global initialisers.