Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.

Overview

Taylor

⚠️ Taylor is DEPRECATED. Use SwiftLint instead.

A tool aimed to increase Swift code quality, by checking for conformance to code metrics.

Build Status codecov.io Release version Swift Code Platform License

Taylor uses SourceKitten to a more accurate AST representation and generates the final report in either Xcode, JSON, PMD or plain text formats.

Installation

Homebrew (recommended)

You need to have Homebrew installed.

brew update
brew install taylor

Source

Rebuild dependencies by running carthage bootstrap --platform Mac (Carthage required)
Clone the project and run make install (latest version of Xcode required).

Package

Download the latest release and run:

Taylor.app/Contents/Resources/install

Usage

Xcode

To get warnings displayed in the IDE add a new Run Script Phase with:

if which taylor >/dev/null; then
  taylor -p ${PROJECT_DIR} -r xcode
else
  echo "Taylor not installed"
fi

Command line

To use Taylor from command line run it as follows:

taylor [option1 [option1_argument]] [option2 option2_argument] […]

Available options
taylor Description
-h/--help Print help.
-v/--version Print Taylor version.
-p/--path path Path to the folder to be analysed (current folder by default).
-e/--exclude file Path to either directory or file to be excluded from analysis.
-ef/--excludeFile file Path to exclude file in .yml format.
-f/--file file File to be included in analysis (may be from an external source).
-t/--type type Type of files to be analysed.
-vl/--verbosityLevel level Verbosity level for output messages (info, warning and error).
-r/--reporter type:name Type of final report (json, xcode, pmd or plain text) and filename.
-rc/--ruleCustomization rule=value Customize rules by giving custom values. See help for more details.

taylor alone with no arguments analyses .swift files inside current folder.

Excludes

If you want to exclude some files or folders from checking create a new .yml file and call Taylor with -ef /path/to/file argument.
Default filename is excludes.yml and its default location is the folder specified by --path flag.
The following excluding name formats can be specified:

- "/path/to/file"
- "file"
- "Folder"
- "Folder/*"
- ".*Tests.*"

Rules

These are the code quality rules currently existing:

Excessive Class Length

Number of lines in a class must not exceed given limit. Default limit = 400 lines.
Example: taylor -rc ExcessiveClassLength=100.

Excessive Method Length

Number of lines in a method must not exceed given limit. Default limit = 20 lines.
Example: taylor -rc ExcessiveMethodLength=10.

Too Many Methods

Number of methods in a class must not exceed given limit. Default limit = 10 methods.
Example: taylor -rc TooManyMethods=7.

Cyclomatic Complexity

Cyclomatic Complexity number of a method must not exceed maximal admitted value. Default = 5.
Example: taylor -rc CyclomaticComplexity=10.

Nested Block Depth

Block Depth of a method must not exceed maximal admitted value. Default = 3.
Example: taylor -rc NestedBlockDepth=7.

N-Path Complexity

N-Path Complexity of a method must not exceed maximal admitted value. Default = 100.
Example: taylor -rc NPathComplexity=50.

Excessive Parameter List

Number of parameters given to a method must not exceed maximal admitted value. Default = 3.
Example: taylor -rc ExcessiveParameterList=5.

Credits

Thanks to JP Simard for developing SourceKitten.

License

MIT Licensed.

Comments
  • Taylor Crashes

    Taylor Crashes

    When I try to run some taylor commands it crashes.

    For example at the commands taylor -rc ExcessiveMethodLength=20 or taylor following error appears:

    fatal error: Loading sourcekitd.framework/Versions/A/sourcekitd failed: file /Users/aculeva/Developer/SourceKitten/Source/SourceKittenFramework/library_wrapper.swift, line 59

    Commands like taylor -v work, though.

    I use version 0.1.3 and installed it with the .pkg file. Over Homebrew there were also some weird issues.

    question 
    opened by quiKsilverItaly 20
  • Handle erroneous arguments

    Handle erroneous arguments

    Handle the case when Taylor is invoked with invalid arguments:
    * Remove force try inside `processArguments()` that was leading to
    imminent crash and unclear error message.
    * If an invalid parameter has been sent print error message and
    prompt the user to play Pacman.
    
    opened by S2dentik 8
  • Engineering/code coverage

    Engineering/code coverage

    This PR enables code coverage status to be displayed for Taylor.I do not own Taylor so I have enabled code coverage for my fork of taylor (see the little Codecov button): https://github.com/thebugcode/Taylor

    This PR enables code coverage to be sent to codecov.io

    I have taken care of the setup details according to this guide https://github.com/codecov/example-swift/ so you only need to go to https://codecov.io/# and enable yopeso/Taylor. You can also give it PR access by clicking on the project, then settings, to get messages like the one below from coveralls (especially useful when PR's decrease the code coverage).

    The alternative to codecov.io is coveralls.io. Integration of coveralls is not as easy (http://list.her.sh/ios-test-coverage-with-coveralls/) but you can switch back and forth between the two. For example here is a PR where someone switched from coveralls to codecov: https://github.com/splinesoft/SSDataSources/commit/9ef0465ca82086ea3ca1245cc60749dabfa86f08

    opened by thebugcode 8
  • Fix getting stuck and crashing

    Fix getting stuck and crashing

    • Fix getting stuck when sending multiple requests to sourcekitd simultaneously from different threads.
    • Fix SIGABRT in SourceKitten when getting substructure.
    bug 
    opened by S2dentik 7
  • Refactor scissors

    Refactor scissors

    Changes: * Create a tree of all available components, then filter the ones actually needed. * Refactor ExtendedComponent complex areas. * appendComponents() and divideByLines() now append to a mutable array which leads to performance increase.

    opened by S2dentik 6
  • Fix coding style inconsistencies

    Fix coding style inconsistencies

    This was made by running swiftlint autocorrect with 'trailing_whitespace' rule ignored. A couple of manual changes had to be made after that (especially for 'if else' statements) .

    opened by thelvis4 5
  • Update codebase to Xcode 7.3

    Update codebase to Xcode 7.3

    SourceKitten changes:

    • Remove SwiftXPC framework dependency.
    • Make all XPCRepresentables be expressed through SourceKitRepresentable.
    • Add its own Structure.init(file: File) method.

    Sourcekit changes:

    • Closure parameters are inside closure substructure and not at the same level.
    • Implicit closure parameters are not recognized at all.

    General:

    • Update ExcludeFileReader to Xcode 7.3.
    • Remove SwiftXPC dependency.

    Code:

    • Remove all XPCRepresentables.
    • Add temporary Array component recognition which is the only way to distinguish between simple expression calls and frequently used HOFs.

    Tests:

    • Update Tokenizer tests to latest 'sourcekit' changes.
    • Update Integration Tests messages to the ones actually reported.
    • Build Quick and Nimble with Xcode 7.3.
    opened by S2dentik 4
  • Crash when trying to run

    Crash when trying to run

    Hi, I just installed Taylor via brew.

    When I try running it I get:

    Illegal instruction: 4

    In both Xcode and terminal.

    I tried to download and run the release version, but it just crashes. Any idea of what could it be?

    I'm running on a MacBook Pro with macOS HighSierra 10.13.3 With CLI Version: 9.2.0.0.1.1510905681

    opened by KioCoan 3
  • Add 'MAKE_SYMLINKS' option to Makefile

    Add 'MAKE_SYMLINKS' option to Makefile

    This option will be used to deactivate symlinks creation when make install is called from Homebrew formula. Executing ln -s in Homebrew formula breaks the sandbox.

    opened by thelvis4 3
  • Fix closure parameters bug

    Fix closure parameters bug

    Fixed the bug when closure parameters were recognized by sourcekit as simple ones and were processed by scissors as function parameters, thus leading to tooManyArguments Violation trigger. Added typeName field to ExtendedComponent, processParameters(_:) method and tests.

    opened by S2dentik 3
  • Fix number of parameters being reported incorrectly

    Fix number of parameters being reported incorrectly

    • Remove parameters that are inside the function body and are seen as function parameters. These include closure parameters that are reported as standalone by sourcekit.
    opened by S2dentik 2
  • Incorrect number of parameters

    Incorrect number of parameters

    Signing.swift:95 Method 'httpBody(parameters:encoding:)' has 4 parameters. The allowed number of parameters is 3
    
    open static func httpBody(for parameters: [String: String], encoding: String.Encoding = .utf8) -> Data? {
        let combine: (String, String) -> String = { key, value in
            return rfc3986encode(key) + "=" + rfc3986encode(value)
        }
    
        return parameters.map(combine).joined(separator: "&").data(using: encoding)
    }
    
    opened by mihai8804858 1
  • ExcessiveMethodLength counts

    ExcessiveMethodLength counts "{" and "}" as part of the function length

    If I have a method like:

    func init
    {
      let something = 1
      let another = somethingElse(start: 0,
                                    end: 1)
      let anArray = [
        "1",
        "2",
        "3"
      ]
      
      if something == 1
      {
        dosomething()
      }
    }
    

    What should be the length for this function? 5 or 14?

    My code style is that the { and } are on a line by itself for all keywords that require it, so this is causing false positives in my code. Functions that are really under 20 lines are being flagged due to brace being on a line by itself and some function calls that have their arguments stacked (as in the above).

    Also when an array literal is defined, see above, all of the lines are counted as part of the function. While the lines are part of the function, they are not individual lines. The declaration of an array is a single line that is split into multiple lines.

    Note: I would love to help out with this project. How can I help?

    opened by insha 1
  • is it possible to disable warnings for a single line/method?

    is it possible to disable warnings for a single line/method?

    I know that rules can be disabled via configuration, but I would like to disable warnings for single methods only - is this possible?

    I.e. the cyclomatic complexity-warning is annoying when a method only contains a switch-statement, therefore I would like to disable it for that method. Can this be achieved somehow?

    opened by haemi 2
  • Recognize iterating functions as `for`s when that's the case.

    Recognize iterating functions as `for`s when that's the case.

    The developer can easily write forEach or map instead of for-in statements to get rid of warnings and code smells. Taylor should be able to handle these cases appropriately.

    opened by S2dentik 0
Releases(0.2.3)
Owner
YOPESO
YOPESO GmbH
YOPESO
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

Nick Lockwood 6.3k Jan 8, 2023
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Jintin 1.6k Jan 7, 2023
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
An xcconfig (Xcode configuration) file for easily turning on a boatload of warnings in your project or its targets.

Warnings This is an xcconfig file to make it easy for you to turn on a large suite of useful warnings in your Xcode project. These warnings catch bugs

Peter Hosey 438 Nov 8, 2022
A static source code analysis tool to improve quality and reduce defects for C, C++ and Objective-C

OCLint - https://oclint.org OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code

The OCLint Static Code Analysis Tool 3.6k Dec 29, 2022
SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations.

SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations. Objective Build a stan

Andres Canal 542 Sep 17, 2022
A tool to enforce Swift style and conventions.

SwiftLint A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guid

Realm 16.9k Jan 9, 2023
Cross-platform static analyzer and linter for Swift.

Wiki • Installation • Usage • Features • Developers • License Tailor is a cross-platform static analysis and lint tool for source code written in Appl

Sleekbyte 1.4k Dec 19, 2022
Type-safe observable values and collections in Swift

GlueKit ⚠️ WARNING ⚠️ This project is in a prerelease state. There is active work going on that will result in API changes that can/will break code wh

null 361 Oct 12, 2022
Lint anything by combining the power of Swift & regular expressions.

Installation • Getting Started • Configuration • Xcode Build Script • Donation • Issues • Regex Cheat Sheet • License AnyLint Lint any project in any

Flinesoft 116 Sep 24, 2022
💊 Syntactic sugar for Swift do-try-catch

Fallback Syntactic sugar for Swift do-try-catch. At a Glance value = try fallback( try get("A"), try get("B"), try get("C"), try get("D") ) is

Suyeol Jeon 43 May 25, 2020
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

null 9 Nov 23, 2022
Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados

Via Cep iOS Sobre - Interface do Usuario - Tecnologias - Requisitos - Autor Projeto ?? FINALIZADO ?? Sobre A Aplicação consiste em fazer buscas usando

Igor Damasceno de Sousa 1 Jun 3, 2022
Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing projects.

Trackable Trackable is a simple analytics integration helper library. It’s especially designed for easy and comfortable integration with existing proj

Vojta Stavik 145 Apr 14, 2022
Makes it easier to support older versions of iOS by fixing things and adding missing methods

PSTModernizer PSTModernizer carefully applies patches to UIKit and related Apple frameworks to fix known radars with the least impact. The current set

PSPDFKit Labs 217 Aug 9, 2022
Find common xib and storyboard-related problems without running your app or writing unit tests.

IBAnalyzer Find common xib and storyboard-related problems without running your app or writing unit tests. Usage Pass a path to your project to ibanal

Arek Holko 955 Oct 15, 2022
Skredvarsel app - an iOS, iPadOS, and macOS application that provides daily avalanche warnings from the Norwegian Avalanche Warning Service API

Skredvarsel (Avalanche warning) app is an iOS, iPadOS, and macOS application that provides daily avalanche warnings from the Norwegian Avalanche Warning Service API

Jonas Follesø 8 Dec 15, 2022
Simple iOS app blackbox assessment tool. Powered by frida.re and vuejs.

Discontinued Project This project has been discontinued. Please use the new Grapefruit #74 frida@14 compatibility issues frida@14 introduces lots of b

Chaitin Tech 1.6k Dec 16, 2022