Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic paths #135

Merged
merged 5 commits into from
Feb 6, 2022

Conversation

jml5qh
Copy link
Contributor

@jml5qh jml5qh commented Dec 24, 2019

The use case for this new flag is to only lint the files that have changed. This could help in larger projects where linting all xib/storyboard files could take a good amount of time. This is also a feature present in other linters like SwiftLint and xiblint.

@jml5qh
Copy link
Contributor Author

jml5qh commented Dec 24, 2019

@kateinoigakukun @giginet - I'm not too familiar with the Github PR UI and can't figure out how to add you as reviewers. I also ran the build checks / tests in my fork (https://github.com/jml5qh/IBLinter/commit/04cbce1455fbcbb860a26aa97dc7b062b696af65/checks?check_suite_id=373173148), but I'm not sure how to get that result added to this PR.

@@ -37,7 +37,7 @@ extension Rules {
let violation: [Violation] = {
guard let baseClassesForElement = baseClasses[view.elementClass] else { return [] }
guard let customClass = view.customClass else {
let message = "CustomClass is not set to \(viewName(of: view))"
let message = "You must use a subclass of \(viewName(of: view))"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also make this part into a separate PR if you prefer. I was a little confused when I ran the linter and saw this error since it says something like "CustomClass is not set to UILabel" even though we actually want the developer to set the custom class to something other than UILabel. Open to suggestions / improvements!

Copy link
Member

@phimage phimage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show me the equivalent code on swiftlint, with same option name?

@@ -26,11 +26,14 @@ struct ValidateCommand: CommandProtocol {
fatalError("\(workDirectoryString) is not directory.")
}

let config = Config(options: options) ?? Config.default
var config = Config(options: options) ?? Config.default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is possible to do all the job in constructor and keep let keyword

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to make that work since the included property actually gets set in the init(from decoder: Decoder) method which is automatically called via the YAMLDecoder object. Let me know if you have any ideas and I can give it a try!

if config.disableWhileBuildingForIB &&
ProcessInfo.processInfo.compiledForInterfaceBuilder {
return .success(())
}
if config.included.isEmpty {
config.included = options.included
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because all you do is modified config object from information defined by options

Sources/IBLinterFrontend/Commands/ValidateCommand.swift Outdated Show resolved Hide resolved
Sources/IBLinterFrontend/Commands/ValidateCommand.swift Outdated Show resolved Hide resolved
Sources/IBLinterFrontend/Commands/ValidateCommand.swift Outdated Show resolved Hide resolved
@jml5qh
Copy link
Contributor Author

jml5qh commented Dec 27, 2019

Could you show me the equivalent code on swiftlint, with same option name?

SwiftLint has a --path Option that you can use for one file (https://github.com/realm/SwiftLint/blob/master/Source/swiftlint/Commands/LintCommand.swift#L43) and then also a non-named Argument that you can use for multiple files (https://github.com/realm/SwiftLint/blob/master/Source/swiftlint/Commands/LintCommand.swift#L67). I first tried the Argument approach, but had issues with file paths with spaces.

@phimage
Copy link
Member

phimage commented Dec 28, 2019

We have a --path option already but maybe you cannot specify a file, only directory
(and then it could do change how to find config file)

It will be better if we could work like swiftlint
maybe the paths argument as you mentionned
https://github.com/realm/SwiftLint/blob/c7c0ac838b8acd59f4082e913a014a3989fe042e/Source/swiftlint/Helpers/CommonOptions.swift#L10

@jml5qh
Copy link
Contributor Author

jml5qh commented Dec 28, 2019

We have a --path option already but maybe you cannot specify a file, only directory
(and then it could do change how to find config file)

It will be better if we could work like swiftlint
maybe the paths argument as you mentionned
https://github.com/realm/SwiftLint/blob/c7c0ac838b8acd59f4082e913a014a3989fe042e/Source/swiftlint/Helpers/CommonOptions.swift#L10

I've never been able to get the pathsArgument to work with file paths that have spaces in them. For example, in our app we have something like: /TV App/TV.storyboard. The Commandant Argument splits this path into two strings, even when trying to escape the parameters - ["TV", "App/TV.storyboard"].

@kateinoigakukun
Copy link
Collaborator

I basically prefer to use arguments instead of option to specify files.

I've never been able to get the pathsArgument to work with file paths that have spaces in them. For example, in our app we have something like: /TV App/TV.storyboard. The Commandant Argument splits this path into two strings, even when trying to escape the parameters - ["TV", "App/TV.storyboard"].

@jml5qh I think it's not Commandant issue, you can pass path including space if you surround it with " or escape the space with \.

@kateinoigakukun kateinoigakukun linked an issue Feb 22, 2020 that may be closed by this pull request
@jml5qh
Copy link
Contributor Author

jml5qh commented Feb 24, 2020

I basically prefer to use arguments instead of option to specify files.

I've never been able to get the pathsArgument to work with file paths that have spaces in them. For example, in our app we have something like: /TV App/TV.storyboard. The Commandant Argument splits this path into two strings, even when trying to escape the parameters - ["TV", "App/TV.storyboard"].

@jml5qh I think it's not Commandant issue, you can pass path including space if you surround it with " or escape the space with \.

Ah you're exactly right - just switched it to use arguments.

@jml5qh
Copy link
Contributor Author

jml5qh commented Apr 23, 2020

@kateinoigakukun @phimage - Any other changes you'd like to see before this PR can get merged? Our team would love to start using IBLinter but are holding off until we can use this change.

@kateinoigakukun kateinoigakukun merged commit 3dfaabd into IBDecodable:master Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamically specify the files to lint
4 participants