summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-02-13 11:09:42 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-02-13 11:09:42 +0000
commite35066a63943b0130d4ebb394cc22ab5656d5e71 (patch)
tree919c856bd7511ca5070f6a9dfcd51753d740588f /perl_checker.src
parent8b6a17ac28886904b3669298a89cdb3d08fb7680 (diff)
downloadperl-MDK-Common-e35066a63943b0130d4ebb394cc22ab5656d5e71.tar
perl-MDK-Common-e35066a63943b0130d4ebb394cc22ab5656d5e71.tar.gz
perl-MDK-Common-e35066a63943b0130d4ebb394cc22ab5656d5e71.tar.bz2
perl-MDK-Common-e35066a63943b0130d4ebb394cc22ab5656d5e71.tar.xz
perl-MDK-Common-e35066a63943b0130d4ebb394cc22ab5656d5e71.zip
check use of variables with name _XXX (reserved for unused variables)
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/global_checks.ml5
1 files changed, 4 insertions, 1 deletions
diff --git a/perl_checker.src/global_checks.ml b/perl_checker.src/global_checks.ml
index f94309a..579e2ae 100644
--- a/perl_checker.src/global_checks.ml
+++ b/perl_checker.src/global_checks.ml
@@ -75,6 +75,7 @@ and get_imports state package =
package.imported := Some l ;
l
+let is_anonymous_variable_name s = String.length s > 1 && s.[0] = '_'
let is_my_declared vars t =
List.exists (fun l ->
@@ -138,7 +139,7 @@ let is_global_var context ident =
| "defined" | "delete" | "die"
| "each" | "endpwent" | "eof" | "eval" | "exec" | "exists" | "exit"
| "fcntl" | "fileno" | "flock" | "formline" | "fork"
- | "gethostbyaddr" | "gethostbyname" | "getgrnam" | "getgrgid" | "getppid" | "getpwent" | "getpwnam" | "getpwuid" | "gmtime" | "goto" | "grep" | "hex"
+ | "gethostbyaddr" | "gethostbyname" | "getgrnam" | "getgrgid" | "getppid" | "getpwent" | "getpwnam" | "getpwuid" | "glob" | "gmtime" | "goto" | "grep" | "hex"
| "index" | "int" | "ioctl" | "join" | "keys" | "kill"
| "last" | "lc" | "lcfirst" | "length" | "link" | "localtime" | "log" | "lstat"
| "map" | "mkdir" | "next" | "no" | "oct" | "open" | "opendir" | "ord"
@@ -154,6 +155,8 @@ let is_global_var context ident =
let check_variable (context, var) vars =
match var with
+ | Ident(_, s, pos) when context <> I_func && is_anonymous_variable_name s && s <> "__FILE__" && s <> "__LINE__" ->
+ warn_with_pos pos (sprintf "variable %s must not be used\n (variable with name _XXX are reserved for unused variables)" (variable2s(context, string_of_Ident var)))
| Ident(Some pkg, _, _) when uses_external_package pkg || List.mem pkg !ignored_packages -> ()
| Ident(None, ident, pos) ->
if is_my_declared vars (context, ident) || is_our_declared vars (context, ident) || is_var_declared vars (context, ident) || is_global_var context ident