mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.49k stars 760 forks source link

Generate warnings when not using R.swift in code where you should #30

Open mac-cain13 opened 9 years ago

mac-cain13 commented 9 years ago

We should be able to do this by outputting something like this: /path/to/file.swift:123: warning: This is the warning message

I'm wondering if we also could give an "auto-fix" suggestion.

mac-cain13 commented 9 years ago

Should be possible now I found this: fix-it:"t.cpp":{7:25-7:29}:"Gamma"

Source; http://clang.llvm.org/docs/UsersManual.html under -fdiagnostics-parseable-fixits

mac-cain13 commented 9 years ago

Hmm, looks like XCode is not parsing any of the clang fix-it formats for custom scripts. :(

mac-cain13 commented 9 years ago

This will be quite hard until we can easily parse the correct source files into an AST and use that to look at your source. The idea would be more suited for a plugin in a Swift linter. Let's put it out of scope for now.

mac-cain13 commented 8 years ago

Should take a look at SourceKitten might be possible to use it to do this! :)

foobra commented 8 years ago

why not check SwiftLint , they use regex to parse code and generate warnings

mac-cain13 commented 8 years ago

Yeah, good point a set of SwiftLint rules could do this probably. :)

Tvede-dk commented 7 years ago

Another suggestion; To add a source editor extension to potentially find theses in the current document, and possibly try to generate / convert the vanilla way to R.swift. However as they are quite limited in ability, it will require some manual work for the "end user".

RishabhTayal commented 7 years ago

I am using swiftlint. How could we write a regex to enforce the R.swift?

RishabhTayal commented 7 years ago

I was finally able to write a custom rule for swiftlint to enforce use of R.swift in my project. Let me know if I could help with the integration somehow.

mac-cain13 commented 7 years ago

If you could share it that could be a starting point for implementing this feature. I'm also curious what the regex looks out for and what cases you cover.

RishabhTayal commented 7 years ago

Here are the rules I am using. Maybe this is not the best way to do it. But it is working for me.

custom_rules:
  uiimage:
      included: ".*.swift"
      name: "UIImage Hardcoded"
      regex: UIImage\(named:\ ?\"(.*)\"\)
      message: "Hardcoded UIImage strings are not allowed."
      severity: error
  uistoryboard:
    included: ".*.swift"
    name: "UIStoryboard Hardcoded"
    regex: UIStoryboard\(name:\ ?\"(.*)\"\)
    message: "Hardcoded UIStoryboard strings are not allowed."
    severity: error
  uinib:
    included: ".*.swift"
    name: "UINib Hardcoded"
    regex: \(nibName:\ ?\"(.*)\"\)
    message: "Hardcoded UINib strings are not allowed."
    severity: error
  uistoryboardsegue:
    included: ".*.swift"
    name: "UIStoryboardSegue Hardcoded"
    regex: performSegue\(withIdentifier:\ ?\"(.*)\"\)
    message: "Hardcoded UIStoryboardSegue strings are not allowed."
    severity: error
RishabhTayal commented 7 years ago

There are few cases we need to cover here. Let me know if you want regex for those as well. Currently I don't have those rules but I can create them for you.

Robuske commented 6 years ago

Any update on this or has it been abandoned?

mac-cain13 commented 6 years ago

It has not been abandoned, but also no active work on this feature at the moment.