Skip to content
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

Pass the value of variables to checkers #72

Closed
wants to merge 3 commits into from
Closed

Conversation

swsnr
Copy link
Contributor

@swsnr swsnr commented Mar 5, 2013

Analogous to config, add option tag to checker commands to pass the value of a variable to a checker. Accompany this tag with a macro flycheck-def-option-var that declares the corresponding variable.

Interface

:command '("phpcs" (option "--standard" flycheck-phpcs-standard) source)

The first element of config is the option to use, the second the variable symbol.

(flycheck-def-option-var flycheck-phpcs-standard php-phpcs nil
   "The coding standard to use when checking with phpcs"
   :type 'string)

The first argument is the variable name, the second the associated checker, the third the default value, and the forth is the docstring. Any further options will be pass to defcustom. The variable will be made buffer local and customizable within a group flycheck-checker-options.

Rationale

Allow to configure checkers beyond configuration files. See #71 for an example.

@steckerhalter
Copy link

Sounds good. Just make sure there is no default set in flycheck because the usual way to the default is via the phpcs config file, e.g. /etc/php-codesniffer/CodeSniffer.conf

(flymake-phpcs had that set to PEAR as default which I found pretty annoying)

Cheers

@swsnr
Copy link
Contributor Author

swsnr commented Jan 25, 2013

Does phpcs have an option to specify the path to this configuration file?

@steckerhalter
Copy link

I couldn't find one... I think it's hard coded into the package, not sure though

@dhaley
Copy link

dhaley commented Jan 28, 2013

Hmm, my phpcs (installed from pear) is a php script. I quickly looked through the php libraries it calls, and didn't see a reference to a config file. But maybe I just missed it. Anyway, on my system, if there is a config file, phpcs did a good job of hiding it.

So I think passing an argument to flycheck is the most solid way of setting the 'Standard'.

See phpcs source

Edit (lunaryorn): Replaced pasted source code with source link

@swsnr
Copy link
Contributor Author

swsnr commented Jan 28, 2013

@dhaley Please do not just dump large code listings into comments, the more if the listings don't provide any insight at all. I've taken the liberty to edit your comment to replace the source code snippet with a link to the source code repository of phpcs.

@dhaley
Copy link

dhaley commented Jan 28, 2013

lunaryorn, thanks for cleaning that up. A link makes a lot more sense.

@steckerhalter
Copy link

this is how the default standard is set:

phpcs --config-set default_standard Squiz

http://pear.php.net/manual/en/package.php.php-codesniffer.config-options.php

it then creates the config file:

cat /etc/php-codesniffer/CodeSniffer.conf

<?php
 $phpCodeSnifferConfig = array (
  'default_standard' => 'Squiz',
)

@swsnr
Copy link
Contributor Author

swsnr commented Feb 1, 2013

@steckerhalter I assume that there is no option to specify a project-specific configuration file, is there?

@arnested
Copy link

arnested commented Feb 1, 2013

No, there is no way to specify a project specific configuration file.

The "--standard" option can also be used to point to the path / file with a specific standard though.

@dhaley
Copy link

dhaley commented Feb 1, 2013

steckerhalter, thanks your details on creating the Code Sniffer config file.

For me, with "mac ports" installed pear, the conf file lives at:

/opt/local/lib/php/data/PHP_CodeSniffer/CodeSniffer.conf

Since I only do Drupal php these days, I can probably live with just setting the standard in the Code Sniffer config file. But it would be nice to switch the standard dynamically based on php derived minor modes, as you guys are proposing.

swsnr added a commit that referenced this pull request Feb 23, 2013
This change prepares for [#72] and the subsequent support for coding
standards in the PHP CodeSniffer checker, which does only accept options
and values given as single argument.
@swsnr swsnr closed this in 9edae23 Mar 8, 2013
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.

4 participants