Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Welcome!

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

September, 2014

Slide 5

Slide 5 text

Code Quality Metrics...

Slide 6

Slide 6 text

Code Quality Metrics... ...in Objective-C

Slide 7

Slide 7 text

Technical Debt

Slide 8

Slide 8 text

Tooling in 2014

Slide 9

Slide 9 text

Tooling in 2014 ☞ gcov ☞ PMD ☞ bash scripts ☞ ...

Slide 10

Slide 10 text

Back to Swift

Slide 11

Slide 11 text

AltConf 2015

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

I Code metrics

Slide 14

Slide 14 text

# lines of code

Slide 15

Slide 15 text

❝Mo Code Mo Problems❞

Slide 16

Slide 16 text

# of tests

Slide 17

Slide 17 text

Code coverage

Slide 18

Slide 18 text

Cyclomatic complexity func example(a: Int, b: Int, c:Int, d:Int) { // 1 if a == b { // 2 print("I") } else if (c == d) { // 3 for index in 1...5 { // 4 print("Have") } } else { // 5 switch c { case 1: // 6 print("No") case 2: // 7 print("Idea") default: // 8 print("What I'm doing") } } }

Slide 19

Slide 19 text

NPath complexity func example(a:Int, b:Int) { if a > 10 { print(1) } else { print(2) } if a > b { print(3) } else { print(4) } } // Result: 4

Slide 20

Slide 20 text

Duplications

Slide 21

Slide 21 text

Depth of inheritance

Slide 22

Slide 22 text

Class coupling

Slide 23

Slide 23 text

Code issues

Slide 24

Slide 24 text

NCSS

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

SPLINTER

Slide 27

Slide 27 text

S wift P layground L aunch INTER val

Slide 28

Slide 28 text

II How to measure

Slide 29

Slide 29 text

swiftc

Slide 30

Slide 30 text

SwiftLint github.com/realm/SwiftLint

Slide 31

Slide 31 text

SwiftLint ☞ Static analysis ☞ via AST... ☞ ...and Regular Expressions ☞ Supports custom rules ☞ Detects cyclomatic complexity

Slide 32

Slide 32 text

SwiftLint ☞ $ brew install swiftlint ☞ $ swiftlint Rules ☞ $ swiftlint rules

Slide 33

Slide 33 text

Tailor github.com/sleekbyte/tailor

Slide 34

Slide 34 text

Tailor ☞ Cross-platform ☞ Different output formats ☞ Based on ANTLR ☞ Simpler rules

Slide 35

Slide 35 text

Tailor $ brew install tailor $ tailor

Slide 36

Slide 36 text

Lizard github.com/terryyin/lizard Cyclomatic complexity analyzer pip install lizard

Slide 37

Slide 37 text

Slather github.com/SlatherOrg/slather

Slide 38

Slide 38 text

Slather ☞ Reads Xcode Code Coverage information ☞ Outputs to a number of different formats (included Cobertura) ☞ Supports a plethora of systems, such as Coveralls, Codecov, etc

Slide 39

Slide 39 text

Slather $ gem install slather $ slather coverage [FORMAT] -b [BUILD_DIR] --scheme [SCHEME] [PROJECT]

Slide 40

Slide 40 text

To sum up ☞ swiftc ☞ SwiftLint ☞ Tailor ☞ Lizard ☞ Slather

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

III Integration

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Codecov codecov.io

Slide 45

Slide 45 text

Codecov ☞ GitHub Integration ☞ Code coverage

Slide 46

Slide 46 text

Hound github.com/houndci/hound

Slide 47

Slide 47 text

Hound ☞ Code issues (via SwiftLint) ☞ GitHub Integration

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Code climate codeclimate.com

Slide 51

Slide 51 text

Code climate ☞ Code issues (via Tailor) ☞ GitHub Integration ☞ Code Coverage

Slide 52

Slide 52 text

Xcode Bots

Slide 53

Slide 53 text

Xcode Bots ☞ Code issues (via swiftc and SwiftLint) ☞ Code Coverage

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

SonarQube sonarqube.org

Slide 58

Slide 58 text

SonarQube ☞ Acts as an hub for a variety of code metrics ☞ Code Coverage ☞ Code Issues ☞ SCM ☞ Complexity (Project-wide) ☞ Duplications

Slide 59

Slide 59 text

SonarQube - Installing $ brew install sonar Tip ☞ Configure a database (MySQL or Postgre)

Slide 60

Slide 60 text

SonarQube Runner

Slide 61

Slide 61 text

SonarQube Runner The frontend for executing sonar Reads a sonar-project.properties file in the project folder

Slide 62

Slide 62 text

SonarQube Runner - Installing $ brew install sonar-runner # Front end

Slide 63

Slide 63 text

SonarQube + Swift == !

Slide 64

Slide 64 text

SonarQube + Swift ==

Slide 65

Slide 65 text

SonarQube Swift plugin github.com/Backelite/sonar-swift

Slide 66

Slide 66 text

SonarQube Swift plugin Retrieves reports from: ☞ Test execution ☞ SwiftLint ☞ Lizard ☞ Slather

Slide 67

Slide 67 text

SonarQube Swift plugin Adds: ☞ Documentation count ☞ LOCs ☞ CPD (Duplication)

Slide 68

Slide 68 text

SonarQube Swift plugin - Installing a. Build from sources: $ cd path/to/swift/plugin $ ./build-and-deploy.sh b. Or download pre-built jar file into $SONARQUBE_HOME/extensions/plugins

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

III bis Automation

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Fastlane

Slide 77

Slide 77 text

Fastlane actions we use ➀ scan ➁ slather ➂ swiftlint ➃ lizard (via sh) ➄ sonar

Slide 78

Slide 78 text

0. Fastlane platform :ios do desc "Collect all the metrics" lane :metrics do

Slide 79

Slide 79 text

1. scan scan(scheme: "MyProject", code_coverage: true, xcargs: "-derivedDataPath ./DerivedData", output_directory: "./reports")

Slide 80

Slide 80 text

2. Slather slather(cobertura_xml: true, scheme: "MyProject", output_directory: "./reports", build_directory: "./DerivedData", binary_basename: "MyProject", proj: "./MyProject.xcodeproj")

Slide 81

Slide 81 text

3. SwiftLint swiftlint(output_file: "./reports/swiftlint.txt", ignore_exit_status: true)

Slide 82

Slide 82 text

4. Lizard sh("cd .. && lizard ./MyProject -l swift --xml > ./reports/lizard-report.xml")

Slide 83

Slide 83 text

5.1 Sonar: sonar-project.properties sonar.projectKey = MyProject sonar.projectName = MyProject sonar.language = swift sonar.sources = MyProject # Sources Folder sonar.tests = MyProjectTests # Test Sources Folder # Report paths sonar.junit.reportsPath = reports/ sonar.swift.lizard.report = reports/lizard-report.xml sonar.swift.coverage.reportPattern = reports/cobertura.xml sonar.swift.SwiftLint.report = reports/*SwiftLint.txt

Slide 84

Slide 84 text

5.2 Sonar-Runner - Fastlane sonar(project_version: Time.new.strftime("%Y.%m.%d.%H.%M"))

Slide 85

Slide 85 text

Complete example platform :ios do desc "Collect all the metrics" lane :metrics do scan(scheme: "MyProject", code_coverage: true, xcargs: "-derivedDataPath ./DerivedData", output_directory: "./reports") slather(cobertura_xml: true, jenkins: true, scheme: "MyProject", output_directory: "./reports", build_directory: "./DerivedData", binary_basename: "MyProject", proj: "./MyProject.xcodeproj") sh("cd .. && lizard ./MyProject -l swift --xml > ./reports/lizard-report.xml") swiftlint(output_file: "./reports/swiftlint.txt", ignore_exit_status: true) sonar(project_version: Time.new.strftime("%Y.%m.%d.%H.%M")) end end

Slide 86

Slide 86 text

IV The bottom line

Slide 87

Slide 87 text

Do not blindly believe in metrics

Slide 88

Slide 88 text

Why should we use them? ☞ understand which components need reworking ☞ identify potential risks ☞ track progress ☞ have an overall view of large systems

Slide 89

Slide 89 text

Automate

Slide 90

Slide 90 text

Pick complementary metrics

Slide 91

Slide 91 text

Aim for all metrics (rather than excelling in a single one)

Slide 92

Slide 92 text

Be honest with yourself

Slide 93

Slide 93 text

Share the results with your team

Slide 94

Slide 94 text

Analyse your metrics

Slide 95

Slide 95 text

Be the quality you want to see in your app

Slide 96

Slide 96 text

Thank you!

Slide 97

Slide 97 text

@viteinfinite

Slide 98

Slide 98 text

One more film

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

CFP is open papercall.io/frenchkit-2016

Slide 104

Slide 104 text

Thank you! @viteinfinite

Slide 105

Slide 105 text

THE USE OF ANY COPYRIGHTED MATERIAL IS USED UNDER THE GUIDELINES OF "FAIR USE" IN TITLE 17 § 107 OF THE UNITED STATES CODE. SUCH MATERIAL REMAINS THE COPYRIGHT OF THE ORIGINAL HOLDER AND IS USED HERE FOR THE PURPOSES OF EDUCATION, COMPARISON, AND CRITICISM ONLY. NO INFRINGEMENT OF COPYRIGHT IS INTENDED.