GeezerVison is showing github.com — Merge "Add an ability to specify max line length" · openstack/bashate@49c5f16
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bashate/bashate.py +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,8 +59,8 @@ def check_no_trailing_whitespace(line, report): | 59 | 59 | report.print_error(MESSAGES['E001'].msg, line) | 60 | 60 |
| 61 | 61 |
| 62 | | -def check_no_long_lines(line, report): | 63 | | - if len(line.rstrip("\r\n")) > 79: | | 62 | +def check_no_long_lines(line, report, max_line_length): | | 63 | + if len(line.rstrip("\r\n")) > max_line_length: | 64 | 64 | report.print_error(MESSAGES['E006'].msg, line) | 65 | 65 |
| 66 | 66 |
| @@ -306,7 +306,7 @@ def log_error(self, error, line, filename, filelineno, warn=False): | 306 | 306 | 'error': error.replace(":", "", 1), | 307 | 307 | 'line': line.rstrip('\n')}) | 308 | 308 |
| 309 | | - def check_files(self, files, verbose): | | 309 | + def check_files(self, files, verbose, max_line_length=79): | 310 | 310 | logical_line = "" | 311 | 311 | token = False | 312 | 312 |
| @@ -401,7 +401,7 @@ def check_files(self, files, verbose): | 401 | 401 | # separatley. Stick with what works... | 402 | 402 | for line in logical_line: | 403 | 403 | check_no_trailing_whitespace(line, report) | 404 | | - check_no_long_lines(line, report) | | 404 | + check_no_long_lines(line, report, max_line_length) | 405 | 405 | check_for_do(line, report) | 406 | 406 | check_if_then(line, report) | 407 | 407 | check_function_decl(line, report) | @@ -431,6 +431,8 @@ def main(args=None): | 431 | 431 | help='Rules to always warn (rather than error)') | 432 | 432 | parser.add_argument('-e', '--error', | 433 | 433 | help='Rules to always error (rather than warn)') | | 434 | + parser.add_argument('--max-line-length', default=79, type=int, | | 435 | + help='Max line length') | 434 | 436 | parser.add_argument('-v', '--verbose', action='store_true', default=False) | 435 | 437 | parser.add_argument('--version', action='store_true', | 436 | 438 | help='show bashate version number and exit', | @@ -457,7 +459,7 @@ def main(args=None): | 457 | 459 | run.register_errors(opts.error) | 458 | 460 |
| 459 | 461 | try: | 460 | | - run.check_files(files, opts.verbose) | | 462 | + run.check_files(files, opts.verbose, opts.max_line_length) | 461 | 463 | except IOError as e: | 462 | 464 | print("bashate: %s" % e) | 463 | 465 | return 1 | |
Collapse file Copy file name to clipboardExpand all lines: bashate/messages.py +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,11 +93,11 @@ def msg(self): | 93 | 93 | 'long_msg': | 94 | 94 | """ | 95 | 95 | This check mimics the widely accepted convention from PEP8 and | 96 | | - many other places that lines longer than 79 columns can not | 97 | | - only cause problems when reading/writing code, but also often | 98 | | - indicates a bad smell, e.g. too many levels of indentation due | 99 | | - to overly complex functions which require refactoring into | 100 | | - smaller chunks. | | 96 | + many other places that lines longer than a standard terminal width | | 97 | + (default=79 columns) can not only cause problems when reading/writing | | 98 | + code, but also often indicates a bad smell, e.g. too many levels | | 99 | + of indentation due to overly complex functions which require | | 100 | + refactoring into smaller chunks. | 101 | 101 | """, | 102 | 102 | 'default': 'W' | 103 | 103 | }, | |
Collapse file Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#!/bin/bash | | 2 | + | | 3 | +# lines longer than 10 columns give warnings | | 4 | + | | 5 | +: 0123456789 | | 6 | +: 1 2 3 4 5 6 7 8 | | 7 | + | | 8 | +: 012345 |
Collapse file Copy file name to clipboardExpand all lines: bashate/tests/test_bashate.py +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,8 +64,11 @@ def test_main_return_one_on_ioerror(self, m_bashaterun): | 64 | 64 |
| 65 | 65 | result = bashate.main(['--verbose', | 66 | 66 | '/path/to/fileA', '/path/to/fileB']) | 67 | | - m_run_obj.check_files.assert_called_with(['/path/to/fileA', | 68 | | - '/path/to/fileB'], True) | | 67 | + m_run_obj.check_files.assert_called_with( | | 68 | + ['/path/to/fileA', '/path/to/fileB'], | | 69 | + True, | | 70 | + 79 | | 71 | + ) | 69 | 72 | expected_return = 1 | 70 | 73 | self.assertEqual(expected_return, result) | 71 | 74 |
| @@ -176,6 +179,14 @@ def test_sample_E006_bad_ignore_trailing_ws(self): | 176 | 179 | self.assert_error_found('E006', 6) | 177 | 180 | self.assert_error_found('E006', 8) | 178 | 181 |
| | 182 | + def test_sample_E006_bad_custom_max_line_length(self): | | 183 | + test_files = ['bashate/tests/samples/E006_bad_custom_length.sh'] | | 184 | + self.run.check_files(test_files, False, 10) | | 185 | + | | 186 | + self.assertEqual(self.run.warning_count, 2) | | 187 | + self.assert_error_found('E006', 5) | | 188 | + self.assert_error_found('E006', 6) | | 189 | + | 179 | 190 | def test_sample_E006_good(self): | 180 | 191 | test_files = ['bashate/tests/samples/E006_good.sh'] | 181 | 192 | self.run.check_files(test_files, False) | |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +features: | | 3 | + - | | | 4 | + Adds an option ``--max-line-length`` to specify the maximum length | | 5 | + of lines for check E006. |
|