From 30bf7e43db2667470875ea4477a95aa297896851 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 12 Nov 2019 15:41:02 +0300 Subject: [PATCH] Disallow regressing crate docs --- crates/ra_cfg/src/lib.rs | 5 ++-- crates/ra_fmt/src/lib.rs | 5 ++-- xtask/tests/tidy-tests/docs.rs | 49 +++++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/crates/ra_cfg/src/lib.rs b/crates/ra_cfg/src/lib.rs index 1bee3eb995..51d953f6e8 100644 --- a/crates/ra_cfg/src/lib.rs +++ b/crates/ra_cfg/src/lib.rs @@ -1,11 +1,12 @@ //! ra_cfg defines conditional compiling options, `cfg` attibute parser and evaluator + +mod cfg_expr; + use std::iter::IntoIterator; use ra_syntax::SmolStr; use rustc_hash::FxHashSet; -mod cfg_expr; - pub use cfg_expr::{parse_cfg, CfgExpr}; /// Configuration options used for conditional compilition on items with `cfg` attributes. diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs index e22ac9753f..a30ed4cbb8 100644 --- a/crates/ra_fmt/src/lib.rs +++ b/crates/ra_fmt/src/lib.rs @@ -1,5 +1,7 @@ //! This crate provides some utilities for indenting rust code. -//! + +use std::iter::successors; + use itertools::Itertools; use ra_syntax::{ ast::{self, AstNode, AstToken}, @@ -7,7 +9,6 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNode, SyntaxToken, T, }; -use std::iter::successors; pub fn reindent(text: &str, indent: &str) -> String { let indent = format!("\n{}", indent); diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index 227937f462..1412198601 100644 --- a/xtask/tests/tidy-tests/docs.rs +++ b/xtask/tests/tidy-tests/docs.rs @@ -1,10 +1,6 @@ -use std::fs; -use std::io::prelude::*; -use std::io::BufReader; -use std::path::Path; +use std::{collections::HashMap, fs, io::prelude::*, io::BufReader, path::Path}; use walkdir::{DirEntry, WalkDir}; - use xtask::project_root; fn is_exclude_dir(p: &Path) -> bool { @@ -37,6 +33,7 @@ fn no_docs_comments() { let crates = project_root().join("crates"); let iter = WalkDir::new(crates); let mut missing_docs = Vec::new(); + let mut contains_fixme = Vec::new(); for f in iter.into_iter().filter_entry(|e| !is_hidden(e)) { let f = f.unwrap(); if f.file_type().is_dir() { @@ -54,7 +51,12 @@ fn no_docs_comments() { let mut reader = BufReader::new(fs::File::open(f.path()).unwrap()); let mut line = String::new(); reader.read_line(&mut line).unwrap(); - if !line.starts_with("//!") { + + if line.starts_with("//!") { + if line.contains("FIXME") { + contains_fixme.push(f.path().to_path_buf()) + } + } else { missing_docs.push(f.path().display().to_string()); } } @@ -65,4 +67,39 @@ fn no_docs_comments() { missing_docs.join("\n") ) } + + let whitelist = [ + "ra_batch", + "ra_cli", + "ra_db", + "ra_hir", + "ra_hir_expand", + "ra_hir_def", + "ra_ide_api", + "ra_lsp_server", + "ra_mbe", + "ra_parser", + "ra_prof", + "ra_project_model", + "ra_syntax", + "ra_text_edit", + "ra_tt", + ]; + + let mut has_fixmes = whitelist.iter().map(|it| (*it, false)).collect::>(); + 'outer: for path in contains_fixme { + for krate in whitelist.iter() { + if path.components().any(|it| it.as_os_str() == *krate) { + has_fixmes.insert(krate, true); + continue 'outer; + } + } + panic!("FIXME doc in a fully-documented crate: {}", path.display()) + } + + for (krate, has_fixme) in has_fixmes.iter() { + if !has_fixme { + panic!("crate {} is fully documented, remove it from the white list", krate) + } + } }