-
Notifications
You must be signed in to change notification settings - Fork 14
Rule: multiple-statements-per-line
#246
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
Could you do this without the blanking by something like: find |
As far as I can tell |
While working on this further I've found something that might be a program p
implicit none
integer :: i, j
! 1st, 2nd/3rd, and 4th semicolons are superfluous
! 3rd/2nd separates the two statements
;i = 1;; j = 2;
write (*,*) i, j
end program p It doesn't like a semicolon at the start of a line or multiples grouped together. I can't see a single instance of either one of these scenarios in my limited collection of test projects, so this is a very low priority bug. |
I've added a rule Blanking all comments and strings is a very expensive operation, and as we can't have one rule return multiple kinds of violation, it has to be done twice per file if both rules are active. Benchmarking suggests this slows the code by ~7%: ❯ hyperfine -i './target/release/fortitude check --output-format=concise --preview --ignore=S081,S082 ../geos-chem'
Benchmark 1: ./target/release/fortitude check --output-format=concise --preview --ignore=S081,S082 ../geos-chem
Time (mean ± σ): 1.763 s ± 0.046 s [User: 8.042 s, System: 0.396 s]
Range (min … max): 1.684 s … 1.808 s 10 runs
Warning: Ignoring non-zero exit code.
❯ hyperfine -i './target/release/fortitude check --output-format=concise --preview ../geos-chem'
Benchmark 1: ./target/release/fortitude check --output-format=concise --preview ../geos-chem
Time (mean ± σ): 1.883 s ± 0.075 s [User: 8.973 s, System: 0.414 s]
Range (min … max): 1.761 s … 1.996 s 10 runs
Warning: Ignoring non-zero exit code.
The difference would be a lot less noticeable in a realistic IO-constrained run ( @ZedThree Would it be possible to have |
Ah, I think the issue is that "end-of-statement" is an unnamed node and done entirely through an external scanner. We could change the grammar to something like:
|
We've just released |
Fantastic, I'll try to get that going now. |
I've got it working with the new TODO:
|
let line = src | ||
.slice(TextRange::new(start_line, start_line + start_offset)) | ||
.to_string(); | ||
line.chars().take_while(|&c| c.is_whitespace()).collect() |
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 might have some fun with tabs here! (although tabs are technically not valid characters in fortran source)
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 figured tabs might be present in some codes, and hence I wrote indentation
to return a string of the current indentation level rather than a count of the number of spaces. That way it can include a mix of tabs and spaces. I think this is the safest way to handle them, but could be totally wrong on that.
On this topic, we should probably have a 'no tabs allowed' rule.
I think I'm finally there. The fixes behave strangely with regards to indentation if the user is doing anything really weird, like using multiple semicolons in a row, but should hold up in most cases. |
Fixes #64
This was a lot harder to implement than I expected!
I've left this as a draft as I'd like to add a companion rule,
superfluous-semicolon
, for a semicolon at the end of a line, and I still need to add tests.