Rollup merge of #146171 - scrabsha:push-wovnxxwltsun, r=WaffleLapkin
tidy: check that error messages don't start with a capitalized letter
This commit is contained in:
commit
141cb38f15
7 changed files with 70 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ codegen_ssa_cpu_required = target requires explicitly specifying a cpu with `-C
|
|||
codegen_ssa_create_temp_dir = couldn't create a temp dir: {$error}
|
||||
|
||||
codegen_ssa_dlltool_fail_import_library =
|
||||
Dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
|
||||
dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
|
||||
{$stdout}
|
||||
{$stderr}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ passes_const_stable_not_stable =
|
|||
.label = attribute specified here
|
||||
|
||||
passes_custom_mir_incompatible_dialect_and_phase =
|
||||
The {$dialect} dialect is not compatible with the {$phase} phase
|
||||
the {$dialect} dialect is not compatible with the {$phase} phase
|
||||
.dialect_span = this dialect...
|
||||
.phase_span = ... is not compatible with this phase
|
||||
|
||||
|
|
|
|||
64
src/tools/tidy/src/fluent_lowercase.rs
Normal file
64
src/tools/tidy/src/fluent_lowercase.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
//! Checks that the error messages start with a lowercased letter (except when allowed to).
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use fluent_syntax::ast::{Entry, Message, PatternElement};
|
||||
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
#[rustfmt::skip]
|
||||
const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[
|
||||
// tidy-alphabetical-start
|
||||
"ABI",
|
||||
"ABIs",
|
||||
"ADT",
|
||||
"C",
|
||||
"CGU",
|
||||
"Ferris",
|
||||
"MIR",
|
||||
"OK",
|
||||
"Rust",
|
||||
"VS", // VS Code
|
||||
// tidy-alphabetical-end
|
||||
];
|
||||
|
||||
fn filter_fluent(path: &Path) -> bool {
|
||||
if let Some(ext) = path.extension() { ext.to_str() != Some("ftl") } else { true }
|
||||
}
|
||||
|
||||
fn is_allowed_capitalized_word(msg: &str) -> bool {
|
||||
ALLOWED_CAPITALIZED_WORDS.iter().any(|word| {
|
||||
msg.strip_prefix(word)
|
||||
.map(|tail| tail.chars().next().map(|c| c == '-' || c.is_whitespace()).unwrap_or(true))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
|
||||
fn check_lowercase(filename: &str, contents: &str, bad: &mut bool) {
|
||||
let (Ok(parse) | Err((parse, _))) = fluent_syntax::parser::parse(contents);
|
||||
|
||||
for entry in &parse.body {
|
||||
if let Entry::Message(msg) = entry
|
||||
&& let Message { value: Some(pattern), .. } = msg
|
||||
&& let [first_pattern, ..] = &pattern.elements[..]
|
||||
&& let PatternElement::TextElement { value } = first_pattern
|
||||
&& value.chars().next().is_some_and(char::is_uppercase)
|
||||
&& !is_allowed_capitalized_word(value)
|
||||
{
|
||||
tidy_error!(
|
||||
bad,
|
||||
"{filename}: message `{value}` starts with an uppercase letter. Fix it or add it to `ALLOWED_CAPITALIZED_WORDS`"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, bad: &mut bool) {
|
||||
walk(
|
||||
path,
|
||||
|path, is_dir| filter_dirs(path) || (!is_dir && filter_fluent(path)),
|
||||
&mut |ent, contents| {
|
||||
check_lowercase(ent.path().to_str().unwrap(), contents, bad);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -257,6 +257,7 @@ pub mod extra_checks;
|
|||
pub mod features;
|
||||
pub mod filenames;
|
||||
pub mod fluent_alphabetical;
|
||||
pub mod fluent_lowercase;
|
||||
pub mod fluent_period;
|
||||
mod fluent_used;
|
||||
pub mod gcc_submodule;
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ fn main() {
|
|||
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose, &ci_info);
|
||||
check!(fluent_alphabetical, &compiler_path, bless);
|
||||
check!(fluent_period, &compiler_path);
|
||||
check!(fluent_lowercase, &compiler_path);
|
||||
check!(target_policy, &root_path);
|
||||
check!(gcc_submodule, &root_path, &compiler_path);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@ pub fn lib_main() {
|
|||
unsafe { f(42); }
|
||||
}
|
||||
|
||||
//~? ERROR Dlltool could not create import library with
|
||||
//~? ERROR dlltool could not create import library with
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
|
||||
error: dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
|
||||
|
||||
$DLLTOOL: Syntax error in def file $DEF_FILE:1␍
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue