Skip to content

Commit

Permalink
Merge pull request #7 from devSC/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
ijoshsmith committed Dec 7, 2017
2 parents 7770dc1 + de0a18e commit 8aa4cd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions AbandonedStrings/main.swift
Expand Up @@ -45,7 +45,7 @@ func contentsOfFile(_ filePath: String) -> String {
}

func concatenateAllSourceCodeIn(_ directories: [String], withStoryboard: Bool) -> String {
var extensions = ["h", "m", "swift"]
var extensions = ["h", "m", "swift", "jsbundle"]
if withStoryboard {
extensions.append("storyboard")
}
Expand All @@ -68,11 +68,11 @@ func extractStringIdentifiersFrom(_ stringsFile: String) -> [String] {
}

func extractStringIdentifierFromTrimmedLine(_ line: String) -> String {
let indexAfterFirstQuote = line.characters.index(after: line.startIndex)
let lineWithoutFirstQuote = line.substring(from: indexAfterFirstQuote)
let endIndex = lineWithoutFirstQuote.characters.index(of:"\"")
let identifier = lineWithoutFirstQuote.substring(to: endIndex!)
return identifier
let indexAfterFirstQuote = line.index(after: line.startIndex)
let lineWithoutFirstQuote = line[indexAfterFirstQuote...]
let endIndex = lineWithoutFirstQuote.index(of:"\"")!
let identifier = lineWithoutFirstQuote[..<endIndex]
return String(identifier)
}

// MARK: - Abandoned identifier detection
Expand All @@ -81,7 +81,9 @@ func findStringIdentifiersIn(_ stringsFile: String, abandonedBySourceCode source
return extractStringIdentifiersFrom(stringsFile).filter { identifier in
let quotedIdentifier = "\"\(identifier)\""
let quotedIdentifierForStoryboard = "\"@\(identifier)\""
let isAbandoned = (sourceCode.contains(quotedIdentifier) == false && sourceCode.contains(quotedIdentifierForStoryboard) == false)
let signalQuotedIdentifierForJs = "'\(identifier)'"
let isAbandoned = (sourceCode.contains(quotedIdentifier) == false && sourceCode.contains(quotedIdentifierForStoryboard) == false &&
sourceCode.contains(signalQuotedIdentifierForJs) == false)
return isAbandoned
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@ If a `.strings` file contains…

`"some_string_identifier"`

…is not found in any of the source code files (namely, files with a `.h`, `.m`, or `.swift` extension).
…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.
Expand Down

0 comments on commit 8aa4cd8

Please sign in to comment.