@@ -18,28 +18,52 @@ pub mod unist;
1818pub use changelog::Changelog;
1919pub use diagnostic::Diagnostic;
2020pub use error::{Error, ParseError};
21+ pub use profile::Profile;
2122pub use rule::Rule;
2223
2324/// Parse a changelog from a string.
2425///
2526/// Parsing a changelog will always succeed. This function returns a [`Result`] to support future
2627/// fatal errors (e.g. if the document is not a changelog at all).
27- pub fn parse_str(s: &str) -> Result<(Changelog, Vec<Diagnostic>), ParseError> {
28- parse(s, None)
28+ pub fn parse_str(s: &str) -> Result<Changelog, ParseError> {
29+ Ok(parser::parse(&s).into())
30+ }
31+
32+ /// Parse and lint a changelog from a string.
33+ pub fn parse_and_lint_str(
34+ s: &str,
35+ profile: &Profile,
36+ ) -> Result<(Changelog, Vec<Diagnostic>), ParseError> {
37+ parse_and_lint(s, None, profile)
2938}
3039
3140/// Parse a changelog from a file.
3241///
3342/// As with [`parse_str()`], parsing the changelog document will nearly always succeed.
3443/// `parse_file()` may additionally return a [`std::io::Error`] ([`Error::Io`]).
35- pub fn parse_file(path: &Path) -> Result<(Changelog, Vec<Diagnostic>), Error> {
44+ pub fn parse_file(path: &Path) -> Result<Changelog, Error> {
45+ let s = std::fs::read_to_string(path)?;
46+ Ok(parser::parse(&s).into())
47+ }
48+
49+ /// Parse and lint a changelog from a file.
50+ ///
51+ /// As with [`parse_str()`], parsing the changelog document will nearly always succeed.
52+ /// `parse_file()` may additionally return a [`std::io::Error`] ([`Error::Io`]).
53+ pub fn parse_and_lint_file(
54+ path: &Path,
55+ profile: &Profile,
56+ ) -> Result<(Changelog, Vec<Diagnostic>), Error> {
3657 let s = std::fs::read_to_string(path)?;
37- Ok(parse (&s, Some(path))?)
58+ Ok(parse_and_lint (&s, Some(path), profile )?)
3859}
3960
40- fn parse(s: &str, path: Option<&Path>) -> Result<(Changelog, Vec<Diagnostic>), ParseError> {
61+ fn parse_and_lint(
62+ s: &str,
63+ path: Option<&Path>,
64+ profile: &Profile,
65+ ) -> Result<(Changelog, Vec<Diagnostic>), ParseError> {
4166 let changelog = parser::parse(s);
42- let profile = profile::Profile::default();
4367 let mut diagnostics = linter::lint(&changelog, &profile);
4468 diagnostics.sort_by_key(|d| d.span);
4569 for diagnostic in &mut diagnostics {
0 commit comments