Open mac-cain13 opened 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
Hmm, looks like XCode is not parsing any of the clang fix-it formats for custom scripts. :(
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.
Should take a look at SourceKitten might be possible to use it to do this! :)
why not check SwiftLint , they use regex to parse code and generate warnings
Yeah, good point a set of SwiftLint rules could do this probably. :)
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".
I am using swiftlint
. How could we write a regex to enforce the R.swift
?
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.
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.
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
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.
Any update on this or has it been abandoned?
It has not been abandoned, but also no active work on this feature at the moment.
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.