-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add no-mistakes-config rule for path, glob, and limit lints #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
75160b3
feat: add no-mistakes-config rule for path, glob, and limit lints
jonathanong 685a45a
style: rustfmt filesystem_dispatch imports
jonathanong 5d45c15
refactor: split no-mistakes-config path collection under 200 lines
jonathanong 0a7b549
fix: export frameworks for sibling no-mistakes-config lints
jonathanong 78f569d
fix: avoid clippy cloned_ref_to_slice_refs in glob lint
jonathanong 6427f8d
fix: run no-mistakes-config from check and honor implicit Direct
jonathanong 3036d04
style: rustfmt env-limit helper
jonathanong 6229b90
fix: cover config-lint branches and treat . as the repo root
jonathanong 05c6e3d
fix: skip env-limit Direct warning when all tests are selected
jonathanong 686afe9
test: cover invalid glob errors and missing file/path kind labels
jonathanong cd08743
merge: origin/main into no-mistakes-config lint
jonathanong 5cfdcc4
merge: origin/main after #764
jonathanong 3078e59
feat: add workflow-topology-policy rule and step-order helpers (#763)
jonathanong 1bec3ad
merge: origin/main after #765 and #767
jonathanong a184b0b
merge: origin/main after #759, #760, and #762
jonathanong 3803086
merge: origin/main after #768
jonathanong c790307
fix: restore query-annotation and production-deps rule IDs after merge
jonathanong 0a057a4
test: cover topology-policy graph, inventory, and step-order branches
jonathanong 71a07c9
merge: origin/main after #769
jonathanong fb437ff
merge origin/main into feat/no-mistakes-config-lint
jonathanong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
crates/no-mistakes/src/codebase/rules/no_mistakes_config.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| use super::RuleFinding; | ||
| use crate::codebase::ts_source::relative_slash_path; | ||
| use crate::config::v2::NoMistakesConfig; | ||
| use anyhow::Result; | ||
| use std::collections::BTreeSet; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| mod globs; | ||
| mod limits; | ||
| mod paths; | ||
|
|
||
| pub const RULE_ID: &str = "no-mistakes-config"; | ||
|
|
||
| pub(crate) fn check_with_files( | ||
| root: &Path, | ||
| config: &NoMistakesConfig, | ||
| all_files: &[PathBuf], | ||
| ) -> Result<Vec<RuleFinding>> { | ||
| let sources = super::source_store_for_files(all_files); | ||
| check_with_files_and_sources(root, config, all_files, &sources) | ||
| } | ||
|
|
||
| pub(crate) fn check_with_files_and_sources( | ||
| root: &Path, | ||
| config: &NoMistakesConfig, | ||
| all_files: &[PathBuf], | ||
| _sources: &crate::codebase::ts_source::SourceStore, | ||
| ) -> Result<Vec<RuleFinding>> { | ||
| if !config.rule_configured(RULE_ID) { | ||
| return Ok(Vec::new()); | ||
| } | ||
| let tracked = tracked_rels(root, all_files); | ||
|
jonathanong marked this conversation as resolved.
|
||
| let config_file = config_rel(root, all_files); | ||
| let mut findings = paths::lint(config, &tracked, &config_file)?; | ||
| findings.extend(globs::lint(config, &tracked, &config_file)?); | ||
| findings.extend(limits::lint(config, &config_file)); | ||
| super::sort_findings(&mut findings); | ||
| Ok(findings) | ||
| } | ||
|
|
||
| fn tracked_rels(root: &Path, all_files: &[PathBuf]) -> BTreeSet<String> { | ||
| all_files | ||
| .iter() | ||
| .map(|path| relative_slash_path(root, path)) | ||
| .filter(|rel| !rel.is_empty()) | ||
| .collect() | ||
| } | ||
|
|
||
| fn config_rel(root: &Path, all_files: &[PathBuf]) -> String { | ||
| all_files | ||
| .iter() | ||
| .find_map(|path| { | ||
| let name = path.file_name()?.to_str()?; | ||
| (name == ".no-mistakes.yml" || name == ".no-mistakes.yaml") | ||
| .then(|| relative_slash_path(root, path)) | ||
| }) | ||
| .unwrap_or_else(|| ".no-mistakes.yml".to_string()) | ||
|
jonathanong marked this conversation as resolved.
|
||
| } | ||
|
|
||
| pub(super) fn finding(config_file: &str, message: String) -> RuleFinding { | ||
| RuleFinding { | ||
| rule: RULE_ID.to_string(), | ||
| file: config_file.to_string(), | ||
| line: 1, | ||
|
jonathanong marked this conversation as resolved.
|
||
| message, | ||
| import: None, | ||
| target: None, | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; | ||
92 changes: 92 additions & 0 deletions
92
crates/no-mistakes/src/codebase/rules/no_mistakes_config/globs.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| use super::finding; | ||
| use super::paths::frameworks; | ||
| use crate::codebase::rules::path_filter::GlobMatcher; | ||
| use crate::codebase::rules::RuleFinding; | ||
| use crate::config::v2::NoMistakesConfig; | ||
| use anyhow::Result; | ||
| use std::collections::BTreeSet; | ||
|
|
||
| pub(super) fn lint( | ||
| config: &NoMistakesConfig, | ||
| tracked: &BTreeSet<String>, | ||
| config_file: &str, | ||
| ) -> Result<Vec<RuleFinding>> { | ||
| let mut findings = Vec::new(); | ||
| for (framework, plan) in frameworks(config) { | ||
| for (env_name, env) in &plan.environments { | ||
| lint_patterns( | ||
| &format!("testPlan.{framework}.environments.{env_name}.include"), | ||
| &env.include, | ||
| tracked, | ||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| lint_patterns( | ||
| &format!("testPlan.{framework}.environments.{env_name}.exclude"), | ||
| &env.exclude, | ||
| tracked, | ||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| } | ||
| } | ||
| for (name, project) in &config.projects { | ||
| lint_patterns( | ||
| &format!("projects.{name}.include"), | ||
| &project.include, | ||
| tracked, | ||
|
jonathanong marked this conversation as resolved.
|
||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| lint_patterns( | ||
| &format!("projects.{name}.exclude"), | ||
| &project.exclude, | ||
| tracked, | ||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| } | ||
| for (index, rule) in config.rules.iter().enumerate() { | ||
| lint_patterns( | ||
|
jonathanong marked this conversation as resolved.
|
||
| &format!("rules[{index}].include"), | ||
| &rule.include, | ||
|
jonathanong marked this conversation as resolved.
|
||
| tracked, | ||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| lint_patterns( | ||
| &format!("rules[{index}].exclude"), | ||
| &rule.exclude, | ||
| tracked, | ||
| config_file, | ||
| &mut findings, | ||
| )?; | ||
| } | ||
| Ok(findings) | ||
| } | ||
|
|
||
| fn lint_patterns( | ||
| field: &str, | ||
| patterns: &[String], | ||
| tracked: &BTreeSet<String>, | ||
| config_file: &str, | ||
| findings: &mut Vec<RuleFinding>, | ||
| ) -> Result<()> { | ||
| for (index, pattern) in patterns.iter().enumerate() { | ||
| if pattern.trim().is_empty() || !looks_like_glob(pattern) { | ||
| continue; | ||
|
jonathanong marked this conversation as resolved.
|
||
| } | ||
| let matcher = GlobMatcher::new(std::slice::from_ref(pattern), field)?; | ||
| if !tracked.iter().any(|rel| matcher.is_match(rel)) { | ||
|
jonathanong marked this conversation as resolved.
|
||
| findings.push(finding( | ||
| config_file, | ||
| format!("{field}[{index}]: glob `{pattern}` matches no tracked files"), | ||
| )); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn looks_like_glob(pattern: &str) -> bool { | ||
| pattern.contains('*') || pattern.contains('?') || pattern.contains('{') | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
crates/no-mistakes/src/codebase/rules/no_mistakes_config/limits.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use super::finding; | ||
| use super::paths::frameworks; | ||
| use crate::codebase::rules::RuleFinding; | ||
| use crate::config::v2::schema::{TestPlanEnvironment, TestPlanGroupType, TestPlanLimit}; | ||
| use crate::config::v2::NoMistakesConfig; | ||
|
|
||
| pub(super) fn lint(config: &NoMistakesConfig, config_file: &str) -> Vec<RuleFinding> { | ||
| let mut findings = Vec::new(); | ||
| for (framework, plan) in frameworks(config) { | ||
| for (env_name, env) in &plan.environments { | ||
| if has_effective_limit(&env.limit) && !env.all && has_direct_group(env) { | ||
| findings.push(finding( | ||
| config_file, | ||
| format!( | ||
| "testPlan.{framework}.environments.{env_name} has a limit while a direct group exists; \ | ||
| scope the budget onto non-direct groups so changed tests are not dropped (regression #9440)" | ||
| ), | ||
| )); | ||
| } | ||
| } | ||
| } | ||
| findings | ||
| } | ||
|
|
||
| fn has_direct_group(env: &TestPlanEnvironment) -> bool { | ||
| env.groups.is_empty() | ||
| || env | ||
| .groups | ||
| .iter() | ||
| .any(|group| group.type_ == TestPlanGroupType::Direct) | ||
| } | ||
|
|
||
| fn has_effective_limit(limit: &Option<TestPlanLimit>) -> bool { | ||
| let Some(limit) = limit else { | ||
| return false; | ||
| }; | ||
| limit.files.is_some() | ||
| || limit | ||
| .percent | ||
| .as_ref() | ||
| .and_then(|percent| percent.value()) | ||
| .is_some() | ||
|
jonathanong marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.