Skip to content

Conversation

@wilzbach
Copy link
Contributor

follow-up to #4239. Here's a simple setup with Travis.
Obviously a lot of stuff fails (= Phobos doesn't stick to it's own style), but I argue that we should fix this and then enable this bot to help submitters.

Using DScanner allows us to check for a couple of goodies:

  • Check for array literals that cause unnecessary allocation
  • Check for poor exception handling practices
  • Check for use of the deprecated 'delete' keyword
  • Check for use of the deprecated floating point operators
  • Check number literals for readability
  • Checks that opEquals, opCmp, toHash, and toString are either const, immutable or inout.
  • Checks for .. expressions where the left side is larger than the right.
  • Checks for if statements whose 'then' block is the same as the 'else' block
  • Checks for some problems with constructors
  • Checks for unused variables and function parameters
  • Checks for unused labels
  • Checks for duplicate attributes
  • Checks that opEquals and toHash are both defined or neither are defined
  • Checks for methods or properties whose names conflict with built-in properties
  • Checks for confusing code in inline asm statements
  • Checks for undocumented public declarations_
  • Checks for poor placement of function attributes
  • Checks for use of the comma operator
  • Checks for redundant expressions in if statements
  • Checks for redundant parenthesis
  • Checks for lines longer than 120 characters
  • Checks for assignment to auto-ref function parameters
  • Checks for incorrect infinite range definitions
  • Checks for asserts that are always true

Ping @Hackerpilot.

For mir we already had to disable a couple of flags due to bugs or coding practices (thus they are not listed here) and I assume as Phobos is a lot bigger, we might need to flip one or other flag, but hey in the end we will have a bot that does all the nitpicking for us!

@Hackerpilot
Copy link
Contributor

My parser hates index.d.

@wilzbach wilzbach force-pushed the travis_linting branch 10 times, most recently from 79daa90 to 8308cb3 Compare April 27, 2016 01:23
@wilzbach
Copy link
Contributor Author

Great news: with #4245, #4246, #4247, the Travis passes. As mentioned I decreased the linting to a minimum, but now we do have it :)
Future work can fix more in the Phobos codebase - small low hanging fruits include e.g. > 120 lines or undocumented public methods.

Btw I found a small bug in libdparse, which the error "Primary expression expressed" is ignored.

.dscanner.ini Outdated
; Configurue which static analysis checks are enabled
[analysis.config.StaticAnalysisConfig]
; Check variable, class, struct, interface, union, and function names against t
; he Phobos style guide
Copy link
Contributor

Choose a reason for hiding this comment

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

The file seems to have been hard-wrapped at a certain column count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's from the default config of Dscanner.
I beautified the two cases, were the hard-wrapping didn't work.
Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I blame @burner for the wrapping.

@wilzbach wilzbach force-pushed the travis_linting branch 2 times, most recently from 63cf3e7 to 1fe455d Compare April 27, 2016 09:31
.travis.yml Outdated
@@ -0,0 +1,13 @@
sudo: false
language: generic
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 line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope it was an artifact when I tried tests without Dscanner. Good spot!

@PetarKirov
Copy link
Member

Nice work, @wilzbach! I'd love to see automated checking such as this leveraged during PR review.

BTW, it would also be useful as a Makefile rule for use during development. Maybe even required before building Phobos/Druntime/DMD/etc.

But let's first get this merged in.

@PetarKirov
Copy link
Member

I reviewed all changes and everything LGTM.

@wilzbach
Copy link
Contributor Author

I reviewed all changes and everything LGTM.

@ZombineDev They are submitted as separate PRs (#4245, #4246) because I didn't know how controversial they were. They are already toggled on auto merge, so as soon as win-farm-1 finds some time - I can rebase this PR and then we are good to go :)

Thanks a lot for your review & feedback!

@wilzbach
Copy link
Contributor Author

Nice initiative. Thanks for doing this. Please stay on 4243 and merge it as soon as possible, so we don't have ripples following the style change from pulling other diffs. Thx! -- Andrei

All pending PRs are in, let's go?

@PetarKirov
Copy link
Member

"All checks have passed" 🎉

@CyberShadow
Copy link
Member

Auto-merge toggled on

@CyberShadow
Copy link
Member

Well, since this has Andrei's blessing...

@wilzbach
Copy link
Contributor Author

BTW, it would also be useful as a Makefile rule for use during development. Maybe even required before building Phobos/Druntime/DMD/etc.

This might be a bit more complicated as we would need to build dscanner then.
However in theory it should be dub fetch dscanner && dub run dscanner, but feel free to explore better possibilities ;-)
Btw for the Travis CI a prebuilt binary is used for superior speed and to avoid troubles when code.dlang.org is down.

@andralex
Copy link
Member

Yah a makefile rule would be a nice next step.

@CyberShadow CyberShadow merged commit 86d4576 into dlang:master Apr 27, 2016
@wilzbach wilzbach deleted the travis_linting branch April 28, 2016 03:40
@ghost
Copy link

ghost commented Apr 28, 2016

It was a bad idea. The new pull requests done in a fine style have already begun to fail because they are affected by the old content in the files, that was never checked.

You should rather

  • run dscanner before
  • run dscanner after
  • verify if the diff is empty.

@CyberShadow
Copy link
Member

It was a bad idea. The new pull requests done in a fine style have already begun to fail because they are affected by the old content in the files, that was never checked.

No, that's not correct. Phobos was green before the checking was enabled. What happened was that someone merged a PR that was failing on Travis, which cause master to fail. The fix is already on auto-merge.

@wilzbach
Copy link
Contributor Author

It was a bad idea. The new pull requests done in a fine style have already begun to fail because they are affected by the old content in the files,

It is a test and we are experimenting with it and Travis doesn't affect autotester at all.
Btw do you get emails from Travis? If so, we should enable this during the testing stage.

@ghost
Copy link

ghost commented Apr 28, 2016

No i didn't get any mail from travis-CI, anyway, another problem is that some tests can include invalid code or quite unidiomatic code on purpose, which Dscanner could interpret as a problem. I have no concret example just now but I think this is something which can be encountered.

@CyberShadow
Copy link
Member

No i didn't get any mail from travis-CI, anyway, another problem is that some tests can include invalid code or quite unidiomatic code on purpose, which Dscanner could interpret as a problem. I have no concret example just now but I think this is something which can be encountered.

Sure. If that ever happens, then that PR can just disable the .dscanner.ini rule in the same PR.

@wilzbach
Copy link
Contributor Author

The fix is already on auto-merge.

It is merged now, so just rebase and all lights should be green again.
Btw here's another proof of linting in work at Phobos ;-)

@MartinNowak
Copy link
Member

Can we please move this into the makefile? There is already checkwhitespace target.
It's fairly inconvenient to have something only in the .travis.yml where you need copy+paste to run it.

@JackStouffer
Copy link
Contributor

If this was relegated to the make file it never would have happened, as no one wants to touch it for fear of breaking it.

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.

8 participants