feat(linter/jest): implement prefer-ending-with-an-expect rule#21372
feat(linter/jest): implement prefer-ending-with-an-expect rule#21372camc314 merged 1 commit intooxc-project:mainfrom
prefer-ending-with-an-expect rule#21372Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
@Afsoon is it easy to share the logic? if so, mind making a follow up PR? |
| let config = value.get(0); | ||
|
|
||
| let assert_function_names = config | ||
| .and_then(|config| config.get("assertFunctionNames")) | ||
| .and_then(serde_json::Value::as_array) | ||
| .map(|v| { | ||
| v.iter() | ||
| .filter_map(serde_json::Value::as_str) | ||
| .map(convert_pattern) | ||
| .collect::<Vec<_>>() | ||
| }) | ||
| .unwrap_or(vec!["expect".into()]); | ||
|
|
||
| let additional_test_block_functions = config | ||
| .and_then(|config| config.get("additionalTestBlockFunctions")) | ||
| .and_then(serde_json::Value::as_array) | ||
| .map(|v| v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect()) | ||
| .unwrap_or_default(); | ||
|
|
||
| Ok(Self(Box::new(PreferEndingWithAnExpectConfig { | ||
| additional_test_block_functions, | ||
| assert_function_names, | ||
| }))) |
There was a problem hiding this comment.
TODO: ideally this should be refactored to use DefaultRuleConfig, so that config errors can be surfaced to the user. we can do this at another time though.
|
@camc314 Yep, it's easy. I will make a follow up PR |
prefer-ending-with-an-expect ruleprefer-ending-with-an-expect rule
|
This rule has a few false positives that make it tricky to enable atm. Async await waitFor(() =>
expect(mockAssign).toHaveBeenCalledWith("https://stub-example.com")
);
jest.mock("../../helpers/polyfillRequestSubmit", () => ({
...jest.requireActual("../../helpers/polyfillRequestSubmit"),
polyfillRequestSubmit: jest.fn(),
})); |
|
@robsterlini can you create an issue while I check it? |
|
@robsterlini about the false positives:
|
Related to #492
AI Disclosure
Only used AI to generate the diagnostic messages and doc. The code has been made from zero.
Summary
Implements
prefer-ending-with-an-expect. The pattern logic has been copy from the ruleexpect-expectInfo