Skip to content

[DO NOT REVIEW ] Append rules that match the glob in neal.json #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/driver/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/input/glob/test.test
Original file line number Diff line number Diff line change
@@ -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: .*
14 changes: 14 additions & 0 deletions tests/integration/multiple_configurations/apps/Application.swift
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import UIKit
import Foundation

func getDispatchQueue() {
let dispatchQueue = Foundation.DispatchQueue()
}

func setBlackColor(view: UIView) {
view.backgroundColor = .white
}


3 changes: 3 additions & 0 deletions tests/integration/multiple_configurations/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# vi: ft=python

config.suffixes = ['.test']
Original file line number Diff line number Diff line change
@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we expect only NoForceCasting is triggered for this file?

// 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)
31 changes: 31 additions & 0 deletions tests/integration/multiple_configurations/neal.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rule NoForceCasting {
Swift::TypeCastingExpresion where Operator == "as!" {
fail("Force-casting can easily crash the app, therefore, not allowed.")
}
}
7 changes: 7 additions & 0 deletions tests/integration/multiple_configurations/rules/common.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

rule GCD {
Swift::ExplicitMemberExpression where Object == "Foundation" && Member == "DispatchQueue" {
fail("Use `PresidioFoundation.DispatchQueue` instead of GCD to allow unit testing.")
}
}

Original file line number Diff line number Diff line change
@@ -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")
}
}