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

Enforce rustfmt on CI #22126

Merged
merged 6 commits into from Nov 7, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Remove import order check from test-tidy

Fix leaking file descriptor.
  • Loading branch information
pyfisch committed Nov 6, 2018
commit 4a947dd7195c3ece1e4996a6bdf7c300bf6ec655
@@ -305,10 +305,11 @@ def test_content(self):
return 0

def install_rustfmt(self):
if self.call_rustup_run(["cargo", "fmt", "--version", "-q"],
stderr=open(os.devnull, "w")) != 0:
# Rustfmt is not installed. Install:
self.call_rustup_run(["rustup", "component", "add", "rustfmt-preview"])
with open(os.devnull, "w") as devnull:
if self.call_rustup_run(["cargo", "fmt", "--version", "-q"],
stderr=devnull) != 0:
# Rustfmt is not installed. Install:
self.call_rustup_run(["rustup", "component", "add", "rustfmt-preview"])

@Command('test-tidy',
description='Run the source code tidiness check',
@@ -509,10 +509,8 @@ def check_rust(file_name, lines):

is_lib_rs_file = file_name.endswith("lib.rs")

prev_use = None
prev_open_brace = False
multi_line_string = False
current_indent = 0
prev_crate = {}
prev_mod = {}
prev_feature_name = ""
@@ -716,36 +714,6 @@ def check_rust(file_name, lines):
# not a feature attribute line, so empty previous name
prev_feature_name = ""

# imports must be in the same line, alphabetically sorted, and merged
# into a single import block
if line.startswith("use "):
import_block = True
if not line.endswith(";") and '{' in line:
yield (idx + 1, "use statement spans multiple lines")
if '{ ' in line:
yield (idx + 1, "extra space after {")
if ' }' in line:
yield (idx + 1, "extra space before }")
# strip "use" from the begin and ";" from the end
current_use = line[4:-1]
if prev_use:
current_use_cut = current_use.replace("{self,", ".").replace("{", ".")
prev_use_cut = prev_use.replace("{self,", ".").replace("{", ".")
if indent == current_indent and current_use_cut < prev_use_cut and check_alphabetical_order:
yield(idx + 1, decl_message.format("use statement")
+ decl_expected.format(prev_use)
+ decl_found.format(current_use))
prev_use = current_use
current_indent = indent

if whitespace or not import_block:
current_indent = 0

# do not allow blank lines in an import block
if import_block and whitespace and line.startswith("use "):
whitespace = False
yield(idx, "encountered whitespace following a use statement")

# modules must be in the same line and alphabetically sorted
if line.startswith("mod ") or line.startswith("pub mod "):
# strip /(pub )?mod/ from the left and ";" from the right
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.