Skip to content

Commit

Permalink
add IDE integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Jul 8, 2023
1 parent 3345a19 commit 0590376
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tests/dscanner.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
; Configure which static analysis checks are enabled
[analysis.config.StaticAnalysisConfig]
; Check variable, class, struct, interface, union, and function names against the Phobos style guide
style_check="disabled"
; Check for array literals that cause unnecessary allocation
enum_array_literal_check="enabled"
; Check for poor exception handling practices
exception_check="enabled"
; Check for use of the deprecated 'delete' keyword
delete_check="enabled"
; Check for use of the deprecated floating point operators
float_operator_check="enabled"
; Check number literals for readability
number_style_check="enabled"
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable, or inout.
object_const_check="enabled"
; Checks for .. expressions where the left side is larger than the right.
backwards_range_check="enabled"
; Checks for if statements whose 'then' block is the same as the 'else' block
if_else_same_check="enabled"
; Checks for some problems with constructors
constructor_check="enabled"
; Checks for unused variables
unused_variable_check="enabled"
; Checks for unused labels
unused_label_check="enabled"
; Checks for unused function parameters
unused_parameter_check="enabled"
; Checks for duplicate attributes
duplicate_attribute="enabled"
; Checks that opEquals and toHash are both defined or neither are defined
opequals_tohash_check="enabled"
; Checks for subtraction from .length properties
length_subtraction_check="enabled"
; Checks for methods or properties whose names conflict with built-in properties
builtin_property_names_check="enabled"
; Checks for confusing code in inline asm statements
asm_style_check="enabled"
; Checks for confusing logical operator precedence
logical_precedence_check="enabled"
; Checks for undocumented public declarations
undocumented_declaration_check="disabled"
; Checks for poor placement of function attributes
function_attribute_check="enabled"
; Checks for use of the comma operator
comma_expression_check="enabled"
; Checks for local imports that are too broad. Only accurate when checking code used with D versions older than 2.071.0
local_import_check="enabled"
; Checks for variables that could be declared immutable
could_be_immutable_check="enabled"
; Checks for redundant expressions in if statements
redundant_if_check="enabled"
; Checks for redundant parenthesis
redundant_parens_check="enabled"
; Checks for mismatched argument and parameter names
mismatched_args_check="enabled"
; Checks for labels with the same name as variables
label_var_same_name_check="enabled"
; Checks for lines longer than `max_line_length` characters
long_line_check="enabled"
; Checks for assignment to auto-ref function parameters
auto_ref_assignment_check="enabled"
; Checks for incorrect infinite range definitions
incorrect_infinite_range_check="enabled"
; Checks for asserts that are always true
useless_assert_check="enabled"
; Check for uses of the old-style alias syntax
alias_syntax_check="enabled"
; Checks for else if that should be else static if
static_if_else_check="enabled"
; Check for unclear lambda syntax
lambda_return_check="enabled"
; Check for auto function without return statement
auto_function_check="enabled"
; Check for sortedness of imports
imports_sortedness="enabled"
; Check for explicitly annotated unittests
explicitly_annotated_unittests="enabled"
; Check for properly documented public functions (Returns, Params)
properly_documented_public_functions="enabled"
; Check for useless usage of the final attribute
final_attribute_check="enabled"
; Check for virtual calls in the class constructors
vcall_in_ctor="enabled"
; Check for useless user defined initializers
useless_initializer="enabled"
; Check allman brace style
allman_braces_check="enabled"
; Check for redundant attributes
redundant_attributes_check="enabled"
; Check public declarations without a documented unittest
has_public_example="enabled"
; Check for asserts without an explanatory message
assert_without_msg="enabled"
; Check indent of if constraints
if_constraints_indent="enabled"
; Check for @trusted applied to a bigger scope than a single function
trust_too_much="enabled"
; Check for redundant storage classes on variable declarations
redundant_storage_classes="enabled"
; Check for unused function return values
unused_result="enabled"
; Enable cyclomatic complexity check
cyclomatic_complexity="enabled"
; Check for function bodies on discord functions
body_on_disabled_func_check="enabled"
; Formatting brace style for automatic fixes (allman, otbs, stroustrup, knr)
brace_style="allman"
; Formatting indentation style for automatic fixes (tabs, spaces)
indentation_style="tab"
; Formatting line ending character (lf, cr, crlf)
eol_style="lf"

16 changes: 16 additions & 0 deletions tests/it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -eu -o pipefail

DSCANNER_DIR="$(dirname -- $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ))"
dub build --root="$DSCANNER_DIR"

cd "$DSCANNER_DIR/tests"

# IDE APIs
# --------
# checking that reporting format stays consistent or only gets extended
diff <(jq -S . <(../bin/dscanner --report it/source_autofix.d)) <(jq -S . it/source_autofix.report.json)
diff <(jq -S . <(../bin/dscanner --resolveMessage b16 it/source_autofix.d)) <(jq -S . it/source_autofix.autofix.json)


38 changes: 38 additions & 0 deletions tests/it/source_autofix.autofix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "Mark function `const`",
"replacements": [
{
"newText": " const",
"range": [
24,
24
]
}
]
},
{
"name": "Mark function `inout`",
"replacements": [
{
"newText": " inout",
"range": [
24,
24
]
}
]
},
{
"name": "Mark function `immutable`",
"replacements": [
{
"newText": " immutable",
"range": [
24,
24
]
}
]
}
]
6 changes: 6 additions & 0 deletions tests/it/source_autofix.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct S
{
int myProp() @property
{
}
}
26 changes: 26 additions & 0 deletions tests/it/source_autofix.report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"classCount": 0,
"functionCount": 1,
"interfaceCount": 0,
"issues": [
{
"column": 6,
"endColumn": 12,
"endIndex": 22,
"endLine": 3,
"fileName": "it\/source_autofix.d",
"index": 16,
"key": "dscanner.confusing.function_attributes",
"line": 3,
"message": "Zero-parameter '@property' function should be marked 'const', 'inout', or 'immutable'.",
"name": "function_attribute_check",
"supplemental": [],
"type": "warn"
}
],
"lineOfCodeCount": 0,
"statementCount": 0,
"structCount": 1,
"templateCount": 0,
"undocumentedPublicSymbols": 0
}

0 comments on commit 0590376

Please sign in to comment.