diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-04-15 19:40:52 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-04-15 19:40:52 +0100 |
commit | cbfab73361f859b3dcad2512c528f9820c13a0c6 (patch) | |
tree | c7332a52452887451b16a194b2a42faf296f5856 /nitpicker | |
parent | 1aea623572f2a88775ebf2a5f6e6c945472438dc (diff) | |
download | obnam-cbfab73361f859b3dcad2512c528f9820c13a0c6.tar.gz |
Move nitpicking code to separate tool
Diffstat (limited to 'nitpicker')
-rwxr-xr-x | nitpicker | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/nitpicker b/nitpicker new file mode 100755 index 00000000..7f3664b1 --- /dev/null +++ b/nitpicker @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# Copyright 2014 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# =*= License: GPL-3+ =*= + + +import sys + +import cliapp + +import obnamlib + + +class TabCharacter(obnamlib.ObnamError): + + msg = 'TAB character found: {line}' + + +class LongLine(obnamlib.ObnamError): + + msg = 'long line ({length} chars after TAB expansion): {line}' + + +class SourceCodeNitpicker(cliapp.Application): + + def setup(self): + self.errors = False + + def cleanup(self): + if self.errors: + sys.exit(1) + + def process_input_line(self, filename, line): + line = line.rstrip('\n') + + if '\t' in line: + self.error(filename, self.lineno, TabCharacter(line=line)) + + expanded = line.expandtabs() + if len(expanded) > 79: + self.error( + filename, self.lineno, + LongLine(line=line, length=len(expanded))) + + def error(self, filename, lineno, error): + self.output.write( + '%s:%s: %s\n' % (filename, lineno, str(error))) + self.errors = True + + +SourceCodeNitpicker().run() |