benmatselby / sublime-phpcs

🔍 PHP CodeSniffer, PHP Coding Standard Fixer, Linter, and Mess Detector Support for Sublime Text
Other
812 stars 126 forks source link

Changing standard from command palette #112

Closed reinink closed 10 years ago

reinink commented 10 years ago

Daily user of this plugin and love it! Had an enhancement idea that would be really useful to myself, and probably others.

I don't use projects in Sublime Text, so setting a project specific coding standard is difficult. I generally use PSR2, but when I work on Laravel projects I have a Laravel specific coding standard. Currently, when switching to a Laravel project, I change the coding standard in the main phpcs.sublime-settings. Not ideal.

What would be brilliant is having the ability to change the current (non project specific) coding standard from the command palette. For example:

PHP Code Sniffer: Set Standard: Laravel
PHP Code Sniffer: Set Standard: PEAR
PHP Code Sniffer: Set Standard: PHPCS
PHP Code Sniffer: Set Standard: PSR1
PHP Code Sniffer: Set Standard: PSR2
PHP Code Sniffer: Set Standard: SquizZend

You can either determine the current standards based on the phpcs -i command, or even add an additional option to phpcs.sublime-settings, such as:

{
    "phpcs_available_standards": [
        "Laravel",
        "PSR1",
        "PSR2",
    ]
}
benmatselby commented 10 years ago

Sounds like a good feature request. I'd prefer that it shelled out and retrieved the standards from phpcs as you mention, so it "just works".

Not sure when I will get time to look at this, as currently a little busy in my personal life, but will keep it in mind.

reinink commented 10 years ago

Awesome!

benmatselby commented 10 years ago

@reinink Very quick implementation on the switch-standard branch. Initial testing shows that it works. Note that this only changes the standard for the session of the editor, and does not get persisted back to the settings file.

reinink commented 10 years ago

Dude, you're amazing! I'm going to give it a try...what's the easiest way? Just manually install into the packages folder?

As for changing the standard for the current session only, I wonder if that's better anyway? I know for myself my default would be PSR2. I don't know—maybe I'll just have to try this and see what it's like.

benmatselby commented 10 years ago

I use projects you see, so not really sure I would benefit from this, but I can see the use case. I suspect having an inflight, none persistent standard change would be better.

Give me about 10-15 mins and I will merge to master, so if you installed using Package Control you can update. The changes are not invasive to other functionality

reinink commented 10 years ago

Awesome!

I would use Sublime Text projects if I only worked in a few projects, even 10 or less. Unfortunately, at my work we have many clients (hundreds) with many smaller web projects, so maintaining project files can become cumbersome.

benmatselby commented 10 years ago

I hear you on that front. Right, pushed to master and tagged as 6.4.0.

Also, note, with my very cursory check of phpcs -i, I couldn't see a "nice" parseable format, so if phpcs changes the wording in output of phpcs -i I will need to update this feature.

reinink commented 10 years ago

Understood, I'll let you know if it breaks. :)

Also, does it take a bit for the change to propagate? I'm running "Upgrade Package" without success, and I don't see the change reflected here. Thoughts?

benmatselby commented 10 years ago

It must do, as I've just loaded that page and it shows the change 21 mins ago. You managed to get it yet?

reinink commented 10 years ago

I now see the update listed here, although the Upgrade Package command is not seeing the update. Evidently this takes some time?

reinink commented 10 years ago

Okay, it's updated successfully. Unfortunately, I'm not seeing any of the new commands. Going to reinstall to make sure...

reinink commented 10 years ago

Yeah, it's not working. Shoot!

FYI, here is the response I'm getting from Code Sniffer:

~/.composer $ /Users/jonathan/.composer/vendor/bin/phpcs -i
The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz and Zend

Also, the version:

~/.composer $ phpcs --version
PHP_CodeSniffer version 1.5.2 (stable) by Squiz (http://www.squiz.net)
benmatselby commented 10 years ago

What do you get? A blank list in the palette?

benmatselby commented 10 years ago

Are there any errors in the console by the way?

reinink commented 10 years ago

What do you get? A blank list in the palette?

Nope, I don't even see the option in the palette.

reinink commented 10 years ago

Are there any errors in the console by the way?

I don't see any, but again, I don't get the PHP Code Sniffer: Switch coding standard option, so I cannot even select it.

reinink commented 10 years ago

I do see the option in the content menu, but it's disabled:

image

benmatselby commented 10 years ago

Fixed. 6.4.1 released. It was checking if the php-cs-fixer path was set - which clearly should not be the case. If you are happy, let me know so I can close down the issue.

reinink commented 10 years ago

Amazing, thanks Ben. As soon as it updates through Package Control I'll let you know.

Again, I really appreciate your work on this. I'm seriously considering learning Python just so I can write extensions for Sublime Text. ;)

benmatselby commented 10 years ago

Yeah I had to learn python for this reason too. Learning coffee script for the Atom Editor plugins I'm doing as well!

reinink commented 10 years ago

I guess that's a great way to learn some new languages!

Still waiting for Package Control, apparently it could take an hour:

No matter how your package is hosted, Package Control will check it for updates approximately once per hour.

reinink commented 10 years ago

Okay, an update you're not going to like. It's still not working. The menu shows up now, which is amazing, but it doesn't actually take effect when I select something. :(

reinink commented 10 years ago

Could this have something to do with not using projects? Which would explain why it makes works for you, and not me.

I see that this line....

pref.set_setting('phpcs_additional_args', current_additional_args)

...calls pref.set_setting, which appears to only set project settings:

def set_setting(self, key, value):
    if key in self.project_settings:
        self.project_settings[key] = value

Seems to me this function should look like this:

def set_setting(self, key, value):
    if key in self.project_settings:
        self.project_settings[key] = value
    else:
        self.settings.set(key, value);
benmatselby commented 10 years ago

This is what happens when I rush, so I'm sorry for messing you about.

Just pushed up, what I hope, is the last change. You were correct so added the change.

reinink commented 10 years ago

Thanks again Ben, I feel your pain on trying to do things quickly. I've run the update and all looks good. This is a great little add-on to an already awesome plugin. Thanks a bunch!

benmatselby commented 10 years ago

Great, no worries, enjoy.