-
Notifications
You must be signed in to change notification settings - Fork 581
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
WIP: Add PHPStanBear #1468
base: master
Are you sure you want to change the base?
WIP: Add PHPStanBear #1468
Conversation
bears/php/PHPStanBear.py
Outdated
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} | ||
@staticmethod | ||
def create_arguments(filename, file, 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.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section python
.
The issue can be fixed by applying the following patch:
--- a/bears/php/PHPStanBear.py
+++ b/bears/php/PHPStanBear.py
@@ -16,5 +16,5 @@
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Syntax'}
@staticmethod
- def create_arguments(filename, file, config_file):
+ def create_arguments(filename, file, config_file):
return ('analyse', '--no-ansi', filename)
bears/php/PHPStanBear.py
Outdated
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} | ||
@staticmethod | ||
def create_arguments(filename, file, 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.
W291 trailing whitespace'
PycodestyleBear (W291), severity NORMAL, section autopep8
.
bears/php/PHPStanBear.py
Outdated
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} | ||
@staticmethod |
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.
E301 expected 1 blank line, found 0'
PycodestyleBear (E301), severity NORMAL, section autopep8
.
bears/php/PHPStanBear.py
Outdated
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} |
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 code does not comply to PEP8.
PEP8Bear, severity NORMAL, section autopep8
.
The issue can be fixed by applying the following patch:
--- a/bears/php/PHPStanBear.py
+++ b/bears/php/PHPStanBear.py
@@ -15,6 +15,7 @@
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Syntax'}
+
@staticmethod
- def create_arguments(filename, file, config_file):
+ def create_arguments(filename, file, config_file):
return ('analyse', '--no-ansi', filename)
4caf034
to
00e1649
Compare
bears/php/PHPStanBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return ('analyse', '--no-ansi', filename) |
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.
PHPStan support different Rule levels as well. Please add arguments for rule_level
as well. Check https://github.com/phpstan/phpstan#rule-levels
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.
Also, you need to add the -c
option followed by config_file
for the configuration file to work.
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.
@satwikkansal There's something wrong with the rule_level
i have tried to add argument this way
def create_arguments(filename, file, config_file,phpstan_level: str='0'):
return ('analyse', '--no-ansi','-l '+phpstan_level,filename)
now while executing coala over a bad_file
coala --bear-dirs=. --bears=PHPStanBear --files=hello-world.php -V --flush-cache
[WARNING][20:20:01] The default coafile '.coafile' was not found. You can generate a configuration file with your current options by adding the `--save` flag or suppress any use of config files with `-I`.
[DEBUG][20:20:01] Platform Linux -- Python 3.6.0, coalib 0.10.0.dev99999999999999
[DEBUG][20:20:01] The file cache was successfully flushed.
Executing section cli...
[DEBUG][20:20:01] 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][20:20:01] Files that will be checked:
/home/damngamerz/bear/hello-world.php
[DEBUG][20:20:01] Running bear PHPStanBear...
[DEBUG][20:20:01] Running 'phpstan analyse --no-ansi -l 0 /home/damngamerz/bear/hello-world.php'
it doesn't catch any error.regex is fine cause earlier it was catching as you can see my screen shot which i have posted.
And similarly tried for -c
argument for config-file
def create_arguments(filename, file, config_file,phpstan_config: str=os.devnull):
return ('analyse', '--no-ansi','-c '+phpstan_config,filename)
same thing happens while running coala for this.
coala --bear-dirs=. --bears=PHPStanBear --files=hello-world.php -V --flush-cache
[WARNING][20:40:56] The default coafile '.coafile' was not found. You can generate a configuration file with your current options by adding the `--save` flag or suppress any use of config files with `-I`.
[DEBUG][20:40:56] Platform Linux -- Python 3.6.0, coalib 0.10.0.dev99999999999999
[DEBUG][20:40:56] The file cache was successfully flushed.
Executing section cli...
[DEBUG][20:40:56] 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][20:40:56] Files that will be checked:
/home/damngamerz/bear/hello-world.php
[DEBUG][20:40:56] Running bear PHPStanBear...
[DEBUG][20:40:56] Running 'phpstan analyse --no-ansi -c /dev/null /home/damngamerz/bear/hello-world.php'
But i have noticed one thing, while invoking this following command in cli gives
phpstan analyse --no-ansi -c /dev/null /home/damngamerz/bear/hello-world.php
Project config file at path /dev/null does not exist.
So for config-file
im doing something wrong.Any Thoughts?
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.
Project config file at path /dev/null does not exist
@damngamerz The error says that the path /dev/null
which you provide as config file is not a valid path which is True as you've not create any configuration file yet.
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.
Also regarding rule-level
, try running phpstan
directly with different levels and see if there is any output or if the regex changes. In your case, you've set the default level to 0 (which is the loosest), so I reckon that's why it wasn't able to capture your bad file errors.
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.
@satwikkansal well then what can i do with -c
so the phpstan
can execute over the file without this error?
By default while running phpstan the level is set to 0.And i had ran that command in cli
phpstan analyse --no-ansi -l 0 /home/damngamerz/bear/hello-world.php
------ -----------------------------------------------------------------
Line hello-world.php
------ -----------------------------------------------------------------
7 Syntax error, unexpected T_ECHO, expecting ';' or '{' on line 7
------ -----------------------------------------------------------------
[ERROR] Found 1 error
Same error reproduced.
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.
@damngamerz You must be having some bugs in your code that are causing this.
Please read our Developer's guide thoroughly as most of the things we generally need are mentioned over there, read the documentation of PHPStan to know how exactly their config file works.
And lastly, in case of some error feel free to discuss on the Gitter channel (as I might miss your notifications, others will still be able to help you out) 😉
bears/php/PHPStanBear.py
Outdated
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} |
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.
For PHPStan's readme, it seems like it can probably detect Unused Code
, 'Variable Misuse', etc. Make sure to add all labels that seem appropriate to CAN_DETECT
set. You can refer bear class documentation for the labels ;)
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.
Yup added the followingCAN_DETECT = {'Syntax','Unused Code','Variable Misuse','Undefined Element','Missing Import','Spelling'}
Will be updating soon.
tests/php/PHPStanBearTest.py
Outdated
|
||
def test_run(self): | ||
# Test a file with errors and warnings | ||
self.check_validity( |
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.
check_validity
asserts if your bear yields any results for a particular check with a list of strings. However, IMO it is good to check the result itself as well. Try using LocalBearTestHelper.check_results
to check the results given by your bears.
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.
Also, not necessary, but you can use verify_local_bear
to create good_files and bad_files (good_file is a file which your bear considers as non-style-violating and a bad_file is one which has at least one error/warning/info)
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.
@satwikkansal Well I have used check_validity
as one of the other bear test file PHPLintBearTest uses those two test files (i.e.test_files/phplint_test1.php
& test_files/phplint_test1.php
).So if we have the resources why not use them.Should i really change it to check_results
? Cause i have read in the docs we can use any of those 3 methods to test a bear.
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.
@damngamerz
check_validity
just checks if there is a result from the bear or not, to test what exactly the result should be, we need to use check_results
.
Here are the docs
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.
@satwikkansal cool i will update 👍 😄
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.
Im changing to verify_local_bear
as later i can append more tests easily 👍
00e1649
to
084b600
Compare
bears/php/PHPStanBear.py
Outdated
""" | ||
:param phpstan_config: | ||
path to a custom configuration file. | ||
When using a custom project config file, you have to pass the phpstan_level argument |
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.
E501 line too long (96 > 79 characters)'
PycodestyleBear (E501), severity NORMAL, section autopep8
.
bears/php/PHPStanBear.py
Outdated
'Undefined Element', 'Missing Import', 'Spelling'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, phpstan_level: str='0', phpstan_config: 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.
E501 line too long (102 > 79 characters)'
PycodestyleBear (E501), severity NORMAL, section autopep8
.
bears/php/PHPStanBear.py
Outdated
""" | ||
:param phpstan_config: | ||
path to a custom configuration file. | ||
When using a custom project config file, you have to pass the phpstan_level argument |
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 is longer than allowed. (96 > 79)
LineLengthBear, severity NORMAL, section linelength
.
bears/php/PHPStanBear.py
Outdated
'Undefined Element', 'Missing Import', 'Spelling'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, phpstan_level: str='0', phpstan_config: 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.
Line is longer than allowed. (102 > 79)
LineLengthBear, severity NORMAL, section linelength
.
084b600
to
90c3f89
Compare
tests/php/PHPStanBearTest.py
Outdated
""" | ||
|
||
|
||
PHPStanBearTest = verify_local_bear( |
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 have been trying to increase test quality and we are trying to move away form verify_local_bear. Please check the bear output to make sure it is outputting the right error.
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.
@Mixih uhhh earlier i was using check_validity
then i moved towards verify_local_bear
on the suggestion of @satwikkansal . 😰
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.
@damngamerz Sorry didn't knew that regarding verify_local_bear
😞
btw we should still use check_results
over check_validity
( @Mixih please correct me if I'm wrong 😅 )
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.
@satwikkansal @Mixih Most of the bear tests which i have seen are using check_validity
and verify_local_bear
.Till now i haven't seen a bear test using check_results
so I'm really not that much comfortable with it.Decide guys 😛
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 last line in testing docs says,
Use
check_results
as much as possible to test your bears.
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 using check_results
won't harm because it is more rigorous than check_validity
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.
@satwikkansal Sorry but i need a second opinion this time.I don't want my effort to go vain again.As i said im not that much comfortable with check_results
. And I haven't found any particular bear test using it.Most of the bear tests use check_validity
and verify_local_bear
.If i have to roll back to check_validity
i can do that.
@Mixih Any thoughts about 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.
weeeell, we've been wanting proper test classes for a while. Please do use check_results with a proper test class with a skiptest decorator. The old way needs to go as it allows bears to spontaneously break.
bears/php/PHPStanBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
phpstan_level: str='0', phpstan_config: 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.
E128 continuation line under-indented for visual indent'
PycodestyleBear (E128), severity NORMAL, section autopep8
.
bears/php/PHPStanBear.py
Outdated
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
phpstan_level: str='0', phpstan_config: 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.
The code does not comply to PEP8.
PEP8Bear, severity NORMAL, section autopep8
.
The issue can be fixed by applying the following patch:
--- a/bears/php/PHPStanBear.py
+++ b/bears/php/PHPStanBear.py
@@ -21,7 +21,7 @@
@staticmethod
def create_arguments(filename, file, config_file,
- phpstan_level: str='0', phpstan_config: str=''):
+ phpstan_level: str='0', phpstan_config: str=''):
"""
:param phpstan_config:
path to a custom configuration file.
90c3f89
to
87e1a24
Compare
bears/php/PHPStanBear.py
Outdated
When using a custom project config file, | ||
you have to pass the phpstan_level argument | ||
(default value 0 does not apply here). | ||
:param phpstan_level: |
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.
When using a custom project config file, you have to pass the phpstan_level argument (default value 0 does not apply here).
If that's the case, please add check for this situation in the code so that it doesn't result in a runtime error.
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.
@satwikkansal uhhh I knew someone will point this out 😄 well i was searching for a solution in coala API docs and existing bears.But i couldn't find any interrupt kind of function, which can warn the user about this.Is there any?
One thing which i can propose is that setting the default value of rule_level
as 1 whenever phpstan_config
is used.And add these details in 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.
Don't know if something relevant exists in coala api , but maybe you can do something like
if phpstan_config and phpstan_level:
# add -c and phpstan_config to arguments
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 have initialized phpstan_level='0'
as you can see, so that won't work.
Instead as i have suggested this works.Tested 👍
args = ('analyse',)
if phpstan_config:
phpstan_level='1'
args += ('--level='+phpstan_level,'-c '+phpstan_config, filename,)
else:
args += ('--level='+phpstan_level, filename,)
return args
988c7fc
to
b025699
Compare
Introduce PHPStanBear Checks the code with ``phpstan analyze``. Closes coala#1426
ffb80de
to
22fdbcb
Compare
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
12 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! |
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! |
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! |
Introduce PHPStanBear
Checks the code with
phpstan analyze
.Closes #1426
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!