-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add reuse_identifier rule and test. #137
Add reuse_identifier rule and test. #137
Conversation
// Currently only supported TableViewCell and CollectionViewCell (contains UICollectionReusableView) | ||
if let tableView = view as? TableView { | ||
return tableView.prototypeCells?.compactMap { | ||
guard let customClass = $0.customClass, let reuseIdentifier = $0.reuseIdentifier else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a IBReusable
protocol implemented by the two type of cells
maybe it could help to factorise some code
So you can extract a function or append list of cells into one before using compactMap
Or we could also add a protocol on TableView
and CollectionView
to provide the reusableCells
of type IBReusable
, so only one if let parentResuable = view as? IBReusableParentView {
is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phimage Thanks for your feedback. I'll try that pattern to aggregate logic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the way, that view types are defined in IBDecodable. Should I modify that project first or add extension it from IBLinter project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, firstly I try to append list of cell pattern without modify IBDecodable project.
@kateinoigakukun @phimage okey, i finish up implementation for NOTE: I added some mess commits for this PR, so please squash merge to clean up git history when you merge or I'll rebase before or after review if you want. looks like CI is not running, this is test result in my local. `swift test` result
|
} else if let collectionView = view as? CollectionView, let cells = collectionView.cells { | ||
reusableCells += cells | ||
} else if let cell = view as? IBReusable & ViewProtocol { | ||
reusableCells += [cell] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very special case :)
ok because cells are not in TableView
or CollectionView
subviews
it seems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I estimate this else if
case is for XIB that defined TableViewCell
or CollectionVIewCell
without parent of TableView
and CollectionView
.
That type of xib is added as test resource.
Rules.md
Outdated
| Default Rule | `false` | | ||
|
||
Check that Reuse Identifier same as view class name. | ||
Currently only supported TableViewCell and CollectionViewCell. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
back-ticks on TableViewCell
and CollectionViewCell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
| Default Rule | `false` | | ||
|
||
Check that Reuse Identifier same as view class name. | ||
Currently only supported `TableViewCell` and `CollectionViewCell`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for confusion. This file is generated automatically based on Rule
protocol information. Could you add second line description to ReuseIdentifierRule.description
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i'll do it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems legit except for nits point 👍
|
||
static let identifier = "reuse_identifier" | ||
static let description = """ | ||
Check that ReuseIdentifier same as class name.\\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing two space to line break for markdown is not good i think because Xcode have Automatically trim trailing whitespace
option that trim space for line break.
So i choose back-tick style line break for markdown.
Great thanks! LGTM |
thanks a lot! |
Hi
I just try to implement
reuse_identifier
rule, how about this rule?If acceptable, I'll continue to add xib support and docs for it.
Closes #136