Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report blank lines that follow an open brace #11472

Merged
merged 2 commits into from May 28, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Warn about empty lines following an open brace.

  • Loading branch information
jdm committed May 27, 2016
commit 4ebc065cba15184c8f63a28f128ec833fffccef7
@@ -299,6 +299,7 @@ def check_rust(file_name, lines):
whitespace = False

prev_use = None
prev_open_brace = False
current_indent = 0
prev_crate = {}
prev_mod = {}
@@ -342,10 +343,10 @@ def check_rust(file_name, lines):
line = re.sub(r"'(\\.|[^\\'])*?'", "''", line)

# get rid of comments
line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '', line)
line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '//', line)

# get rid of attributes that do not contain =
line = re.sub('^#[A-Za-z0-9\(\)\[\]_]*?$', '', line)
line = re.sub('^#[A-Za-z0-9\(\)\[\]_]*?$', '#[]', line)

# flag this line if it matches one of the following regular expressions
# tuple format: (pattern, format_message, filter_function(match, line))
@@ -401,6 +402,10 @@ def check_rust(file_name, lines):

yield (idx + 1, message.format(*match.groups(), **match.groupdict()))

if prev_open_brace and not line:
yield (idx + 1, "found an empty line following a {")
prev_open_brace = line.endswith("{")

# check alphabetical order of extern crates
if line.startswith("extern crate "):
# strip "extern crate " from the begin and ";" from the end
@@ -58,6 +58,7 @@ def test_rust(self):
self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2])
self.assertEqual('mod declaration spans multiple lines', errors.next()[2])
self.assertTrue('extern crate declaration is not in alphabetical order' in errors.next()[2])
self.assertEqual('found an empty line following a {', errors.next()[2])
self.assertEqual('missing space before ->', errors.next()[2])
self.assertEqual('missing space after ->', errors.next()[2])
self.assertEqual('missing space after :', errors.next()[2])
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.