-
Notifications
You must be signed in to change notification settings - Fork 1k
A linter to continuously check code quality in CI #4278
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
Conversation
|
In languageserver, we use xmlparsedata to convert the parsed data to XML tree to analyze the code. Maybe it'll help here somehow? |
7f420f9 to
b5ea92c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4278 +/- ##
=======================================
Coverage 97.46% 97.46%
=======================================
Files 80 80
Lines 14822 14822
=======================================
Hits 14447 14447
Misses 375 375 ☔ View full report in Codecov by Sentry. |
inst/tests/tests.Rraw
Outdated
| brackify = data.table:::brackify | ||
| chmatchdup = data.table:::chmatchdup | ||
| compactprint = data.table:::compactprint | ||
| CsubsetDT = data.table:::CsubsetDT |
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.
and this is caused by what?
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'm not quite sure the point of it, but if we're blocking it in the source we may as well block it in tests:
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.
make sense.
fyi @mattdowle
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.
BTW IIUC this test is related to making sure we're using the C API correctly. If we're not registering our routines "properly" we'd have to refer to them as a string, and use package in the .Call call, I think the way we're doing it using dyn.load adds it to the symbol table so we can refer by symbol which is preferred. So the quotation check is about registering routines.
inst/tests/tests.Rraw
Outdated
| test(458, DT[,sum(v),by=list(a%%2L)], data.table(a=c(1L,0L),V1=c(26L,13L))) | ||
| test(459, DT[, list(sum(v)), list(ifelse(a == 2, NA, 1L))], data.table(ifelse=c(1L,NA_integer_),V1=c(26L,13L))) | ||
| test(460, DT[, list(sum(v)), list(ifelse(a == 2, 1, NA))], data.table(ifelse=c(NA_real_,1),V1=c(26L,13L))) | ||
| test(459, DT[, list(sum(v)), list(fifelse(a == 2L, NA_integer_, 1L))], data.table(fifelse=c(1L,NA_integer_),V1=c(26L,13L))) |
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 we should leave ifelse and not replace it with fifelse, better to test against base R than our functions.
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 do have a test (2085.33) matching fifelse to ifelse, I figured that is good enough. We could also add a few more tests of consistency of fifelse & ifelse...
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.
Testing fifelse is a different thing. We do test grouping by same order, not fifelse really. I is fine to use fifelse here, but we should not remove every ifelse in favour of fifelse. I would remove ifelse checks from linter.
|
Really liking @renkun-ken's suggestion now that I'm quite comfortable working with XML versions of the parse trees from some work with |
|
@MichaelChirico Yes, exactly. The XML versions of the parse trees are much easier to work with. |
8a2a333 to
63632e6
Compare
|
@renkun-ken added you as a reviewer since you're already familiar with @jangorecki where do you think the right place is to insert this to the CI pipeline? Output of the current set of linters as of now: |
|
For something like |
|
I like this approach to lint package with customized rules and I tried it and it works quite well.
Yes, this might be the simplest way to allow |
|
nolint sounds ok, but in case of a line starting with comment sign we could make skip that somehow and nolint every line like this? |
|
@jangorecki not sure I follow
in XML parse tree, comments are given their own nodes, so they wouldn't be caught by any linter unless we targeted comments specificaly. See gives XML tree |
|
Just don't try to fix what linter is saying as we will ended up having many new conflicts |
Ah, too late. FWIW I kept it "minimal" and focused on low-volume/trivial fixes. How to proceed? (1) Split off all non-CI changes to separate PR(s) (2) Split off all R/* changes (3) Some more intermediate option (4) Merge as-is (after review) |
|
Let's clear out PR queue in 1.15.99 and come back to this after |
|
Closing this draft, we can add incremental PRs easily going forward. Track future work in #4190 |
Closes #4190
TODO:
gsub/grep/etc calls that can usefixed=TRUEpastecalls usingsep=""=for assignment=in function callsif:if (condition) {&&/||where possiblepaste(x, collapse=',')in favor ofbrackify(x)any(is.na())/any(is.duplicated())any(!x)->!all(x),all(!x)->!any(x)stop()/warning()/message()-->stopf()/warningf()/messagef()test(SYMBOL, ...)ortest(SYMBOL + ....)linted (see Changes to ensure test(number instead of test(name #6041 for lint logic)# nolintlogicgreps ofsrc(still as regex, from R)++iinstead ofi++in all loops