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

Stop messing around with line endings, just use LF πŸ‘¨β€βš–οΈ #89

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
4 changes: 2 additions & 2 deletions crates/ditto-checker/src/result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub type Result<T> = std::result::Result<T, TypeError>;

#[cfg(test)]
mod tests {
#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/warnings/(.*).ditto",
output = "golden-tests/warnings/${1}.warnings"
)]
Expand Down Expand Up @@ -40,7 +40,7 @@ mod tests {
.join("\n")
}

#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/type-errors/(.*).ditto",
output = "golden-tests/type-errors/${1}.error"
)]
Expand Down
2 changes: 1 addition & 1 deletion crates/ditto-codegen-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod tests {
use ditto_checker as checker;
use ditto_cst as cst;

#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/javascript/(.*).ditto",
output = "golden-tests/javascript/${1}.js"
)]
Expand Down
12 changes: 3 additions & 9 deletions crates/ditto-codegen-js/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ pub fn render_module(module: Module) -> String {
accum
}

#[cfg(windows)]
static NEWLINE: &str = "\r\n";

#[cfg(not(windows))]
static NEWLINE: &str = "\n";

pub(crate) trait Render {
// REVIEW I doubt pushing to a String like this is the most efficient solution?
fn render(&self, accum: &mut String);
Expand All @@ -23,11 +17,11 @@ impl Render for Module {
fn render(&self, accum: &mut String) {
self.imports.iter().for_each(|import| {
import.render(accum);
accum.push_str(NEWLINE);
accum.push('\n');
});
self.statements.iter().for_each(|stmt| {
stmt.render(accum);
accum.push_str(NEWLINE);
accum.push('\n');
});

accum.push_str("export {");
Expand All @@ -40,7 +34,7 @@ impl Render for Module {
.join(","),
);
accum.push_str("};");
accum.push_str(NEWLINE);
accum.push('\n');
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ditto-config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod errors {
}
}

#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/parse-errors/(.*).toml",
output = "golden-tests/parse-errors/${1}.error"
)]
Expand Down
2 changes: 1 addition & 1 deletion crates/ditto-cst/src/parser/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod r#type;

use crate::{parse_header_and_imports, Module};

#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/parse-errors/(.*).ditto",
output = "golden-tests/parse-errors/${1}.error"
)]
Expand Down
6 changes: 0 additions & 6 deletions crates/ditto-fmt/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
pub static INDENT_WIDTH: u8 = 4;
pub static MAX_WIDTH: u32 = 80;

#[cfg(windows)]
pub static NEWLINE: &str = "\r\n";

#[cfg(not(windows))]
pub static NEWLINE: &str = "\n";
4 changes: 2 additions & 2 deletions crates/ditto-fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod syntax;
mod token;
mod r#type;

use config::{INDENT_WIDTH, MAX_WIDTH, NEWLINE};
use config::{INDENT_WIDTH, MAX_WIDTH};

/// Pretty-print a CST module.
pub fn format_module(module: ditto_cst::Module) -> String {
Expand All @@ -26,7 +26,7 @@ pub fn format_module(module: ditto_cst::Module) -> String {
indent_width: INDENT_WIDTH,
max_width: MAX_WIDTH,
use_tabs: false, // nah
new_line_text: NEWLINE,
new_line_text: "\n",
},
)
}
Expand Down
26 changes: 10 additions & 16 deletions crates/ditto-make/src/build_ninja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,14 @@ impl BuildNinja {
variables.sort();
for (key, value) in variables {
string.push_str(&format!("{} = {}", key, value));
string.push_str(NEWLINE);
string.push_str(NEWLINE);
string.push('\n');
string.push('\n');
}
} else {
for (key, value) in self.variables.into_iter() {
string.push_str(&format!("{} = {}", key, value));
string.push_str(NEWLINE);
string.push_str(NEWLINE);
string.push('\n');
string.push('\n');
}
};

Expand All @@ -446,8 +446,8 @@ impl BuildNinja {
}
for rule in rules {
string.push_str(&rule.into_syntax());
string.push_str(NEWLINE);
string.push_str(NEWLINE);
string.push('\n');
string.push('\n');
}

let mut builds = self
Expand All @@ -461,8 +461,8 @@ impl BuildNinja {
}
for build in builds {
string.push_str(&build);
string.push_str(NEWLINE);
string.push_str(NEWLINE);
string.push('\n');
string.push('\n');
}
string
}
Expand Down Expand Up @@ -511,7 +511,7 @@ impl Rule {

fn into_syntax(self) -> String {
let Self { name, command } = self;
format!("rule {name}{NEWLINE} command = {command}")
format!("rule {name}\n command = {command}")
}
}

Expand Down Expand Up @@ -619,7 +619,7 @@ impl Build {
let mut variables = self
.variables
.into_iter()
.map(|(key, value)| format!("{NEWLINE} {key} = {value}"))
.map(|(key, value)| format!("\n {key} = {value}"))
.collect::<Vec<_>>();

if cfg!(debug_assertions) {
Expand All @@ -631,12 +631,6 @@ impl Build {
}
}

#[cfg(windows)]
static NEWLINE: &str = "\r\n";

#[cfg(not(windows))]
static NEWLINE: &str = "\n";

fn read_module_header_and_imports(path: &Path) -> Result<(cst::Header, Vec<cst::ImportLine>)> {
let contents = std::fs::read_to_string(path).into_diagnostic()?;
cst::parse_header_and_imports(&contents)
Expand Down
2 changes: 1 addition & 1 deletion crates/snapshot-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Cheapskate data-driven testing for the `ditto-*` crates.
It's not _generally_ useful, yet...

```rust
#[snapshot_test::snapshot_lf(
#[snapshot_test::snapshot(
input = "golden-tests/(.*).in",
output = "golden-tests/${1}.out"
)]
Expand Down
1 change: 1 addition & 0 deletions crates/snapshot-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl TestCase {
}

#[proc_macro_attribute]
#[deprecated]
pub fn snapshot_lf(attrs: TokenStream, func: TokenStream) -> TokenStream {
snapshot_impl(attrs, func, true)
}
Expand Down