Skip to content

Commit

Permalink
cli: use hard tabs to align with vscode style
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Sep 23, 2022
1 parent 665eb03 commit b784bcd
Show file tree
Hide file tree
Showing 43 changed files with 6,424 additions and 6,426 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
"editor.insertSpaces": true
},
"typescript.tsc.autoDetect": "off",
"testing.autoRun.mode": "rerun",
Expand Down
67 changes: 33 additions & 34 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,56 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/


const FILE_HEADER: &str = "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/";

use std::{env, fs, io, path::PathBuf, process};

fn main() {
let files = enumerate_source_files().expect("expected to enumerate files");
ensure_file_headers(&files).expect("expected to ensure file headers");
let files = enumerate_source_files().expect("expected to enumerate files");
ensure_file_headers(&files).expect("expected to ensure file headers");
}

fn ensure_file_headers(files: &[PathBuf]) -> Result<(), io::Error> {
let mut ok = true;
let mut ok = true;

let crlf_header_str = str::replace(FILE_HEADER, "\n", "\r\n");
let crlf_header = crlf_header_str.as_bytes();
let lf_header = FILE_HEADER.as_bytes();
for file in files {
let contents = fs::read(file)?;
for file in files {
let contents = fs::read(file)?;

if !(contents.starts_with(lf_header) || contents.starts_with(crlf_header)) {
eprintln!("File missing copyright header: {}", file.display());
ok = false;
}
}
if !(contents.starts_with(lf_header) || contents.starts_with(crlf_header)) {
eprintln!("File missing copyright header: {}", file.display());
ok = false;
}
}

if !ok {
process::exit(1);
}
if !ok {
process::exit(1);
}

Ok(())
Ok(())
}

/// Gets all "rs" files in the source directory
fn enumerate_source_files() -> Result<Vec<PathBuf>, io::Error> {
let mut files = vec![];
let mut queue = vec![];

let current_dir = env::current_dir()?.join("src");
queue.push(current_dir);

while !queue.is_empty() {
for entry in fs::read_dir(queue.pop().unwrap())? {
let entry = entry?;
let ftype = entry.file_type()?;
if ftype.is_dir() {
queue.push(entry.path());
} else if ftype.is_file() && entry.file_name().to_string_lossy().ends_with(".rs") {
files.push(entry.path());
}
}
}

Ok(files)
let mut files = vec![];
let mut queue = vec![];

let current_dir = env::current_dir()?.join("src");
queue.push(current_dir);

while !queue.is_empty() {
for entry in fs::read_dir(queue.pop().unwrap())? {
let entry = entry?;
let ftype = entry.file_type()?;
if ftype.is_dir() {
queue.push(entry.path());
} else if ftype.is_file() && entry.file_name().to_string_lossy().ends_with(".rs") {
files.push(entry.path());
}
}
}

Ok(files)
}
1 change: 1 addition & 0 deletions cli/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hard_tabs = true
Loading

0 comments on commit b784bcd

Please sign in to comment.