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

feat: Add ratchet-from option #41

Merged
merged 15 commits into from
May 6, 2021
Merged

feat: Add ratchet-from option #41

merged 15 commits into from
May 6, 2021

Conversation

slarse
Copy link
Collaborator

@slarse slarse commented May 3, 2021

Fix #8

This PR finally adds the ratchet functionality. In essence, by adding e.g. ratchet-from: 'origin/main' to the with-block of the configuration for buildbreaker, only the lines changed from the main branch are considered.

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2021

Codecov Report

Merging #41 (1611db3) into main (8561a6e) will increase coverage by 0.42%.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   92.71%   93.14%   +0.42%     
==========================================
  Files           6        6              
  Lines         151      175      +24     
  Branches       10       18       +8     
==========================================
+ Hits          140      163      +23     
- Misses         11       12       +1     
Impacted Files Coverage Δ
src/main.ts 92.06% <96.00%> (+1.81%) ⬆️
src/sorald.ts 89.18% <100.00%> (+0.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8561a6e...1611db3. Read the comment docs.

@slarse slarse requested a review from algomaster99 May 4, 2021 07:27
Comment on lines +64 to +65
'1854:Main.java:10:4:10:7',
'2164:Main.java:8:6:8:11'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just for context, these are the unique identifiers for the two rule violations that are contained in the changed code.

Copy link
Member

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Dropped a few comments. Rest looks good to me.


import * as git from './git';
import {ClosedRange} from './ranges';
Copy link
Member

Choose a reason for hiding this comment

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

I think line 10 will take care of this import.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a single-item import. With only line 10, I'd have to specify ranges.ClosedRange everywhere, as opposed to just ClosedRange. I don't know what's most common in TypeScript.

Copy link
Collaborator Author

@slarse slarse May 6, 2021

Choose a reason for hiding this comment

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

After looking around a bit more, there seems to be absolutely no consensus around how to do imports in TypeScript. It doesn't help that there are some 6 or so ways to do them. The only thing I can determine to be universally frowned upon is using require.

So, I'll go mostly with import * as whatever as that seems to be favored in other GHA implementations. I think we can use named imports as well when it makes sense.

Just as a side note on our discussion, I agree with avoiding * imports in Python, but that is very different from this * import. In python, import * from module imports all public top-level members of module (or everything defined in __all__) as individual objects, whereas import * as module ... in TS imports the module by some name (the closest to import module in Python that it seems to be possible to get, but really equivalent to import module as name).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It appears that combining star import with named import on a single line doesn't work. There appears to be a way to make it work with synthetic default imports, but restructuring the imports is starting to feel like a separate PR. Perhaps just defer this for later?

This is where a more structured language like Java is nice: there are standard imports, and there are static imports, and that's it :)

Copy link
Member

Choose a reason for hiding this comment

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

whereas import * as module ... in TS imports the module by some name

Yes, TS does not have a "default module name" like Python does.

Perhaps just defer this for later?

Restructuring would require a lot of thought and changes because there will be multiple export statements added and if you export something as default, you would need to decide which one. So you're right that there will be a lot of changed so you may defer this for later.

src/main.ts Show resolved Hide resolved
@@ -62,11 +84,36 @@ export async function runSorald(
return allRepairs;
}

function filterViolationSpecsByRatchet(
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to add docstrings here. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As this function isn't exported, I figured it's like "private" in TypeScript, and therefore omitted the docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to meeting: add explanatory docstring.

@slarse slarse requested a review from algomaster99 May 5, 2021 08:35
@slarse
Copy link
Collaborator Author

slarse commented May 6, 2021

@algomaster99 Ready for final review. You can see my comments on imports, I think we should just leave it for a separate PR and restructure all imports according to some format.

Right now, I'm thinking that types (e.g. ClosedRange) should be imported with named imports. That's because they typically appear in type annotations, and as you said, typing ranges.ClosedRange can make something like a function declaration much longer than it needs to be.

As for functions, I prefer using them with the qualified name (e.g. ranges.overlapsAny), as it makes it clear where they come from, and they aren't used in function headers or the like and so the added length isn't that much of a problem.

WDYT?

@algomaster99
Copy link
Member

I prefer using them with the qualified name (e.g. ranges.overlapsAny), as it makes it clear where they come from,

Keeping the conventions aside, this standalone makes sense and it indeed makes it clearer to identify where the function comes form.

can make something like a function declaration much longer than it needs to be.

But if you decide to create an instance first and then use the class methods, then this does not hold. Named export anyway sounds like a good idea. You could use default imports too but I think since it allows one to import it by any module name, the consistency might be lost if that module is used across a lot of file. For example, one file could import it as A, other B. Thus, I feel name imports will be better.

import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
jest.setTimeout(20 * 1000);
Copy link
Member

@algomaster99 algomaster99 May 6, 2021

Choose a reason for hiding this comment

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

A better alternative would be to set timeout for individual tests like given here.

@slarse , another person who thinks like us. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good find, let's do that!

Copy link
Member

Choose a reason for hiding this comment

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

If there are many tests for which would need to do this fix, you can create a separate PR for it. Up to you.

Copy link
Collaborator Author

@slarse slarse May 6, 2021

Choose a reason for hiding this comment

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

Actually, since all of the main tests require a high timeout, it's probably just a better idea to set the timeout globally. DRY :)

Copy link
Member

Choose a reason for hiding this comment

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

In that case, you can configure this in jest.config.js. Haven't looked up if it is possible but if it is, I think you should consider it.

const repairedViolations: string[] = await runSorald(
source,
soraldJarUrl,
ratchetFrom ? ratchetFrom : undefined
Copy link
Member

Choose a reason for hiding this comment

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

Is this ternary operator required? Line 115 could be a string or undefined so accordingly the value can be set here. However, if the string is '' (empty string), you may want to set it to undefined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, line 115 is lying, it can't be undefined. It's always a string (empty string if it's not defined). So I need to change that confusing type annotation.

@algomaster99
Copy link
Member

@slarse dropped my comments. Once you address them, I will mark the PR as approved. :)

@slarse
Copy link
Collaborator Author

slarse commented May 6, 2021

@algomaster99 comments addressed, merge if nothing major persists

@algomaster99 algomaster99 merged commit f3ce916 into main May 6, 2021
@algomaster99 algomaster99 deleted the issue/8-add-ratchet branch May 6, 2021 12:21
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.

Add ratcheting (gradual adoptance)
3 participants