-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Code Sniffer Rules #182
Comments
Hi, I've previously built sniffers for CodeIgniter 2 and 3 in PHP_CodeSniffer 2 which included phpcbf functionality, I've been using these pretty much daily in SublimeText as linters and fixing up old code for a few years. I never announced these publicly as I included a bunch of personal preferences and best practices which were being argued about at the time, these were mostly commenting, spacing alignment, string concatenation to name a few. [deprecated link removed] I'm currently in the process of converting these to PHP_CodeSniffer 3 and I have a basic working CI 4 version. You can't make these with just a ruleset.xml as some CodeIgniter style guidelines are not available anywhere within the existing PHP_CodeSniffer sniffs so I have some sniffs created purely for CodeIgniter 2, 3 and 4. I have some questions about interpreting the new style guide and I guess it could change a bit if needed?, how would you like me to proceed?, should I ask here or would you like to start a thread on the forum?, my username there is also 'louisl'. Regards Louis |
Hey Louis, that would be awesome! I started to look at it a week or so ago, realizing I would need to write sniffs for it and put that aside, since I don't have any experience with that :) Post your questions here, that's fine. If we open it up on the forums we get too many opinions lol. Or you could simply shoot me an email and we could discuss it there. |
OK, lets get the ball rolling. The example titled 'Good control structure examples:'
conflicts with:
So we want this right?
|
Good catch. You're correct. There should not be spaces inside the parentheses. |
I've run CodeIgniter4 through and it's showing up a ton of inconsistencies... Lots of space indenting, tab aligning, wrong indenting, mixed tab and space indenting, non visibility declared functions, spaces missing around operators, upper case keywords, missing newline at end of file,
to name a few. Thats good though right?, proof we're getting somewhere! Most of it's fixable with the phpcbf. OK some questions... It's not mentioned in the current style guide, but am I ok to require Quote marks for strings. - I think we should to pick one or another, my preference is single quotes unless containing a single quote then I use double quotes. Current CodeIgniter4 is mostly using single quotes. (Already have the sniff with fixer made for this too). String concatenation - guidelines are suggesting no space around |
And that's exactly why we need this! :)
|
I have always used spaces around concatenation operators, in both PHP and Java. It makes more sense to me. |
Then let's go with a space around it to maintain consistency. |
Preview version ;) https://github.com/louisl/CodeIgniter4-Standard Have a few issues to sort out but it's linting well and fixing most errors, although there's currently a problem with PHP_Codesniffer 3.0.1 phpcbf not saving files. |
Couple of updates, grab the latest develop branch.
TODO
The core of it's done. I've taken a mix of CodeIgniter 3, CodeIgniter 4 and PSR2 guides, consistencies in the CodeIgniter 4 code and some general good practices to shape it so far, so let me know what you think. |
OK, it's been added to composer and install instructions have been done. |
It's looking pretty good so far! Thanks so much for doing this. The only that stood out to me is you seem to have both lowerCaseConstants and UpperCaseConstant rules listed in ruleset.xml? |
No problem,
|
Oh, that makes sense, then. Great. |
The 'system' contains a mix of underscore prefixed private and protected methods and properties and non underscore private and protected. Whats the preference?, we can exclude methods from the rules if needed, eg |
1.0.0-beta0005 released.
Still waiting for squizlabs to release PHP_Codesniffer 3.0.2 to use the beautifier (phpcbf), however you can patch the file saving error in 3.0.1 easily for now. squizlabs/PHP_CodeSniffer#1526 |
Hi Guys, Could do with an answer on the private/protected methods and properties requiring underscore prefix or not? This analysis may help to make some decisions Analysis of Coding Conventions |
Sorry for the delay. As far as underscores, typically I wouldn't use them for private methods. As noted, the _remap method exists mainly because of backward compatibility. And a few of the libraries that support handler classes have them, but they could be renamed. So - as far as I know, only the _remap would really be kept. |
1.0.0-beta0006 released.
|
May I suggest we change the file doc block copyright tag to:
Because
|
1.0.0-beta0007 released.
|
LOL. I have no problems with that. @jim-parry ? |
I am fine with the doc block copyright change. That should be a bulk change that either you or I push directly, rather than going through a PR. Did you want to do that or shall I? @lonnieezell |
You can hit it if you'd like, @jim-parry |
Copyright notices changed, per above. |
Thank you. |
Sorry to be a pain but it shouldn't have the comma after '2017'. |
phpDocumentor says "The format of the description is governed by the coding standard of each individual project." |
Thank you for indulging me. OK this is not high priority right now but it's worth thinking about. There is this rule in the guidelines, Can I get some clarification on the interpretation of it? if filename contains |
Users can build their own helpers, inside application/Helpers. I would expect those to use snake_case, like ours inside system/Helpers do. |
That is a should rule, not engraved in stone. Is it something that should be enforced? |
Well if someone were to drop My_big_Bunch_of_Functions.php in application/helpers would it load with |
If something (BananaPie) is intended to hold helper functions, CI will look for the snake_case filename (bananapie_helper.php) |
So it would be safest to enforce *[lowercase]_helper.php in application/helpers and system/helpers then? I guess if someone needed to use something from ThirdParty or elsewhere they could just 'require' it in a helper they create rather than drop junk filenames in application/helpers. |
or, could we enforce that any filename ending with "_helper" be snake_case, and contain only function declarations and no classes? |
OK, I'm happy to go with that. |
Currently working on array sniffs and fixes, almost got it. I want to get that right before I release the next beta version. |
1.0.0-beta0008 released.
|
1.0.0-beta0009 released.
This is pretty solid now, from here on I want feedback, changes, feature requests, bugs and issues. I'll be adding some more unit tests and optimising but I'm not going to change any more functionality now without instruction. @jim-parry If you want me to hand the repo over so it's officially in bcit-ci github, I'm happy to do that. Also I don't mind if you change all the header copyrights if/when we do ;) Happy coding Let me know how you get on with it! |
This is all looking great. @louisl Thanks so much! I can't speak for @jim-parry, but I think it would be great as an official package. I'd like to see more official offshoot packages, but that's a discussion for another day. :) Jim's heading for vacation for few weeks, or has just left, so it might be a bit before he can get an answer. In the meantime, I'll start trying to use it on the CI repo and see what changes, if any, we discover. |
I haven't left yet, but I'll be off in a couple of days, and don't think I will have a chance to check this out :( |
1.0.0-beta0011 released.
Thanks for the thanks! |
Not sure how this rule must works. Is it OK currently? |
@natanfelles We decided further up in this thread that we preferred to go with a space around dot's for concatenation, so the standard is right but the style guide hasn't been updated. |
1.0.0-beta0012 released.
|
We have ignition ... https://github.com/bcit-ci/CodeIgniter4-Standard |
Looking for someone familiar with PHP_CodeSniffer to create a ruleset matching our style guide.
This is initially intended for use inside an IDE, and ultimately perhaps as part of our travis-ci build.
The text was updated successfully, but these errors were encountered: