Swiftpack.co - Package - yanagiba/swift-lint

Swift Lint

swift-ast 0.3.5 swift-lint master swift-transform pending

Travis CI Status codecov Swift 4.0 Swift Package Manager Platforms License

Swift Lint (swift-lint) is a static code analysis tool for improving quality and reducing defects by inspecting Swift code and looking for potential problems, such as possible bugs, unused code, complicated code, redundant code, code smells, bad practices, and so on.

Swift Lint relies on Swift Abstract Syntax Tree (swift-ast) of the source code for better accuracy and efficiency.

Swift Lint is part of Yanagiba Project. Yanagiba umbrella project is a toolchain of compiler modules, libraries, and utilities, written in Swift and for Swift.



A Work In Progress

Both Swift Abstract Syntax Tree and Swift Lint are in active development. Though many features are implemented, some are with limitations.

Swift Lint doesn't modify your code, therefore, the tool is safe to be deployed in production environment while we are working hard towards 1.0 release. Please be cautious with bugs, edge cases and false positives (issues and pull requests are welcomed).

Please also check out the status from swift-ast.

Requirements

Installation

Standalone Tool

To use it as a standalone tool, clone this repository to your local machine by

git clone https://github.com/yanagiba/swift-lint

Go to the repository folder, run the following command:

swift build -c release

This will generate a swift-lint executable inside .build/release folder.

Adding to swift Path (Recommended, but Optional)

It is recommended to copy the swift-lint to the same folder that your swift binary resides.

For example, if swift is installed at (Linux) or the toolchain (macOS)'s bin path is

/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Then copy swift-lint to it by

cp .build/release/swift-lint /Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-lint

Once you have done this, you can invoke swift-lint by calling swift lint in your terminal directly.

Embed Into Your Project

Add the swift-lint dependency to your Swift Package Manager (SPM) dependencies in Package.swift:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
  name: "MyPackage",
  dependencies: [
    .package(url: "https://github.com/yanagiba/swift-lint.git", from: "0.2.0")
  ],
  targets: [
    .target(name: "MyTarget", dependencies: ["SwiftMetric", "SwiftLint"]),
  ],
  swiftLanguageVersions: [4]
)

An example project will be added in the future.

Usage & Documentation

Command Line

Simply provide the file paths to swift-lint:

swift-lint path/to/Awesome.swift
swift-lint path1/to1/foo.swift path2/to2/bar.swift ... path3/to3/main.swift

CLI Options

Run swift-lint --help to get the updated command line options.

Documentation

Go to Documentation for details.

Development

Build & Run

Building the entire project can be done by simply calling:

make

This is equivalent to

swift build

The dev version of the tool will be generated to .build/debug/swift-lint.

Running Tests

Compile and run the entire tests by:

make test

Contact

Ryuichi Sai

  • http://github.com/ryuichis
  • ryuichi@yanagiba.org

License

Swift Lint is available under the Apache License 2.0. See the LICENSE file for more info.

Github

link
Stars: 9
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v0.2.1 - Aug 14, 2017

  • Use libTooling
  • Support sequence expression
  • Other dev changes and minor ones

v0.2.0 - Jun 29, 2017

  • Command line options
  • Configuration file (.yanagiba)
  • Rules (#19)
  • Reporters (#20)
  • Update documentation

v0.1.3 - Jun 17, 2017

  • Catch up Swift 4-beta and swift-ast 0.3.4
  • Metrics calculations and related rules
    • High cyclomatic complexity
    • High npath complexity
    • Nested code depth
    • Non-commenting source code statements
  • First part of rules:
    • RedundantEnumCaseStringValueRule
    • RedundantVariableDeclarationKeywordRule
    • CollapsibleIfStatementsRule
    • DoubleNegativeRule
    • InvertedLogicRule
    • ConstantConditionalOperatorConditionRule
    • ConstantGuardStatementConditionRule
    • ConstantIfStatementConditionRule
    • RedundantConditionalOperatorRule
    • RedundantIfStatementRule
    • RedundantInitializationToNilRule
    • RemoveGetForReadOnlyComputedPropertyRule
    • NoForcedTryRule
  • Doc gen binary
  • Comment-based suppression
  • Comment-based configuration
  • Exit code

v0.1.2 - Apr 26, 2017

  • Catch up Swift 3.1 and swift-ast 0.1.4 changes
  • ForceCastRule uses AST visitor

v0.1.1 - Dec 31, 2015

Initial release with project bootstrapping, and a rule to check on force cast.