#![warn(missing_docs)]
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
#[allow(missing_docs)]
mod options;
use std::path::Path;
pub use crate::options::{
IndentStyle, LineEnding, ResolvedShellFormatOptions, ShellDialect, ShellFormatOptions,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FormattedSource {
Unchanged,
Formatted(String),
}
impl FormattedSource {
#[must_use]
pub fn is_changed(&self) -> bool {
matches!(self, Self::Formatted(_))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FormatError {
Parse {
message: String,
line: usize,
column: usize,
},
Internal(String),
}
impl std::fmt::Display for FormatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Parse {
message,
line,
column,
} => {
if *line > 0 {
write!(f, "parse error at line {line}, column {column}: {message}")
} else {
write!(f, "parse error: {message}")
}
}
Self::Internal(message) => f.write_str(message),
}
}
}
impl std::error::Error for FormatError {}
pub type Result<T> = std::result::Result<T, FormatError>;
pub fn format_source(
_source: &str,
_path: Option<&Path>,
_options: &ShellFormatOptions,
) -> Result<FormattedSource> {
Ok(FormattedSource::Unchanged)
}
#[doc(hidden)]
pub fn source_is_formatted(
_source: &str,
_path: Option<&Path>,
_options: &ShellFormatOptions,
) -> Result<bool> {
Ok(true)
}
pub fn format_file_ast<File>(
_source: &str,
_file: File,
_path: Option<&Path>,
_options: &ShellFormatOptions,
) -> Result<FormattedSource> {
Ok(FormattedSource::Unchanged)
}
#[cfg(feature = "benchmarking")]
#[doc(hidden)]
#[must_use]
pub fn build_formatter_facts<File>(_source: &str, _file: &File) -> usize {
0
}
#[cfg(test)]
mod tests {
use std::path::Path;
use super::*;
#[test]
fn format_source_is_currently_a_noop() {
let formatted = format_source(
" echo hi\n",
Some(Path::new("script.sh")),
&ShellFormatOptions::default(),
)
.unwrap();
assert_eq!(formatted, FormattedSource::Unchanged);
assert!(
source_is_formatted(
" echo hi\n",
Some(Path::new("script.sh")),
&ShellFormatOptions::default()
)
.unwrap()
);
}
}