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
bears/php: Add PHPMessDetectorBear #1486
Conversation
tests/php/PHPMessDetectorBearTest.py
Outdated
def load_testfile(name): | ||
return open(get_testfile_path(name)).readlines() | ||
|
||
@generate_skip_decorator(PHPMessDetectorBear) |
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.
E302 expected 2 blank lines, found 1'
PycodestyleBear (E302), severity NORMAL, section autopep8
.
Since PHPMD depends on composer for its installation, we shall wait till https://gitlab.com/coala/package_manager/issues/34 gets merged. |
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
5 similar comments
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
@yash-nisar this can be worked on now? |
Since I had included it in my GSoC proposal, the plan was to do it during GSoC if at all I get selected but I'll complete this asap once I'm done with my exams. :) |
e0d4b9c
to
13cb512
Compare
curl -fsSL -o phpmd.phar http://static.phpmd.org/php/latest/phpmd.phar | ||
sudo chmod +x phpmd.phar | ||
sudo mv phpmd.phar ~/phpmd/phpmd | ||
fi |
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.
Line contains following spacing inconsistencies:
- No newline at EOF.
SpaceConsistencyBear, severity NORMAL, section ci
.
The issue can be fixed by applying the following patch:
--- a/.ci/deps.sh
+++ b/.ci/deps.sh
@@ -184,4 +184,4 @@
curl -fsSL -o phpmd.phar http://static.phpmd.org/php/latest/phpmd.phar
sudo chmod +x phpmd.phar
sudo mv phpmd.phar ~/phpmd/phpmd
-fi+fi
f7cd2bf
to
95f0b60
Compare
Aaaanddddd the tests pass again ! 🎉 |
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.
No need to wait for ComposerRequirement for this; it is one line that can be added at the end of the release cycle.
bears/php/PHPMessDetectorBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
phpmd_ruleset: typed_list(str)=''): |
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 wrong on many levels.
never use an empty string as a default unless that is a valid value. Use None
.
and this is supposed to be a list, but you give a string as a default.
But, since it is a mandatory argument, simply do not provide a default and coala will do the work for 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.
@jayvdb Do you mean something like phpmd_ruleset: list
?
bears/php/PHPMessDetectorBear.py
Outdated
Available rulesets: cleancode, codesize, controversial, design, | ||
naming, unusedcode. | ||
""" | ||
if phpmd_ruleset == '': # pragma: no cover |
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 will all be removed due to the above comment, ...
but never use # pragma: no cover
to avoid writing additional tests. It should be used only for insanely difficulty chunks of code to reach with a test.
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.
Removed 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.
no eol at eof
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 should make coala do that. :P
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.
why does coala not pick this up?
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.
@SanketDG coala doesn't pick this up even when I run it individually on this file.
Command: coala -V -b SpaceConsistencyBear -f s.php --flush-cache
s.php
is the following file without a newline at eof.
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 coala/coala#2006
} | ||
} | ||
} | ||
?> |
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.
no eol at eof
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.
Rectified. :)
@@ -0,0 +1,39 @@ | |||
from coalib.settings.Setting import typed_list |
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 file contains unused source code.
PyUnusedCodeBear, severity NORMAL, section flakes
.
The issue can be fixed by applying the following patch:
--- a/bears/php/PHPMessDetectorBear.py
+++ b/bears/php/PHPMessDetectorBear.py
@@ -1,4 +1,3 @@
-from coalib.settings.Setting import typed_list
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.DistributionRequirement import \
DistributionRequirement
ff7cc1d
to
cd2f965
Compare
@@ -0,0 +1,39 @@ | |||
from coalib.settings.Setting import typed_list |
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 file contains unused source code.
PyUnusedCodeBear, severity NORMAL, section flakes
.
The issue can be fixed by applying the following patch:
--- a/bears/php/PHPMessDetectorBear.py
+++ b/bears/php/PHPMessDetectorBear.py
@@ -1,4 +1,3 @@
-from coalib.settings.Setting import typed_list
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.DistributionRequirement import \
DistributionRequirement
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.
Why do I forget to run coala ?!!
bears/php/PHPMessDetectorBear.py
Outdated
phpmd_ruleset: list): | ||
""" | ||
:param phpmd_ruleset: | ||
A ruleset filename or a comma-separated string of rulesetfilenames. |
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.
"rulesetfilenames." - what is that?
-> comma-separated string of ruleset filenames and built-in ruleset names.
But really we should be using config_file
for the filename, which would mean that this ruleset variable is used only for the built-in ruleset names, which makes it more easily verified. (and the _config variable could then be managed by coala/coala#4072)
This comes at a slight loss of functionality, as only one config file could be used (It looks like phpmd supports multiple) , but presumably XInclude can be used to avoid that limitation.
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.
Okay so IIUC, we mention the rulesets
in our config_file
? @jayvdb
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.
phpmd -h
gives this:
yash ~ phpmd -h
Mandatory arguments:
1) A php source code filename or directory. Can be a comma-separated string
2) A report format
3) A ruleset filename or a comma-separated string of rulesetfilenames
So, this is where I picked the description from 😛
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 workaround satisfactory ? @jayvdb
@staticmethod
def create_arguments(filename, file, config_file,
phpmd_ruleset: list):
"""
:param phpmd_ruleset:
A ruleset filename or a comma-separated string of rulesetfilenames.
Available rulesets: cleancode, codesize, controversial, design,
naming, unusedcode.
"""
config_file = phpmd_ruleset
return filename, 'text', ','.join(config_file)
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.
So in any way it's a list, right? I think it just suffices to say
A list of rulesets to use for analysis. Available rulesets: ...
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 then I would call this setting phpmd_rulesets
(note the s
)
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.
Awesome. 🎉
bears/php/PHPMessDetectorBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
phpmd_ruleset: list): |
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.
list(str)
!
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.
Getting a type error, TypeError: 'type' object is not iterable
.
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.
--> typed_list(str)
is the right one ;)
bears/php/PHPMessDetectorBear.py
Outdated
@@ -0,0 +1,38 @@ | |||
from coalib.bearlib.abstractions.Linter import linter | |||
from dependency_management.requirements.DistributionRequirement import \ | |||
DistributionRequirement |
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.
braces instead of \
please ;)
bears/php/PHPMessDetectorBear.py
Outdated
|
||
@linter(executable='phpmd', | ||
output_format='regex', | ||
output_regex=r'(?P<filename>.*):(?P<line>\d+)(?P<message>.*)') |
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.
isn't there some space between line
and message
? Could you post me an output example of phpmd
?
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.
Sure, just a minute. :)
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.
[WARNING][21:11:32] Implicit 'Default' section inheritance is deprecated. It will be removed soon. To silence this warning remove settings in the 'Default' section from your coafile. You can use dots to specify inheritance: the section 'all.python' will inherit all settings from 'all'.
Please enter a value for the setting "phpmd_ruleset" (A ruleset filename or a comma-separated string of rulesetfilenames. Available rulesets: cleancode, codesize, controversial, design, naming, unusedcode.) needed by PHPMessDetectorBear for section "cli":
cleancode
[DEBUG][21:11:37] Platform Linux -- Python 3.5.2, coalib 0.11.0.dev99999999999999
[DEBUG][21:11:37] The file cache was successfully flushed.
Executing section cli...
[DEBUG][21:11:37] Files that will be checked:
/home/yash/s.php
[DEBUG][21:11:37] coala is run only on changed files, bears' log messages from previous runs may not appear. You may use the `--flush-cache` flag to see them.
[DEBUG][21:11:37] Running bear PHPMessDetectorBear...
[DEBUG][21:11:37] Running 'phpmd /home/yash/s.php text cleancode'
s.php
| 8| ········}·else·{
| | [NORMAL] PHPMessDetectorBear:
| | The method bar uses an else expression. Else is never necessary and you can simplify the code to work without else.
| | *0: Do nothing
| | 1: Open file(s)
| | 2: Add ignore comment
| | Enter number (Ctrl-D to exit): 0```
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 the output of the phpmd tool:
yash (e) venv ~ phpmd /home/yash/s.php text cleancode
/home/yash/s.php:8 The method bar uses an else expression. Else is never necessary and you can simplify the code to work without else.
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.
Will update my regex to (?P<filename>.*):(?P<line>\d+)\s*(?P<message>.*)
, note that I've added an \s*
to capture spaces. :)
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.
Interesting though, looks like coala does strip the message. And now I recall that from somewhen... but still: better explicit than implicit 👍
bears/php/PHPMessDetectorBear.py
Outdated
Available rulesets: cleancode, codesize, controversial, design, | ||
naming, unusedcode. | ||
""" | ||
return filename, 'text', ','.join(phpmd_ruleset) |
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.
what's text
?
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.
An available report format. It can be xml, text or html. :)
bears/php/PHPMessDetectorBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
phpmd_ruleset: list): |
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.
Maybe we want to make this setting optional by kicking in all available rulesets by default? Not sure...
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.
So IIUC, do we provide all the rulesets as default like phpmd_ruleset: list=[rule1, rule2, ...]
?
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.
yeah exactly, though I'm really not sure if we wanna 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.
What are the current defaults of phpmd?
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.
The ruleset is a mandatory argument, so phpmd s.php text
yields nothing whereas phpmd s.php text cleancode
yields results.
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.
okay let's keep it mandatory for now^^
Reviewers v1.0
|
bears/php/PHPMessDetectorBear.py
Outdated
|
||
@linter(executable='phpmd', | ||
output_format='regex', | ||
output_regex=r'(?P<filename>.*):(?P<line>\d+)\s*(?P<message>.*)') |
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.
do not capture filename, as it is useless information that the bear already has. (please check our docs dont recommend capturing filename)
and don't use .*
unless there is no other option.
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 everything else good ?
ack bb46ca3 |
@rultor merge |
Closes #22
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!