Skip to content

Commit 57b3464

Browse files
committed
Implement review suggestions
1 parent 571237a commit 57b3464

File tree

7 files changed

+7
-31
lines changed

7 files changed

+7
-31
lines changed

cli/tests/integration/inputs/mixed_formats.ncl

Lines changed: 0 additions & 7 deletions
This file was deleted.

cli/tests/snapshot/snapshots/snapshot__export_stdout_mixed_formats.ncl.snap

Lines changed: 0 additions & 14 deletions
This file was deleted.

core/src/bytecode/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ impl<'a> Pretty<'a, Allocator> for &Node<'_> {
996996
"import",
997997
allocator.space(),
998998
allocator.as_string(path.to_string_lossy()).double_quotes(),
999-
if Some(*format) != InputFormat::from_path(std::path::Path::new(path)) {
999+
if Some(*format) != InputFormat::from_path(path) {
10001000
docs![
10011001
allocator,
10021002
allocator.space(),

core/src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub enum InputFormat {
6868

6969
impl InputFormat {
7070
/// Returns an [InputFormat] based on the file extension of a path.
71-
pub fn from_path(path: &Path) -> Option<InputFormat> {
72-
match path.extension().and_then(OsStr::to_str) {
71+
pub fn from_path(path: impl AsRef<Path>) -> Option<InputFormat> {
72+
match path.as_ref().extension().and_then(OsStr::to_str) {
7373
Some("ncl") => Some(InputFormat::Nickel),
7474
Some("json") => Some(InputFormat::Json),
7575
Some("yaml") | Some("yml") => Some(InputFormat::Yaml),

core/src/parser/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ pub fn mk_import_based_on_filename(
395395
_span: RawSpan,
396396
) -> Result<Node<'_>, ParseError> {
397397
let path = OsString::from(path);
398-
let format: Option<InputFormat> =
399-
InputFormat::from_path(std::path::Path::new(path.as_os_str()));
398+
let format: Option<InputFormat> = InputFormat::from_path(&path);
400399

401400
// Fall back to InputFormat::Nickel in case of unknown filename extension for backwards compatiblilty.
402401
let format = format.unwrap_or_default();

core/src/pretty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,7 @@ impl<'a> Pretty<'a, Allocator> for &Term {
11581158
"import",
11591159
allocator.space(),
11601160
allocator.as_string(path.to_string_lossy()).double_quotes(),
1161-
if Some(*format)
1162-
!= InputFormat::from_path(std::path::Path::new(path.as_os_str()))
1163-
{
1161+
if Some(*format) != InputFormat::from_path(path) {
11641162
docs![
11651163
allocator,
11661164
allocator.space(),

core/src/program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<EC: EvalCache> Program<EC> {
286286
let main_id = match input {
287287
Input::Path(path) => {
288288
let path = path.into();
289-
let format = InputFormat::from_path(Path::new(&path)).unwrap_or_default();
289+
let format = InputFormat::from_path(&path).unwrap_or_default();
290290
cache.sources.add_file(path, format)?
291291
}
292292
Input::Source(source, name) => {
@@ -332,7 +332,7 @@ impl<EC: EvalCache> Program<EC> {
332332
.map(|input| match input {
333333
Input::Path(path) => {
334334
let path = path.into();
335-
let format = InputFormat::from_path(Path::new(&path)).unwrap_or_default();
335+
let format = InputFormat::from_path(&path).unwrap_or_default();
336336

337337
RichTerm::from(Term::Import(Import::Path { path, format }))
338338
}

0 commit comments

Comments
 (0)