diff --git a/src/core/driver/driver.ml b/src/core/driver/driver.ml index cbe1701..2cd761a 100644 --- a/src/core/driver/driver.ml +++ b/src/core/driver/driver.ml @@ -105,7 +105,7 @@ let scope_matches { includes; ignores } file = exception Break of Neal.Rule.ruleset list let collect_rules file rules = function | (`Global, rs) -> rs @ rules - | (`Scoped scope, rs) when scope_matches scope file -> raise (Break rs) + | (`Scoped scope, rs) when scope_matches scope file -> rs @ rules | _ -> rules let visitor (module P : Provider.PROVIDER) reporters file source rules absyn = diff --git a/tests/integration/input/glob/test.test b/tests/integration/input/glob/test.test index b234593..1861e9f 100644 --- a/tests/integration/input/glob/test.test +++ b/tests/integration/input/glob/test.test @@ -1,5 +1,8 @@ // RUN: %not %neal %p | %check -// CHECK-NEXT: error: Must use visibility = PRIVATE instead. -// CHECK-NEXT: error: Call bar instead +// Make sure that there are only 2 errors emitted +// RUN: %not %neal %p | test $(wc -l) -eq 3 + +// CHECK: error: Must use visibility = PRIVATE instead. +// CHECK: error: Call bar instead // CHECK-NOT: .* diff --git a/tests/integration/multiple_configurations/apps/Application.swift b/tests/integration/multiple_configurations/apps/Application.swift new file mode 100644 index 0000000..d2ed0ab --- /dev/null +++ b/tests/integration/multiple_configurations/apps/Application.swift @@ -0,0 +1,14 @@ + + +func main() { + let value = convertToInteger(0.123) + DispatchQueue.main.async { + let view = UIView() + view.backgroundColor = .red + } +} + + +func convertToInteger(x: Double) -> Int { + return x as! Int +} diff --git a/tests/integration/multiple_configurations/libraries/Libraries.swift b/tests/integration/multiple_configurations/libraries/Libraries.swift new file mode 100644 index 0000000..1b5bc68 --- /dev/null +++ b/tests/integration/multiple_configurations/libraries/Libraries.swift @@ -0,0 +1,12 @@ +import UIKit +import Foundation + +func getDispatchQueue() { + let dispatchQueue = Foundation.DispatchQueue() +} + +func setBlackColor(view: UIView) { + view.backgroundColor = .white +} + + diff --git a/tests/integration/multiple_configurations/lit.local.cfg b/tests/integration/multiple_configurations/lit.local.cfg new file mode 100644 index 0000000..d055999 --- /dev/null +++ b/tests/integration/multiple_configurations/lit.local.cfg @@ -0,0 +1,3 @@ +# vi: ft=python + +config.suffixes = ['.test'] diff --git a/tests/integration/multiple_configurations/multiple_configurations.test b/tests/integration/multiple_configurations/multiple_configurations.test new file mode 100644 index 0000000..b7f4bf4 --- /dev/null +++ b/tests/integration/multiple_configurations/multiple_configurations.test @@ -0,0 +1,8 @@ +// RUN: %not %neal %p | %check + +// Make sure that there are only 3 errors emitted +// RUN: %not %neal %p | test $(wc -l) -eq 3 + +// CHECK-L:apps/Application.swift:12: error: Force-casting can easily crash the app, therefore, not allowed. (NoForceCasting) +// CHECK-L:libraries/Libraries.swift:5: error: Use `PresidioFoundation.DispatchQueue` instead of GCD to allow unit testing. (GCD) +// CHECK-L:libraries/Libraries.swift:9: error: Dont use default UIColors (UIColors) diff --git a/tests/integration/multiple_configurations/neal.json b/tests/integration/multiple_configurations/neal.json new file mode 100644 index 0000000..9dae55f --- /dev/null +++ b/tests/integration/multiple_configurations/neal.json @@ -0,0 +1,31 @@ +{ + "rule-map": [ + { + "name": "APPLICATION_CONFIG", + "glob": [ + "apps/.*" + ], + "rules": [ + "./rules/application.rules" + ] + }, + { + "name": "LIBRARY_CONFIG", + "glob": [ + "libraries/.*" + ], + "rules": [ + "./rules/libraries.rules" + ] + }, + { + "name": "COMMON_RULES", + "glob": [ + ".*" + ], + "rules": [ + "./rules/common.rules" + ] + } + ] +} diff --git a/tests/integration/multiple_configurations/rules/application.rules b/tests/integration/multiple_configurations/rules/application.rules new file mode 100644 index 0000000..32e213f --- /dev/null +++ b/tests/integration/multiple_configurations/rules/application.rules @@ -0,0 +1,5 @@ +rule NoForceCasting { + Swift::TypeCastingExpresion where Operator == "as!" { + fail("Force-casting can easily crash the app, therefore, not allowed.") + } +} diff --git a/tests/integration/multiple_configurations/rules/common.rules b/tests/integration/multiple_configurations/rules/common.rules new file mode 100644 index 0000000..a99fbd9 --- /dev/null +++ b/tests/integration/multiple_configurations/rules/common.rules @@ -0,0 +1,7 @@ + +rule GCD { + Swift::ExplicitMemberExpression where Object == "Foundation" && Member == "DispatchQueue" { + fail("Use `PresidioFoundation.DispatchQueue` instead of GCD to allow unit testing.") + } +} + diff --git a/tests/integration/multiple_configurations/rules/libraries.rules b/tests/integration/multiple_configurations/rules/libraries.rules new file mode 100644 index 0000000..093ab2d --- /dev/null +++ b/tests/integration/multiple_configurations/rules/libraries.rules @@ -0,0 +1,5 @@ +rule UIColors { + Swift::ImplicitMemberExpression where match(Property, /\b(white|black|lightGray|gray|clear|darkGray|orange|clear|yellow|blue|red)$/) { + fail("Dont use default UIColors") + } +}