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
Adds FilesLinter that makes sure all required files are available #6069
base: main
Are you sure you want to change the base?
Conversation
I wonder
|
I don't think we should blindly suppress warnings, but rather allow suppressing a specific instance of it. |
@danieleformichelli okay, then how do we identify or specify which warnings a developer would want to suppress? what I mean by that is do we separate the types of warnings within tuist into different domains and then run it somewhat like this |
For this specific case, I think it should be a target property whether to ignore if it has ick m invalid sources or not |
Wouldn't that go against why we would want to add suppress the warnings? For example, on local development machines we would want to suppress warnings, but not on the CI. |
When have we decided that it was the why? :) My PoV is that ususally it's a good warning. There might be some cases (like the template mentioned in the issue) where it might be annoying, hence we should allow to disable it only for targets created from that template |
Sounds good, i'll move this discussion into slack later today! thanks for your input |
5dda4a9
to
979cf0b
Compare
796e917
to
59db266
Compare
fixtures/ios_app_with_framework_and_missing_resources/App/Config/App-Info.plist
Outdated
Show resolved
Hide resolved
30d7b15
to
a2f8682
Compare
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.
Thanks a lot for the PR! However, I think we should move the linting from the loading phase to the generation phase instead to align with other linters we already have in the codebase.
if !path.pathString.isGlobComponent { | ||
// FIXME: This should be done in a linter. | ||
logger.warning("No files found at: \(path.pathString)") | ||
} |
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.
Why have we not moved this to the new linter?
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.
Code wise this just needs to be removed, the linter already does this
|
||
@testable import TuistLoader | ||
|
||
class FilesLinterTests: XCTestCase { |
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.
class FilesLinterTests: XCTestCase { | |
final class FilesLinterTests: XCTestCase { |
func lint(project: LoadedWorkspace, convertedProjects: [TuistGraph.Project]) -> [LintingIssue] | ||
} | ||
|
||
public class FilesLinter: FilesLinting { |
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.
public class FilesLinter: FilesLinting { | |
public final class FilesLinter: FilesLinting { |
let results = subject.lint(project: workspace, convertedProjects: [graphProject]) | ||
|
||
// Then | ||
XCTAssertTrue(results.contains(LintingIssue( |
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.
You can use XCTContainsLintingIssue
I would also assert the number of issues
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.
Can we also test that a glob for which no files exist does not throw a warning?
let filesLintingIssues = filesLinter.lint( | ||
project: allManifests, | ||
convertedProjects: projectsModels | ||
) | ||
filesLintingIssues.printWarningsIfNeeded() |
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.
Why is this linted here and not along with all the other linters we have here? This could probably be added as a TargetLinter. I don't really see a reason why this needs to be linted during the load phase.
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.
Yeah, so i tried to looking into that, however it seems that we cant really put it there since we require the allManifests
and that's being fetched within the same function. and the linter itself compares the paths between, the generated targets from the allManifests
to the actual allManifests
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.
Or do you think there is a better option there @fortmarek?
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.
Considering the need "I need linters to know whether a file has been derived from a glob", you need:
- A way to express that
- Use that information from the linters that @fortmarek pointed out.
We already have a module that represents a path. You can extend it to include information about whether it came from a glob:
public enum FileElement: Equatable, Hashable, Codable {
case file(path: AbsolutePath, metadata: Set<FileElementMetadata>)
case folderReference(path: AbsolutePath, metadata: Set<FileElementMetadata>)
}
// Somewhere in the mapping logic.
FileElement.path("....", metadata: [.fromGlob])
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.
Okay nice then, I'll take a look at it and see if that's going to work as expected
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've been wondering, do we need the extra metadata? If we decide that we won't show any warnings when no files match a glob but we still want to show a warning for individual files, can't we only lint the individual files exist? As we don't add the parent glob directory if the glob doesn't match anything.
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.
can't we only lint the individual files exist?
That's the idea, but how do you know at the linter level if a file or not was hardcoded by the user or resolved from a glob without passing that information when the models are mapped from ProjectDescription
to TuistGraph
?
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.
When we resolve a glob, we then pass on only files that the file system can find. How would a non-existing file from a glob be added as a regular file?
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'll resume the work on this weekend, or the weekend after. I've been super busy lately.
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.
Hey, If possible, I would love to get some feedback regarding the approach that was taken before adding tests and basically moving forward with this PR.
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.
Thanks a lot for taking the lead here @mustiikhalil. I think we should move this to the existing linters, and make any necessary changes to allow that solution.
c9547a7
to
adc7d4b
Compare
if target.supportsResources { | ||
let files = target.copyFiles.flatMap(\.files) | ||
|
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.
We can lint based on glob, and folder reference too, but for now I made it simple for the sake of reviewing it
public var sourcesPaths: [AbsolutePath] | ||
public var resources: ResourceFileElements | ||
public var resourcesPaths: [AbsolutePath] | ||
public var copyFiles: [CopyFilesAction] | ||
public var copyFilesPaths: [AbsolutePath] |
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.
Do we actually need to track these paths in extra properties? Can't we lint that the files added do exist based on directly the sources
, resources
, and copyFiles
properties?
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.
Well, i tried to make it work but couldnt since we kinda need to find a point of reference. For example, /app/sources/text.swift
will not show up in the sources
if its not within the directory. So we kinda need to store the paths to compare them later on in the linter.
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 should be a place where we skip adding files to sources
when they don't exist. Maybe we can try including them? Would be interesting to see what happens as that should be a valid operation in Xcode.
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.
@fortmarek so I updated the code to remove all of those and simply just allow tuist to append all the files into Xcode. And then use the TargetLinter to display if there are any missing folders or files.
If this is the way to progress, I will add the tests and finalize the code for it
adc7d4b
to
1a1f041
Compare
@fortmarek if you have time to review it so we can move forward towards getting this PR merged. |
Creates a file linter that check if all non-glob Files within the targets are available within the generated targets and project Moves File validation into the TargetLinter as discussed
Short description 📝
Adds FilesLinter that makes sure that all non-glob files would would present warnings
Resolves #5552
How to test the changes locally 🧐
The command should be useable through out the entire project, however to test this following the steps below would be the best approach:
fixtures
that's missing resources, or sources.tuist generate --no-open
should flush a lot of warnings which is to be expectedOutput
tuist generate --no-open
should flush non-glob warnings as shown belowOutput
Contributor checklist ✅
mise run lint:fix
Reviewer checklist ✅
changelog:added
,changelog:fixed
, orchangelog:changed
, and the title is usable as a changelog entry