+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_cli): correctly compute file to handle in rome ci #3453

Merged
merged 6 commits into from
Oct 24, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Oct 19, 2022

Summary

There was an issue in the rome ci command, but we couldn't see it because the MemoryFileSystem behaves differently when handling the files, compared to OsFileSystem. By default, it was accepting any kind of file and it was using the strip_prefix function. This results in two issues:

  • couldn't simulate commands like rome format . (the dot)
  • couldn't replicate 100% how the real traversal behaves

This PR tries to change that behaviour.

Test Plan

  • I added a new test case for ignoring directories, and see if it works as expected.
  • Once I added the can_handle function, the test ci_does_not_run_linter was failing, because it was wrongly computing when a file is ignored. That's fixed in the traversal.rs

@ematipico ematipico requested a review from leops as a code owner October 19, 2022 12:16
@ematipico ematipico temporarily deployed to netlify-playground October 19, 2022 12:16 Inactive
@netlify
Copy link

netlify bot commented Oct 19, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit 0b74d0b
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/635695f11849a7000817fe9b

@ematipico ematipico added this to the 10.0.0 milestone Oct 19, 2022
@ematipico ematipico temporarily deployed to netlify-playground October 19, 2022 12:16 Inactive
@ematipico ematipico added the A-CLI Area: CLI label Oct 19, 2022
@github-actions
Copy link

github-actions bot commented Oct 19, 2022

@ematipico ematipico temporarily deployed to netlify-playground October 20, 2022 10:37 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 20, 2022 10:40 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 20, 2022 10:53 Inactive
@ematipico ematipico requested a review from leops October 20, 2022 13:27
@ematipico ematipico temporarily deployed to netlify-playground October 20, 2022 13:37 Inactive
Copy link
Contributor

@leops leops left a comment

Choose a reason for hiding this comment

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

Since the traversal behavior is hard to get right perhaps we should add more test cases to verify that it works correctly in various edge cases (check that it's visiting the correct files, but also importantly not visiting the files that are not contained in the base path)

@@ -161,8 +161,21 @@ impl<'scope> TraversalScope<'scope> for MemoryTraversalScope<'scope> {
{
let files = &self.fs.files.0.read();
for path in files.keys() {
if path.strip_prefix(&base).is_ok() {
let should_process_file = if base.starts_with(".") || base.starts_with("./") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Path type has a set of is_relative / is_absolute methods to detect these cases

Copy link
Contributor Author

@ematipico ematipico Oct 21, 2022

Choose a reason for hiding this comment

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

That's not the case we are trying to get right. If we use is_relative, the paths test.js and ./ will both yield true in both cases. If we use is_absolute, it would give us false for both paths.

I updated the comment, to explain what we are doing.

@ematipico ematipico temporarily deployed to netlify-playground October 21, 2022 09:48 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 21, 2022 09:49 Inactive
@ematipico
Copy link
Contributor Author

Since the traversal behavior is hard to get right perhaps we should add more test cases to verify that it works correctly in various edge cases (check that it's visiting the correct files, but also importantly not visiting the files that are not contained in the base path)

I added another test to see if that works.

@ematipico ematipico requested a review from leops October 21, 2022 09:50
@ematipico ematipico temporarily deployed to netlify-playground October 21, 2022 15:35 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 24, 2022 08:50 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 24, 2022 13:00 Inactive
@ematipico ematipico temporarily deployed to netlify-playground October 24, 2022 13:41 Inactive
@ematipico ematipico merged commit 254f613 into main Oct 24, 2022
@ematipico ematipico deleted the fix/ci-command branch October 24, 2022 14:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-CLI Area: CLI
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载