GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge "Add an ability to specify max line length" · openstack/bashate@49c5f16

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bashate
    • bashate.py
    • messages.py
    • tests
      • samples
        • E006_bad_custom_length.sh
      • test_bashate.py
  • releasenotes/notes
    • custom-line-length-083e8077951a8ead.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bashate/bashate.py‎

Copy file name to clipboardExpand all lines: bashate/bashate.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def check_no_trailing_whitespace(line, report):
5959
report.print_error(MESSAGES['E001'].msg, line)
6060

6161

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:
6464
report.print_error(MESSAGES['E006'].msg, line)
6565

6666

@@ -306,7 +306,7 @@ def log_error(self, error, line, filename, filelineno, warn=False):
306306
'error': error.replace(":", "", 1),
307307
'line': line.rstrip('\n')})
308308

309-
def check_files(self, files, verbose):
309+
def check_files(self, files, verbose, max_line_length=79):
310310
logical_line = ""
311311
token = False
312312

@@ -401,7 +401,7 @@ def check_files(self, files, verbose):
401401
# separatley. Stick with what works...
402402
for line in logical_line:
403403
check_no_trailing_whitespace(line, report)
404-
check_no_long_lines(line, report)
404+
check_no_long_lines(line, report, max_line_length)
405405
check_for_do(line, report)
406406
check_if_then(line, report)
407407
check_function_decl(line, report)
@@ -431,6 +431,8 @@ def main(args=None):
431431
help='Rules to always warn (rather than error)')
432432
parser.add_argument('-e', '--error',
433433
help='Rules to always error (rather than warn)')
434+
parser.add_argument('--max-line-length', default=79, type=int,
435+
help='Max line length')
434436
parser.add_argument('-v', '--verbose', action='store_true', default=False)
435437
parser.add_argument('--version', action='store_true',
436438
help='show bashate version number and exit',
@@ -457,7 +459,7 @@ def main(args=None):
457459
run.register_errors(opts.error)
458460

459461
try:
460-
run.check_files(files, opts.verbose)
462+
run.check_files(files, opts.verbose, opts.max_line_length)
461463
except IOError as e:
462464
print("bashate: %s" % e)
463465
return 1
Collapse file

‎bashate/messages.py‎

Copy file name to clipboardExpand all lines: bashate/messages.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ def msg(self):
9393
'long_msg':
9494
"""
9595
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.
101101
""",
102102
'default': 'W'
103103
},
Collapse file

‎bashate/tests/samples/E006_bad_custom_length.sh‎

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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

‎bashate/tests/test_bashate.py‎

Copy file name to clipboardExpand all lines: bashate/tests/test_bashate.py
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def test_main_return_one_on_ioerror(self, m_bashaterun):
6464

6565
result = bashate.main(['--verbose',
6666
'/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+
)
6972
expected_return = 1
7073
self.assertEqual(expected_return, result)
7174

@@ -176,6 +179,14 @@ def test_sample_E006_bad_ignore_trailing_ws(self):
176179
self.assert_error_found('E006', 6)
177180
self.assert_error_found('E006', 8)
178181

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+
179190
def test_sample_E006_good(self):
180191
test_files = ['bashate/tests/samples/E006_good.sh']
181192
self.run.check_files(test_files, False)
Collapse file

‎releasenotes/notes/custom-line-length-083e8077951a8ead.yaml‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Adds an option ``--max-line-length`` to specify the maximum length
5+
of lines for check E006.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.