Skip to content

Commit 0590376

Browse files
committed
add IDE integration tests
1 parent 3345a19 commit 0590376

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed

tests/dscanner.ini

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
; Configure which static analysis checks are enabled
2+
[analysis.config.StaticAnalysisConfig]
3+
; Check variable, class, struct, interface, union, and function names against the Phobos style guide
4+
style_check="disabled"
5+
; Check for array literals that cause unnecessary allocation
6+
enum_array_literal_check="enabled"
7+
; Check for poor exception handling practices
8+
exception_check="enabled"
9+
; Check for use of the deprecated 'delete' keyword
10+
delete_check="enabled"
11+
; Check for use of the deprecated floating point operators
12+
float_operator_check="enabled"
13+
; Check number literals for readability
14+
number_style_check="enabled"
15+
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable, or inout.
16+
object_const_check="enabled"
17+
; Checks for .. expressions where the left side is larger than the right.
18+
backwards_range_check="enabled"
19+
; Checks for if statements whose 'then' block is the same as the 'else' block
20+
if_else_same_check="enabled"
21+
; Checks for some problems with constructors
22+
constructor_check="enabled"
23+
; Checks for unused variables
24+
unused_variable_check="enabled"
25+
; Checks for unused labels
26+
unused_label_check="enabled"
27+
; Checks for unused function parameters
28+
unused_parameter_check="enabled"
29+
; Checks for duplicate attributes
30+
duplicate_attribute="enabled"
31+
; Checks that opEquals and toHash are both defined or neither are defined
32+
opequals_tohash_check="enabled"
33+
; Checks for subtraction from .length properties
34+
length_subtraction_check="enabled"
35+
; Checks for methods or properties whose names conflict with built-in properties
36+
builtin_property_names_check="enabled"
37+
; Checks for confusing code in inline asm statements
38+
asm_style_check="enabled"
39+
; Checks for confusing logical operator precedence
40+
logical_precedence_check="enabled"
41+
; Checks for undocumented public declarations
42+
undocumented_declaration_check="disabled"
43+
; Checks for poor placement of function attributes
44+
function_attribute_check="enabled"
45+
; Checks for use of the comma operator
46+
comma_expression_check="enabled"
47+
; Checks for local imports that are too broad. Only accurate when checking code used with D versions older than 2.071.0
48+
local_import_check="enabled"
49+
; Checks for variables that could be declared immutable
50+
could_be_immutable_check="enabled"
51+
; Checks for redundant expressions in if statements
52+
redundant_if_check="enabled"
53+
; Checks for redundant parenthesis
54+
redundant_parens_check="enabled"
55+
; Checks for mismatched argument and parameter names
56+
mismatched_args_check="enabled"
57+
; Checks for labels with the same name as variables
58+
label_var_same_name_check="enabled"
59+
; Checks for lines longer than `max_line_length` characters
60+
long_line_check="enabled"
61+
; Checks for assignment to auto-ref function parameters
62+
auto_ref_assignment_check="enabled"
63+
; Checks for incorrect infinite range definitions
64+
incorrect_infinite_range_check="enabled"
65+
; Checks for asserts that are always true
66+
useless_assert_check="enabled"
67+
; Check for uses of the old-style alias syntax
68+
alias_syntax_check="enabled"
69+
; Checks for else if that should be else static if
70+
static_if_else_check="enabled"
71+
; Check for unclear lambda syntax
72+
lambda_return_check="enabled"
73+
; Check for auto function without return statement
74+
auto_function_check="enabled"
75+
; Check for sortedness of imports
76+
imports_sortedness="enabled"
77+
; Check for explicitly annotated unittests
78+
explicitly_annotated_unittests="enabled"
79+
; Check for properly documented public functions (Returns, Params)
80+
properly_documented_public_functions="enabled"
81+
; Check for useless usage of the final attribute
82+
final_attribute_check="enabled"
83+
; Check for virtual calls in the class constructors
84+
vcall_in_ctor="enabled"
85+
; Check for useless user defined initializers
86+
useless_initializer="enabled"
87+
; Check allman brace style
88+
allman_braces_check="enabled"
89+
; Check for redundant attributes
90+
redundant_attributes_check="enabled"
91+
; Check public declarations without a documented unittest
92+
has_public_example="enabled"
93+
; Check for asserts without an explanatory message
94+
assert_without_msg="enabled"
95+
; Check indent of if constraints
96+
if_constraints_indent="enabled"
97+
; Check for @trusted applied to a bigger scope than a single function
98+
trust_too_much="enabled"
99+
; Check for redundant storage classes on variable declarations
100+
redundant_storage_classes="enabled"
101+
; Check for unused function return values
102+
unused_result="enabled"
103+
; Enable cyclomatic complexity check
104+
cyclomatic_complexity="enabled"
105+
; Check for function bodies on discord functions
106+
body_on_disabled_func_check="enabled"
107+
; Formatting brace style for automatic fixes (allman, otbs, stroustrup, knr)
108+
brace_style="allman"
109+
; Formatting indentation style for automatic fixes (tabs, spaces)
110+
indentation_style="tab"
111+
; Formatting line ending character (lf, cr, crlf)
112+
eol_style="lf"
113+

tests/it.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
DSCANNER_DIR="$(dirname -- $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ))"
6+
dub build --root="$DSCANNER_DIR"
7+
8+
cd "$DSCANNER_DIR/tests"
9+
10+
# IDE APIs
11+
# --------
12+
# checking that reporting format stays consistent or only gets extended
13+
diff <(jq -S . <(../bin/dscanner --report it/source_autofix.d)) <(jq -S . it/source_autofix.report.json)
14+
diff <(jq -S . <(../bin/dscanner --resolveMessage b16 it/source_autofix.d)) <(jq -S . it/source_autofix.autofix.json)
15+
16+

tests/it/source_autofix.autofix.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"name": "Mark function `const`",
4+
"replacements": [
5+
{
6+
"newText": " const",
7+
"range": [
8+
24,
9+
24
10+
]
11+
}
12+
]
13+
},
14+
{
15+
"name": "Mark function `inout`",
16+
"replacements": [
17+
{
18+
"newText": " inout",
19+
"range": [
20+
24,
21+
24
22+
]
23+
}
24+
]
25+
},
26+
{
27+
"name": "Mark function `immutable`",
28+
"replacements": [
29+
{
30+
"newText": " immutable",
31+
"range": [
32+
24,
33+
24
34+
]
35+
}
36+
]
37+
}
38+
]

tests/it/source_autofix.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct S
2+
{
3+
int myProp() @property
4+
{
5+
}
6+
}

tests/it/source_autofix.report.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"classCount": 0,
3+
"functionCount": 1,
4+
"interfaceCount": 0,
5+
"issues": [
6+
{
7+
"column": 6,
8+
"endColumn": 12,
9+
"endIndex": 22,
10+
"endLine": 3,
11+
"fileName": "it\/source_autofix.d",
12+
"index": 16,
13+
"key": "dscanner.confusing.function_attributes",
14+
"line": 3,
15+
"message": "Zero-parameter '@property' function should be marked 'const', 'inout', or 'immutable'.",
16+
"name": "function_attribute_check",
17+
"supplemental": [],
18+
"type": "warn"
19+
}
20+
],
21+
"lineOfCodeCount": 0,
22+
"statementCount": 0,
23+
"structCount": 1,
24+
"templateCount": 0,
25+
"undocumentedPublicSymbols": 0
26+
}

0 commit comments

Comments
 (0)