Skip to content

Commit 0fb157c

Browse files
Merge pull request #349 from DataDog/celia.yuen/default-for-bool
[STAL-1686] Follow-up for handling rules marked as `is_testing`
2 parents b374121 + 3892914 commit 0fb157c

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

crates/static-analysis-kernel/src/model/rule.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ pub struct Rule {
143143
pub language: Language,
144144
pub rule_type: RuleType,
145145
pub entity_checked: Option<EntityChecked>,
146-
pub is_testing: bool,
147146
#[serde(rename = "code")]
148147
pub code_base64: String,
149148
pub cwe: Option<String>,
@@ -154,6 +153,8 @@ pub struct Rule {
154153
#[serde(default)]
155154
pub arguments: Vec<Argument>,
156155
pub tests: Vec<RuleTest>,
156+
#[serde(default)]
157+
pub is_testing: bool,
157158
}
158159

159160
#[derive(Clone, Deserialize, Debug, Serialize, Builder)]

crates/static-analysis-server/src/model/analysis_request.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub struct ServerRule {
2727
pub tree_sitter_query_base64: Option<String>,
2828
#[serde(default)]
2929
pub arguments: Vec<Argument>,
30-
pub is_testing: bool,
3130
}
3231

3332
#[derive(Clone, Deserialize, Debug, Serialize)]

crates/static-analysis-server/src/request.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn process_analysis_request(request: AnalysisRequest) -> AnalysisResponse {
112112
tree_sitter_query_base64: r.tree_sitter_query_base64.clone(),
113113
arguments: r.arguments.clone(),
114114
tests: vec![],
115-
is_testing: r.is_testing,
115+
is_testing: false,
116116
})
117117
.collect();
118118

@@ -252,7 +252,6 @@ mod tests {
252252
pattern: None,
253253
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
254254
arguments: vec![],
255-
is_testing: false,
256255
}
257256
]
258257
};
@@ -286,7 +285,6 @@ mod tests {
286285
pattern: None,
287286
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
288287
arguments: vec![],
289-
is_testing: false,
290288
}
291289
]
292290
};
@@ -322,7 +320,6 @@ mod tests {
322320
pattern: None,
323321
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
324322
arguments: vec![],
325-
is_testing: false,
326323
}
327324
]
328325
};
@@ -358,7 +355,6 @@ mod tests {
358355
pattern: None,
359356
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
360357
arguments: vec![],
361-
is_testing: false,
362358
}
363359
]
364360
};
@@ -394,7 +390,6 @@ mod tests {
394390
pattern: None,
395391
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
396392
arguments: vec![],
397-
is_testing: false,
398393
}
399394
]
400395
};
@@ -422,7 +417,6 @@ mod tests {
422417
pattern: None,
423418
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
424419
arguments: vec![],
425-
is_testing: false,
426420
};
427421
let mut request = AnalysisRequest {
428422
filename: "path/to/myfile.py".to_string(),
@@ -594,7 +588,6 @@ rulesets:
594588
pattern: None,
595589
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
596590
arguments: vec![],
597-
is_testing: false,
598591
}],
599592
};
600593
let response = process_analysis_request(request.clone());
@@ -651,7 +644,6 @@ function visit(node, filename, code) {
651644
pattern: None,
652645
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
653646
arguments: vec![],
654-
is_testing: false,
655647
}
656648
]
657649
};
@@ -693,7 +685,6 @@ function visit(node, filename, code) {
693685
pattern: None,
694686
tree_sitter_query_base64: Some("KGZ1bmN0aW9uX2RlZmluaXRpb24KICAgIG5hbWU6IChpZGVudGlmaWVyKSBAbmFtZQogIHBhcmFtZXRlcnM6IChwYXJhbWV0ZXJzKSBAcGFyYW1zCik=".to_string()),
695687
arguments: vec![],
696-
is_testing: false,
697688
}
698689
]
699690
};

misc/test-production-rules.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def transform_rule(rule):
151151
'code': rule['code'],
152152
'variables': {},
153153
'checksum': rule['checksum'],
154-
'is_testing': rule['is_testing']
155154
}
156155

157156
def test_ruleset_cli(ruleset):
@@ -205,8 +204,12 @@ def test_ruleset_cli(ruleset):
205204

206205
# Invoke the tool, do not print anything
207206
cmd = f"{options.clibin} -r {test_rules_file} -i {ruledir} -o {test_results_file} -f json"
208-
subprocess.run(shlex.split(cmd), check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
209-
207+
# TODO: There should be a cleaner way to be able to parse the output of the error
208+
try:
209+
subprocess.run(shlex.split(cmd), check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
210+
except subprocess.CalledProcessError as e:
211+
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
212+
210213
# check that the number of violations match the number of expected annotations
211214
with open(test_results_file) as results_file:
212215
results = results_file.read()

0 commit comments

Comments
 (0)