Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
a25dd24d
Commit
a25dd24d
authored
2 years ago
by
Patrick Baudin
Committed by
Andre Maroneze
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[lint] adds -s option for strict mode
parent
67a5c415
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/lint/lint.ml
+34
-22
34 additions, 22 deletions
tools/lint/lint.ml
with
34 additions
and
22 deletions
tools/lint/lint.ml
+
34
−
22
View file @
a25dd24d
...
@@ -22,6 +22,23 @@
...
@@ -22,6 +22,23 @@
open
CamomileLibrary
open
CamomileLibrary
(**************************************************************************)
(* Warning/Error *)
let
strict
=
ref
false
let
res
=
ref
true
(* impact the exit value *)
let
warn
ftext
=
if
!
strict
then
res
:=
false
;
Format
.
eprintf
"Warning: "
;
Format
.
eprintf
ftext
let
error
ftext
=
res
:=
false
;
Format
.
eprintf
ftext
(**************************************************************************)
(**************************************************************************)
(* Utils *)
(* Utils *)
...
@@ -91,7 +108,7 @@ let parse_indent_formatter ~file ~attr ~value = match value with
...
@@ -91,7 +108,7 @@ let parse_indent_formatter ~file ~attr ~value = match value with
|
"ocp-indent"
->
Check
(
Some
ml_indent_formatter
)
|
"ocp-indent"
->
Check
(
Some
ml_indent_formatter
)
|
"clang-format"
->
Check
(
Some
(
Tool
c_indent_formatter
))
|
"clang-format"
->
Check
(
Some
(
Tool
c_indent_formatter
))
|
"black"
->
Check
(
Some
(
Tool
python_indent_formatter
))
|
"black"
->
Check
(
Some
(
Tool
python_indent_formatter
))
|
_
->
Format
.
eprintf
"Unsupported indent formatter: %s %s=%s@."
|
_
->
warn
"Unsupported indent formatter: %s %s=%s@."
file
attr
value
;
file
attr
value
;
NoCheck
NoCheck
...
@@ -116,7 +133,7 @@ let add_attr ~file ~attr ~value checks =
...
@@ -116,7 +133,7 @@ let add_attr ~file ~attr ~value checks =
let
is_set
=
function
let
is_set
=
function
|
"set"
->
true
|
"set"
->
true
|
"unset"
->
false
|
"unset"
->
false
|
_
->
failwith
(
Format
.
sprintf
"Invalid attribute value: %s %s=%s"
file
attr
value
)
|
_
->
warn
"Invalid attribute value: %s %s=%s"
file
attr
value
;
false
in
in
match
attr
with
match
attr
with
|
"check-eoleof"
->
{
checks
with
eoleof
=
is_set
value
}
|
"check-eoleof"
->
{
checks
with
eoleof
=
is_set
value
}
...
@@ -124,7 +141,8 @@ let add_attr ~file ~attr ~value checks =
...
@@ -124,7 +141,8 @@ let add_attr ~file ~attr ~value checks =
|
"check-utf8"
->
{
checks
with
utf8
=
is_set
value
}
|
"check-utf8"
->
{
checks
with
utf8
=
is_set
value
}
|
"check-indent"
->
{
checks
with
|
"check-indent"
->
{
checks
with
indent
=
parse_indent_formatter
~
file
~
attr
~
value
}
indent
=
parse_indent_formatter
~
file
~
attr
~
value
}
|
_
->
failwith
(
Format
.
sprintf
"Unknown attribute: %s %s=%s"
file
attr
value
)
|
_
->
warn
"Unknown attribute: %s %s=%s"
file
attr
value
;
checks
let
handled_attr
s
=
let
handled_attr
s
=
s
=
"check-eoleof"
||
s
=
"check-indent"
||
s
=
"check-eoleof"
||
s
=
"check-indent"
||
...
@@ -150,8 +168,8 @@ let rec collect = function
...
@@ -150,8 +168,8 @@ let rec collect = function
Hashtbl
.
replace
table
file
(
add_attr
~
file
~
attr
~
value
checks
)
;
Hashtbl
.
replace
table
file
(
add_attr
~
file
~
attr
~
value
checks
)
;
collect
tl
collect
tl
|
[]
->
()
|
[]
->
()
|
[
file
;
attr
]
->
Format
.
eprintf
"Missing attribute value: %s %s=?@."
file
attr
|
[
file
;
attr
]
->
warn
"Missing attribute value: %s %s=?@."
file
attr
|
[
file
]
->
Format
.
eprintf
"Missing attribute name for file: %s@."
file
|
[
file
]
->
warn
"Missing attribute name for file: %s@."
file
(**************************************************************************)
(**************************************************************************)
(* Functions used to check lint *)
(* Functions used to check lint *)
...
@@ -236,7 +254,7 @@ let config () =
...
@@ -236,7 +254,7 @@ let config () =
(
fun
stx
->
(
fun
stx
->
try
Approx_lexer
.
enable_extension
stx
try
Approx_lexer
.
enable_extension
stx
with
IndentExtend
.
Syntax_not_found
name
->
with
IndentExtend
.
Syntax_not_found
name
->
Format
.
eprintf
"Warning: u
nknown syntax extension %S@."
name
)
warn
"U
nknown syntax extension %S@."
name
)
syntaxes
;
syntaxes
;
global_config
:=
Some
config
;
global_config
:=
Some
config
;
config
config
...
@@ -277,7 +295,7 @@ let is_formatter_available ~file indent_formatter =
...
@@ -277,7 +295,7 @@ let is_formatter_available ~file indent_formatter =
let
is_available
=
(
0
=
Sys
.
command
indent_formatter
.
available_cmd
)
in
let
is_available
=
(
0
=
Sys
.
command
indent_formatter
.
available_cmd
)
in
indent_formatter
.
is_available
<-
Some
is_available
;
indent_formatter
.
is_available
<-
Some
is_available
;
if
not
is_available
then
if
not
is_available
then
Format
.
eprintf
"Warning:
%s is unavailable for checking some %s files (i.e. %s)@."
warn
"
%s is unavailable for checking
indentation of
some %s files (i.e. %s)@."
indent_formatter
.
name
indent_formatter
.
kind
file
;
indent_formatter
.
name
indent_formatter
.
kind
file
;
is_available
is_available
|
Some
is_available
->
is_available
|
Some
is_available
->
is_available
...
@@ -303,8 +321,6 @@ let check_indent ~indent_formatter ~update file =
...
@@ -303,8 +321,6 @@ let check_indent ~indent_formatter ~update file =
0
=
Sys
.
command
(
Format
.
sprintf
"%s
\"
%s
\"
"
indent_formatter
.
update_cmd
file
)
0
=
Sys
.
command
(
Format
.
sprintf
"%s
\"
%s
\"
"
indent_formatter
.
update_cmd
file
)
else
true
(* there no updating command *)
else
true
(* there no updating command *)
let
res
=
ref
true
(* Main checks *)
(* Main checks *)
let
check
~
verbose
~
update
file
params
=
let
check
~
verbose
~
update
file
params
=
...
@@ -317,10 +333,8 @@ let check ~verbose ~update file params =
...
@@ -317,10 +333,8 @@ let check ~verbose ~update file params =
close_in
in_chan
;
close_in
in_chan
;
(* UTF8 *)
(* UTF8 *)
if
params
.
utf8
then
if
params
.
utf8
then
if
not
@@
is_utf8
content
then
begin
if
not
@@
is_utf8
content
then
Format
.
eprintf
"Bad encoding (not UTF8) for %s@."
file
;
error
"Bad encoding (not UTF8) for %s@."
file
;
res
:=
false
end
;
(* Blanks *)
(* Blanks *)
let
rewrite
=
ref
false
in
let
rewrite
=
ref
false
in
let
syntactic_check
checker
content
message
=
let
syntactic_check
checker
content
message
=
...
@@ -328,8 +342,8 @@ let check ~verbose ~update file params =
...
@@ -328,8 +342,8 @@ let check ~verbose ~update file params =
if
update
&&
not
was_ok
if
update
&&
not
was_ok
then
begin
rewrite
:=
true
;
new_content
end
then
begin
rewrite
:=
true
;
new_content
end
else
if
not
was_ok
then
begin
else
if
not
was_ok
then
begin
Format
.
eprintf
"%s for %s@."
message
file
;
error
"%s for %s@."
message
file
;
res
:=
false
;
new_content
new_content
end
end
else
new_content
else
new_content
in
in
...
@@ -354,14 +368,11 @@ let check ~verbose ~update file params =
...
@@ -354,14 +368,11 @@ let check ~verbose ~update file params =
match
params
.
indent
with
match
params
.
indent
with
|
NoCheck
->
()
|
NoCheck
->
()
|
Check
indent_formatter
->
|
Check
indent_formatter
->
if
not
@@
check_indent
~
indent_formatter
~
update
file
then
begin
if
not
@@
check_indent
~
indent_formatter
~
update
file
then
Format
.
eprintf
"Bad indentation for %s@."
file
;
error
"Bad indentation for %s@."
file
;
res
:=
false
end
;
end
;
end
;
with
Bad_ext
->
with
Bad_ext
->
Format
.
eprintf
"Don't know how to (check) indent %s@."
file
;
error
"Don't know how to (check) indent %s@."
file
res
:=
false
end
end
(**************************************************************************)
(**************************************************************************)
...
@@ -374,6 +385,7 @@ let verbose = ref false
...
@@ -374,6 +385,7 @@ let verbose = ref false
let
argspec
=
[
let
argspec
=
[
"-u"
,
Arg
.
Set
update
,
" update ill-formed files (does not handle UTF8 update)"
;
"-u"
,
Arg
.
Set
update
,
" update ill-formed files (does not handle UTF8 update)"
;
"-v"
,
Arg
.
Set
verbose
,
" verbose mode"
;
"-v"
,
Arg
.
Set
verbose
,
" verbose mode"
;
"-s"
,
Arg
.
Set
strict
,
" considers warnings as errors for the exit value"
;
]
]
let
sort
argspec
=
let
sort
argspec
=
List
.
sort
(
fun
(
name1
,
_
,
_
)
(
name2
,
_
,
_
)
->
String
.
compare
name1
name2
)
List
.
sort
(
fun
(
name1
,
_
,
_
)
(
name2
,
_
,
_
)
->
String
.
compare
name1
name2
)
...
@@ -385,7 +397,7 @@ let sort argspec =
...
@@ -385,7 +397,7 @@ let sort argspec =
let
()
=
let
()
=
Arg
.
parse
Arg
.
parse
(
Arg
.
align
(
sort
argspec
))
(
Arg
.
align
(
sort
argspec
))
(
fun
s
->
Format
.
eprintf
"Unknown argument: %s"
s
)
(
fun
s
->
warn
"Unknown argument: %s
@.
"
s
)
(
"Usage: git ls-files -z | git check-attr --stdin -z -a | "
^
exec_name
^
" [options]"
);
(
"Usage: git ls-files -z | git check-attr --stdin -z -a | "
^
exec_name
^
" [options]"
);
collect
@@
lines_from_in
stdin
;
collect
@@
lines_from_in
stdin
;
Hashtbl
.
iter
(
check
~
verbose
:!
verbose
~
update
:!
update
)
table
;
Hashtbl
.
iter
(
check
~
verbose
:!
verbose
~
update
:!
update
)
table
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment