-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
bestpractices.xml
72 lines (66 loc) · 2.99 KB
/
bestpractices.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Best Practices"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
Rules which enforce generally accepted best practices.
</description>
<rule name="ProhibitedInterfaceBuilder"
since="7.0.0"
language="swift"
message="Creating views using Interface Builder should be avoided."
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_swift_bestpractices.html#prohibitedinterfacebuilder">
<description>
Creating views using Interface Builder should be avoided.
Defining views by code allows the compiler to detect issues that otherwise will be runtime errors.
It's difficult to review the auto-generated code and allow concurrent modifications of those files.
Consider building views programmatically.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
//VariableDeclarationHead/Attributes/Attribute[AttributeName/Identifier/T-Identifier[@Text = "IBOutlet"]]
|
//FunctionHead/Attributes/Attribute[AttributeName/Identifier/T-Identifier[@Text = "IBAction"]]
</value>
</property>
</properties>
<example>
<![CDATA[
class ViewController: UIViewController {
@IBOutlet var label: UILabel! // violation, referencing a IBOutlet
}
class ViewController: UIViewController {
var label: UILabel!
}
]]>
</example>
</rule>
<rule name="UnavailableFunction"
since="7.0.0"
language="swift"
message="Unimplemented functions should be marked as unavailable."
class="net.sourceforge.pmd.lang.swift.rule.bestpractices.UnavailableFunctionRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_swift_bestpractices.html#unavailablefunction">
<description>
Due to Objective-C and Swift interoperability some functions are often required to be implemented but
aren't really needed. It is extremely common that the sole implementation of the functions consist of throwing
a fatal error. Marking these functions as unavailable prevents them from being executed while still making
the compiler happy.
</description>
<priority>3</priority>
<example>
<![CDATA[
required init?(coder _: NSCoder) { // violation, no unavailable attribute added to the function declaration
fatalError("init(coder:) has not been implemented")
}
@available(*, unavailable) // no violation
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
]]>
</example>
</rule>
</ruleset>