Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gitlint
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Antti Tanhuanpää
gitlint
Commits
f47f7997
Commit
f47f7997
authored
Mar 08, 2017
by
Antti Tanhuanpää
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Interactive mode
parent
657888e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
10 deletions
+136
-10
gitlint
gitlint
+136
-10
No files found.
gitlint
View file @
f47f7997
...
...
@@ -4,6 +4,7 @@ from os import path
import
shlex
import
subprocess
import
sys
import
termios
linters
=
{
...
...
@@ -17,6 +18,81 @@ class NoLinterFound(Exception):
pass
class
Terminal
:
class
ReadChar
:
def
__init__
(
self
,
file
):
self
.
file
=
file
def
readchar
(
self
,
default
=
None
):
b
=
self
.
file
.
read
(
1
)
c
=
b
.
decode
()
if
c
.
isprintable
():
return
c
return
default
def
__init__
(
self
,
dev
=
'/dev/tty'
):
self
.
dev
=
dev
self
.
file
=
None
self
.
tcattrs
=
None
def
__enter__
(
self
):
self
.
file
=
open
(
self
.
dev
,
'rb'
,
buffering
=
0
)
try
:
self
.
set_non_canon
()
except
Exception
as
exc
:
self
.
reset
()
raise
exc
return
self
.
ReadChar
(
self
.
file
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
exc_tb
):
self
.
reset
()
return
False
def
reset
(
self
):
file
=
self
.
file
tcattrs
=
self
.
tcattrs
self
.
file
=
None
self
.
tcattrs
=
None
if
file
:
if
tcattrs
:
self
.
set_tcattrs
(
tcattrs
,
fd
=
file
.
fileno
())
file
.
close
()
def
set_non_canon
(
self
):
fd
=
self
.
file
.
fileno
()
self
.
tcattrs
=
termios
.
tcgetattr
(
fd
)
iflag
,
oflag
,
cflag
,
lflag
,
ispeed
,
ospeed
,
cc
=
self
.
tcattrs
lflag
&=
~
(
termios
.
ECHO
|
termios
.
ICANON
)
self
.
set_tcattrs
([
iflag
,
oflag
,
cflag
,
lflag
,
ispeed
,
ospeed
,
cc
])
def
set_tcattrs
(
self
,
attrs
,
fd
=
None
):
if
fd
is
None
:
fd
=
self
.
file
.
fileno
()
termios
.
tcsetattr
(
fd
,
termios
.
TCSAFLUSH
,
attrs
)
def
get_files
():
files
=
[]
while
True
:
line
=
sys
.
stdin
.
readline
()
if
not
line
:
break
filename
=
line
.
strip
()
files
.
append
(
filename
)
return
files
def
get_linter
(
filename
):
try
:
_
,
extension
=
filename
.
rsplit
(
'.'
,
1
)
...
...
@@ -45,17 +121,67 @@ def lint(filename, require_linter=False):
return
ret
==
0
def
main
(
*
args
):
ret
=
True
while
True
:
line
=
sys
.
stdin
.
readline
()
if
not
line
:
break
def
lint_all
(
files
):
success
=
False
filename
=
line
.
strip
()
ret
&=
lint
(
filename
)
while
not
success
:
success
=
True
for
filename
in
files
:
success
&=
lint
(
filename
)
if
not
success
:
retry
,
skip
=
prompt_for_retry
()
if
not
retry
:
success
=
skip
break
print
(
file
=
sys
.
stderr
)
return
success
def
prompt_for_retry
():
with
Terminal
()
as
term
:
while
True
:
print
(
'(A)bort, (I)gnore, (R)etry: '
,
end
=
''
,
file
=
sys
.
stderr
,
flush
=
True
)
ans
=
term
.
readchar
(
'r'
)
print
(
ans
,
file
=
sys
.
stderr
)
try
:
return
{
'a'
:
(
False
,
False
),
'i'
:
(
False
,
True
),
'r'
:
(
True
,
False
),
}[
ans
.
lower
()]
except
KeyError
:
pass
def
main
():
from
signal
import
signal
,
SIGINT
,
SIGTERM
class
Exit
(
Exception
):
pass
exit_signals
=
(
SIGTERM
,
SIGINT
)
def
sig_handler
(
signum
,
frame
):
if
signum
in
exit_signals
:
raise
Exit
for
signum
in
exit_signals
:
signal
(
signum
,
sig_handler
)
try
:
files
=
get_files
()
success
=
lint_all
(
files
)
except
Exit
:
success
=
False
return
1
^
success
return
1
^
ret
if
__name__
==
'__main__'
:
sys
.
exit
(
main
(
*
sys
.
argv
[
1
:]
))
sys
.
exit
(
main
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment