Coder Social home page Coder Social logo

abandoned-strings's Introduction

Abandoned Resource String Detection

This command line program detects unused resource strings in an iOS or OS X application.

Updated to Swift 3, thanks to @astaeck on Oct-17-2016

Usage

Open a Terminal to the directory which contains the AbandonedStrings executable, and run the following command:

$ ./AbandonedStrings /Users/your-username/path/to/source/code

What to expect

If a .strings file contains…

"some_string_identifier" = "Some Display Text";

…this program will consider that resource string to be abandoned if…

"some_string_identifier"

…is not found in any of the source code files (namely, files with a .h, .m, .swift or .jsbundle extension).

More details

This program searches through the source code files in an iOS app project, looking for resource strings (in a .strings file) whose identifiers are not referenced by the application's source code.

The search logic does not take into account if code is commented out, so it won't be as reliable if your application has a lot of commented-out code.

It also does not try to determine the context in which string identifiers are used, such as whether or not the string is being used to look up a localized string value or if it just happens to match a resource string identifier by coincidence.

Also, this program is ineffective if resource string identifiers are referenced via constants or dynamically constructed.

Disclaimer

As noted above, this program uses a simple heuristic and is not guaranteed to produce perfect results for every codebase.

abandoned-strings's People

Contributors

devsc avatar hlung avatar ijoshsmith avatar sterlingwes avatar xaphod 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

abandoned-strings's Issues

String(contentsOfFile: filePath) failed : couldn’t be opened because you don’t have permission to view it.

Searching for abandoned resource strings…
cannot read file!!! : Error Domain=NSCocoaErrorDomain Code=257 "The file “xxxx” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Users/myname/Documents/MyProject/Pods/xxxxxx.swift, NSUnderlyingError=0x7f8afd9f3e10 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}

I tryid every thing I could think of :
chmod X on AbandonString.swift
chmod -R 777 on project folder
and execute command with "sudo"

🤷‍♂️

Thanks for help.

No results when '.strings' files are not UTF8 encoded

Don't know if you've had this problem, but I got no results running abandoned-strings on my source. Turned out it was thecontentsOfFile method failing due to the encoding of the .strings files not being UTF8 encoded.
I changed the method thusly to fix it.

func contentsOfFile(filePath: String) -> String {
    do {
        let usedEncoding = UnsafeMutablePointer<NSStringEncoding>()
        return try String(contentsOfFile: filePath, usedEncoding: usedEncoding)
    }
    catch { return "" }
}

Can't run with `./AbandonedStrings <project-folder-path>`

I Can't run with ./AbandonedStrings <project-folder-path>.
I need to use ./AbandonedStrings/main.swift <project-folder-path> instead, with chmod to add execution permission. May be we can update the README to better capture this issue.

Crash due to force unwrapping

Seeing quite a few crashes here: let endIndex = lineWithoutFirstQuote.index(of:"\"")!

It would be best to remove all force unwrapping and make functions like extractStringIdentifierFromTrimmedLine return optional strings.

Use stdout and stderr for output

Right now project isn't writing to stdout and stderr so this won't work:

./AbandonedStrings /path/to/project > outputfile.txt

Executable file doesn't execute

When i try to execute the command line in terminal knowing that im in the directory, help me plz i need this tool.
-bash: ./AbandonedStrings: is a directory

utf16

Been trying to hand prune our localization files, but they have over 2k strings from over seven years. Tried this out and it didn't find anything abandoned.

Turns out contentsOfFile is reading the strings file using utf8 encoding and our files are utf16. This causes the try to fail and an empty string returned instead of file contents.

Found something mentioned on SO that as of 2016 Apple is using utf8, but a new localization I created yesterday is utf16 as well.

Maybe consider a warning in contentsOfFile catch?

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.