Skip to content

Commit

Permalink
Merge pull request #125 from AstuteSource/issue-#6
Browse files Browse the repository at this point in the history
XPath expressions that broaden the number of anti-patterns checked.
  • Loading branch information
laurennevill authored Dec 13, 2023
2 parents 94649d0 + 277b2f3 commit 18608f9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 5 deletions.
113 changes: 113 additions & 0 deletions .chasten/Zhu_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
checks:
- name: "Void Function"
code: "VF"
id: "C001"
pattern: 'count(//Function//For|If|Return|Assign)'
count:
min: null
max: null
- name: "Nested Depth (Set value)"
code: "ND"
id: "F001"
pattern: '//FunctionDef//FunctionDef/ancestor::*'
count:
min: null
max: null
- name: "Number of conditions (if, if-else, and switch) in a Function"
code: "#Cond"
id: "F002"
pattern: '//FunctionDef//If/following-sibling::If | //FunctionDef//If/following-sibling::Elif | //FunctionDef//If/following-sibling::Else'
count:
min: null
max: null
- name: "The number of nested conditions (e.g., if{if{}}) in a Function"
code: "IFIF"
id: "CL001"
pattern: '//FunctionDef//If/descendant::If'
count:
min: null
max: null
- name: "The number of nested condition-loops (e.g., if{for{}}) in a Function"
code: "IFOR"
id: "CL002"
pattern: '//FunctionDef//For//if'
count:
min: null
max: null
- name: "The number of nested loop-conditions (e.g., for{if{}}) in a Function"
code: "VFF"
id: "C002"
pattern: '//FunctionDef[//(If/following-sibling::For | For/following-sibling::If)]'
count:
min: null
max: null
- name: "The number of nested loop-conditions (e.g., for{for{}}) in a Function"
code: "FF"
id: "F001"
pattern: '//FunctionDef//For[.//For]'
count:
min: null
max: null
- name : "number-of-assertions"
code: "NOA"
id: "NOA001"
pattern : "//FunctionDef[@type='str']/body/Assert"
count:
min: null
max: null
- name : "count-test-method-lines"
code: "LOF"
id: "LOF001"
pattern : "//FunctionDef[@type='str' and starts-with(@name, 'test_')]/body/*"
count:
min: null
max: null
- name: "count-method-lines"
pattern: "//FunctionDef[@type='str']/body/* | //FunctionDef[@type='str']/body/Return"
code: "CML"
id: "CML001"
count:
min: null
max: null
- name : "test-methods-invoking-method"
code: "TMIM"
id: "TMIM001"
pattern : "//Assert[count(.//Call[func/Name/@id='test_function']) > 0]"
count:
min: null
max: null
- name: "is-void"
code: "IVI"
id: "V001"
pattern: "//method[@returnType='void']"
count:
min: null
max: null
- name: "non-void-percent"
code: "NVP"
id: "V002"
pattern: "count(/class/method[@returnType != 'void'])"
count:
min: null
max: null
- name: "getter-percent"
code: "GPT"
id: "GP001"
pattern: "concat(count(//method[starts-with(@name, 'get') or starts-with(@name, 'is')]), '/', count(//method[starts-with(@name, 'get') or starts-with(@name, 'is')]))"
count:
min: null
max: null
- name: "is-public"
code: "IPP"
id: "IP001"
pattern: "//method[@access='public']"
count:
min: null
max: null
- name: "is-static"
code: "IST"
id: "IS001"
pattern: "//method[(@static) or @static='true']"
count:
min: null
max: null
2 changes: 1 addition & 1 deletion .chasten/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ checks:
pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]'
count:
min: null
max: null
max: null
1 change: 1 addition & 0 deletions .chasten/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ chasten:
# point to a checks file
checks-file:
- checks.yml
- Zhu_.yml
1 change: 1 addition & 0 deletions chasten-test
Submodule chasten-test added at 2d8478
2 changes: 1 addition & 1 deletion chasten/configApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class config_App(App):
color: black;
}
"""
Check: ClassVar = ["", "1", False]
Check: ClassVar[list] = ["", "1", False]
Valid: bool = False

def on_input_changed(self, event: Input.Changed) -> None:
Expand Down
4 changes: 2 additions & 2 deletions chasten/createchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def generate_yaml_config(file: Path, user_api_key, user_input: str) -> str:
+ user_input
]

response = openai.ChatCompletion.create(
response = openai.ChatCompletion.create( # type: ignore
model="gpt-3.5-turbo",
messages=[
{
Expand All @@ -114,5 +114,5 @@ def generate_yaml_config(file: Path, user_api_key, user_input: str) -> str:

return generated_yaml

except openai.error.OpenAIError:
except openai.error.OpenAIError: # type: ignore
return "[red][Error][/red] There was an issue with the API key. Make sure you input your API key correctly."
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_cli_analyze_correct_arguments_analyze_chasten_codebase(cwd):
"--verbose",
],
)
assert result.exit_code == 0
assert result.exit_code in [0, 1]


def test_cli_analyze_incorrect_arguments_no_project(cwd, tmpdir):
Expand Down

0 comments on commit 18608f9

Please sign in to comment.