Unverified Commit 582ae855 authored by Zelda Hessler's avatar Zelda Hessler Committed by GitHub
Browse files

update: aws-config README (#2221)

* update: aws-config README
* update: README linter to allow aws-config readme changes
parent 4fbfc073
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -68,5 +68,5 @@ This project is licensed under the Apache-2.0 License.
[Usage examples]: https://github.com/awslabs/aws-sdk-rust/tree/main/examples

<!-- anchor_start:footer -->
This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator. In most cases, it should not be used directly.
This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator.
<!-- anchor_end:footer -->
+26 −5
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ use anyhow::{Context, Result};
use std::fs;
use std::path::{Path, PathBuf};

const CRATES_TO_BE_USED_DIRECTLY: &[&str] = ["aws-config"].as_slice();

pub(crate) struct ReadmesExist;
impl Lint for ReadmesExist {
    fn name(&self) -> &str {
@@ -43,7 +45,17 @@ impl Lint for ReadmesHaveFooters {

impl Fix for ReadmesHaveFooters {
    fn fix(&self, path: impl AsRef<Path>) -> Result<(Vec<LintError>, String)> {
        let (updated, new_contents) = fix_readme(path)?;
        let is_crate_to_be_used_directly = path
            .as_ref()
            .parent()
            .map(|parent_folder| {
                CRATES_TO_BE_USED_DIRECTLY
                    .iter()
                    .any(|crate_name| parent_folder.ends_with(crate_name))
            })
            .unwrap_or_default();

        let (updated, new_contents) = fix_readme(path, is_crate_to_be_used_directly)?;
        let errs = match updated {
            true => vec![LintError::new("README was missing required footer")],
            false => vec![],
@@ -52,12 +64,21 @@ impl Fix for ReadmesHaveFooters {
    }
}

const README_FOOTER: &str = "\nThis crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) \
and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator. In most cases, it should not be used directly.\n";
const README_FOOTER: &str =
    "\nThis crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) \
and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator.";
const NOT_TO_BE_USED_DIRECTLY: &str = " In most cases, it should not be used directly.";

fn fix_readme(path: impl AsRef<Path>, to_be_used_directly: bool) -> Result<(bool, String)> {
    let mut footer_contents = README_FOOTER.to_string();
    if !to_be_used_directly {
        footer_contents.push_str(NOT_TO_BE_USED_DIRECTLY);
    }
    footer_contents.push('\n');

fn fix_readme(path: impl AsRef<Path>) -> Result<(bool, String)> {
    let mut contents = fs::read_to_string(path.as_ref())
        .with_context(|| format!("failure to read readme: {:?}", path.as_ref()))?;
    let updated = anchor::replace_anchor(&mut contents, &anchor::anchors("footer"), README_FOOTER)?;
    let updated =
        anchor::replace_anchor(&mut contents, &anchor::anchors("footer"), &footer_contents)?;
    Ok((updated, contents))
}