Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- `check --format json` names the rule of the context-stage findings and of four more semantic findings, where `rule` was null (follow-up to #10). The context stage sets `Diagnostic::code` for its rule-named findings, names the owning-type rules of an `actor`, `stakeholder`, `require`/`assume`, `verify`, `entry`/`do`/`exit` or `render` member in the wrong body (`validate…MembershipOwningType`) and the name clash (`validateNamespaceDistinguishibility`); the semantic stage names `validateMetadataFeatureMetaclass`, `validateMultiplicityRangeBoundResultTypes`, `validateConnectorBinarySpecialization` and the two invocation-argument rules. The messages of the newly named context findings start with the rule, as the others do; severities do not change.

## v0.11.3

### Added
Expand Down
67 changes: 67 additions & 0 deletions crates/sysmlv2-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,73 @@ fn check_format_json_names_the_rule_a_semantic_finding_reports() {
let _ = fs::remove_dir_all(&dir);
}

#[test]
fn check_format_json_names_the_rule_of_every_stage() {
let dir = std::env::temp_dir().join(format!(
"sysmlv2-cli-test-check-json-rules-{}",
std::process::id()
));
fs::create_dir_all(&dir).unwrap();
let model = dir.join("model.sysml");
fs::write(
&model,
"package P {
requirement def R { subject a; subject b; }
calc def C { actor x; return r; }
part def D { part y; part y; }
part def K;
part k { @K; }
attribute n = 1.5;
part w[n];
calc def F { in x; return r; }
attribute z = F(x = 1, x = 2);
}
",
)
.unwrap();

let out = sysmlv2(&["check", "--format", "json", model.to_str().unwrap()]);
assert!(!out.status.success());
let doc: serde_json::Value = serde_json::from_str(&stdout(&out)).expect("stdout is JSON");
let rules: Vec<(&str, &str, &str)> = doc["findings"]
.as_array()
.unwrap()
.iter()
.map(|f| {
(
f["stage"].as_str().unwrap(),
f["severity"].as_str().unwrap(),
f["rule"].as_str().unwrap_or("null"),
)
})
.collect();
assert_eq!(
rules,
[
(
"context",
"error",
"validateRequirementDefinitionOnlyOneSubject"
),
("context", "error", "validateActorMembershipOwningType"),
("context", "error", "validateNamespaceDistinguishibility"),
("semantic", "error", "validateMetadataFeatureMetaclass"),
(
"semantic",
"error",
"validateMultiplicityRangeBoundResultTypes"
),
(
"semantic",
"warn",
"validateInvocationExpressionNoDuplicateParameterRedefinition"
),
],
"{doc}"
);
let _ = fs::remove_dir_all(&dir);
}

#[test]
fn lint_format_json_locates_findings_past_a_parse_failure() {
let dir = std::env::temp_dir().join(format!(
Expand Down
5 changes: 5 additions & 0 deletions crates/sysmlv2-model/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub const IMPLEMENTED_NORMATIVE_SEMANTIC_RULES: &[&str] = &[
"validateCaseDefinitionOnlyOneObjective",
"validateCaseUsageOnlyOneObjective",
"validateClassSpecialization",
"validateConnectorBinarySpecialization",
"validateConnectorRelatedFeatures",
"validateConstructorExpressionNoDuplicateFeatureRedefinition",
"validateControlNodeIncomingSuccessions",
Expand Down Expand Up @@ -97,11 +98,15 @@ pub const IMPLEMENTED_NORMATIVE_SEMANTIC_RULES: &[&str] = &[
"validateIncludeUseCaseUsageReference",
"validateInstantiationExpressionInstantiatedType",
"validateInvocationExpressionInstantiatedType",
"validateInvocationExpressionNoDuplicateParameterRedefinition",
"validateInvocationExpressionParameterRedefinition",
"validateJoinNodeOutgoingSuccessions",
"validateMergeNodeIncomingSuccessions",
"validateMergeNodeOutgoingSuccessions",
"validateMetadataFeatureAnnotatedElement",
"validateMetadataFeatureBody",
"validateMetadataFeatureMetaclass",
"validateMultiplicityRangeBoundResultTypes",
"validateNamespaceDistinguishibility",
"validateOccurrenceUsageIndividualDefinition",
"validateOccurrenceUsageIndividualUsage",
Expand Down
34 changes: 22 additions & 12 deletions crates/sysmlv2-model/src/check/invocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ pub(super) fn validate(r: &mut ResolvedModel, model: &Model) -> Vec<(usize, Diag
Some(name) => name.to_display_string(),
None => {
let Some(name) = params.get(positional) else {
out.push((unit, Diagnostic::warning(span, format!(
"invocation of `{}` supplies {} arguments for {} parameter(s)",
qn.to_display_string(), args.len(), params.len()
))));
out.push((unit, super::rule_warning(
span,
"validateInvocationExpressionParameterRedefinition",
format!(
"invocation of `{}` supplies {} arguments for {} parameter(s)",
qn.to_display_string(), args.len(), params.len()
),
)));
invalid = true;
break;
};
Expand All @@ -83,20 +87,26 @@ pub(super) fn validate(r: &mut ResolvedModel, model: &Model) -> Vec<(usize, Diag
}
};
let message = if !params.contains(&name) {
Some(format!(
"invocation of `{}` names unknown parameter `{name}`",
qn.to_display_string()
Some((
"validateInvocationExpressionParameterRedefinition",
format!(
"invocation of `{}` names unknown parameter `{name}`",
qn.to_display_string()
),
))
} else if !bound.insert(name.clone()) {
Some(format!(
"invocation of `{}` binds parameter `{name}` more than once",
qn.to_display_string()
Some((
"validateInvocationExpressionNoDuplicateParameterRedefinition",
format!(
"invocation of `{}` binds parameter `{name}` more than once",
qn.to_display_string()
),
))
} else {
None
};
if let Some(message) = message {
out.push((unit, Diagnostic::warning(arg.value.span, message)));
if let Some((rule, message)) = message {
out.push((unit, super::rule_warning(arg.value.span, rule, message)));
invalid = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/sysmlv2-model/src/check/multiplicities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ pub(super) fn validate(r: &mut ResolvedModel, model: &Model) -> Vec<(usize, Diag
if invalid {
out.push((
r.b.unit_of_elem(owner),
Diagnostic::error(
super::rule_error(
span,
"validateMultiplicityRangeBoundResultTypes",
"multiplicity bound must be a Natural number (or `*` for the upper bound)",
),
));
Expand Down
6 changes: 4 additions & 2 deletions crates/sysmlv2-model/src/check/specialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ pub(super) fn validate(r: &mut ResolvedModel, model: &Model) -> Vec<(usize, Diag
if !matches!(target_ty, "MetadataDefinition" | "Metaclass") {
out.push((
unit,
Diagnostic::error(
super::rule_error(
qn.span,
"validateMetadataFeatureMetaclass",
format!(
"metadata must be typed by a metadata definition or \
metaclass; `{}` is a {}",
Expand Down Expand Up @@ -398,8 +399,9 @@ pub(super) fn validate(r: &mut ResolvedModel, model: &Model) -> Vec<(usize, Diag
let ends = end_count(&r.b, *owner);
out.push((
r.b.unit_of_elem(*owner),
Diagnostic::warning(
super::rule_warning(
qn.span,
"validateConnectorBinarySpecialization",
format!(
"connector with {ends} ends specializes a binary connector (a binary connector cannot have more than two ends)"
),
Expand Down
Loading