Giter VIP home page Giter VIP logo

swift-scripts's Introduction

Unused

unused.rb Searches for unused swift functions, and variable at specified path

Usage

cd <path-to-the-project>
<path-to-unused.sh>/unused.rb 

Output

 Item< func loadWebViewTos [private] from:File.swift:23:0>
Total items to be checked 4276
Total unique items to be checked 1697
Starting searching globally it can take a while
 Item< func applicationHasUnitTestTargetInjected [] from:AnotherFile.swift:31:0>
 Item< func getSelectedIds [] from: AnotherFile.swift:82:0>

Xcode integration

In order to integrate this to Xcode just add Custom Build Phase/Run Script
~/Projects/swift-scripts/unused.rb xcode

Known issues:

  • Fully text search (no fancy stuff)
  • A lot of false-positives (protocols, functions, objc interoop, System delegate methods)
  • A lot of false-negatives (text search, yep)

swift-scripts's People

Contributors

niklasarnitz avatar paultaykalo avatar wata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-scripts's Issues

Make output in xcode compatible format

Although there are many false-positives, it would still be useful to produce warnings that can be picked up by xcode (if run for example as part of build phase). This way it is easier to process warnings.

Filter out methods of Cocoa protocols

False positives reported for Cocoa protocols may be explicitly filtered out. Either common used protocols may be collected, or search in SDK may be performed.

Enum documentation comment is parsed for class definitions

I have the following code:

    /// When the URLSessionTask is complete the validateCompletion() function will return one of these values
    /// to indicate to APIDispatcher how it should proceed
    enum CompletionValidation {
        case completionValidated    /// Indicates to APIDispatcher that the last response you received is valid, and it should consider this request complete
        case rejectedIsRetriable    /// Indicates to APIDispatcher that your class implements APIRetriableRequestCompatible and the last received response was invalid. APIDispatcher will confirm the re-attempt and cooldown interval using the shouldReattempt function
        case rejectedDontRetry      /// Indicates to APIDispatcher that the last response you received was invalid, it should not attempt a retry and it should stop processing the request
    }

Unused.rb complains that "class implements is unused". This refers to the comment of the rejectedIsRetriable enum in which you can find the word "class". This is obviously not a class definition syntax.

It would be nice to have a way to disable false-positives

The script is currently very useful since its well maintained, does the job and is extremely simple to integrate.

You could add this to the installation
1- Place the file inside your project folder directory
2- Call it via $SRCROOT/unused.rb xcode

Given that there are a lot of false positives like mentioning the word protocol in a comment or others, it would be nice to have a way like swift-lint to disable specific warnings.

ex unused-disable-this which would disable the warning on the specific line
unused-disable-all which would disable warnings for all the class

What do you think about it ?

Awesome project btw

Should ignore PreviewProvider/*_Previews-structs

In SwiftUI you'll use files named something like OnboardingView_Previews using the PreviewProvider-protocol to create previews. Unused.rb reports them as unused, which is somewhat correct, but they are used by the developers to see what they're coding.

False positive for public modifiers inside a framework

Maybe the script can have a mode for scanning a framework VS an app, because for many of the properties and functions of a framework class whose access modifiers are public, the script is reporting false positive since those properties and functions are most likely not referenced inside the framework.

Item is unused when it's followed by a comment

The script detects an unused item when I return the result of a function with a comment at the same line:

Here an example:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return getCell() // Bla bla bla
}

Move all `private (set)` variables to `non_private_items`.

Hi Paul, I'd like feedback on the following change as well as permissions to PR if possible.

Currently in Master

non_private_items, private_items = file_items.partition {  |f|
    !f.modifiers.include?("private") 
        && !f.modifiers.include?("fileprivate") 
}

Proposed Change

private_items, non_private_items = file_items.partition { |f|
    (
        f.modifiers.include?("private")
            && !f.modifiers.include?("(set)")
    ) || (
            f.modifiers.include?("fileprivate")
    )
}

Basically I want to make sure to only count private items if they don't contain (set).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.