-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
'1854:Main.java:10:4:10:7', | ||
'2164:Main.java:8:6:8:11' |
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.
Just for context, these are the unique identifiers for the two rule violations that are contained in the changed code.
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.
Dropped a few comments. Rest looks good to me.
|
||
import * as git from './git'; | ||
import {ClosedRange} from './ranges'; |
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 think line 10 will take care of this import.
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.
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.
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.
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
).
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.
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 :)
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.
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.
@@ -62,11 +84,36 @@ export async function runSorald( | |||
return allRepairs; | |||
} | |||
|
|||
function filterViolationSpecsByRatchet( |
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 forgot to add docstrings here. :)
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.
As this function isn't exported, I figured it's like "private" in TypeScript, and therefore omitted the docstring.
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.
According to meeting: add explanatory docstring.
@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. As for functions, I prefer using them with the qualified name (e.g. WDYT? |
Keeping the conventions aside, this standalone makes sense and it indeed makes it clearer to identify where the function comes form.
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 |
import * as process from 'process' | ||
import * as cp from 'child_process' | ||
import * as path from 'path' | ||
jest.setTimeout(20 * 1000); |
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 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.
Good find, let's do that!
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.
If there are many tests for which would need to do this fix, you can create a separate PR for it. Up to you.
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.
Actually, since all of the main tests require a high timeout, it's probably just a better idea to set the timeout globally. DRY :)
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.
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 |
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.
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
.
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.
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.
@slarse dropped my comments. Once you address them, I will mark the PR as approved. :) |
@algomaster99 comments addressed, merge if nothing major persists |
Fix #8
This PR finally adds the ratchet functionality. In essence, by adding e.g.
ratchet-from: 'origin/main'
to thewith
-block of the configuration for buildbreaker, only the lines changed from the main branch are considered.