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

Ignore line or array specific key declaration #147

Open
FlorentTorregrosa opened this issue Nov 19, 2021 · 7 comments
Open

Ignore line or array specific key declaration #147

FlorentTorregrosa opened this issue Nov 19, 2021 · 7 comments

Comments

@FlorentTorregrosa
Copy link

Hello,

First, thanks for the tool!

I have added it to my development stack, and use it against Drupal contrib modules that I maintain.

Is there a way to ignore a specific line with a comment? Like PHPStan, PHPCS, etc. do.

And is there a way to ignore numbers in keyed array for specific keys?

Because in Drupal, forms are declared with arrays and I think it would be an overburden to have to declare a constant for each weight or size of every element of each form.

Example of form https://git.drupalcode.org/project/qwantsearch/-/blob/8.x-1.x/src/Form/Settings.php#L124

Also, there are still procedural parts in Drupal, such as for declaring custom tables https://git.drupalcode.org/project/i18n_sso/-/blob/8.x-1.x/i18n_sso.install#L40. Ok we can create an interface and call it in the procedural parts.

So would it be possible to have a new option to have a way to ignore array keys:

#weight
#size

Thanks for any reply.

Best regards,

@sidz
Copy link
Collaborator

sidz commented Nov 19, 2021

Hi @FlorentTorregrosa

Nope it is not possible to ignore a specific line of code in this moment.

@FlorentTorregrosa
Copy link
Author

Hi @sidz,

Thanks for the quick reply. Ok, so I didn't miss something :)

@exussum12
Copy link
Collaborator

You can ignore every instance by using intval(10) instead of just 10. It's not ideal as you wouldn't know by looking at intval(10) that it's used to ignore a check for phpmnd.

Sounds a good feature request though :)

@FlorentTorregrosa
Copy link
Author

Yes and also it adds unneeded function calls.

I also tried to use string, the Drupal form API is enough permissive to do that, but I don't want to do that too. Typing is more and more enforced and changing the values type just to satisfy a code quality tool is a non-sense in my opinion.

Thanks for your feedback :)

@exussum12
Copy link
Collaborator

Yeah agreed. I think the same about comments to ignore lines tbh. The array key whitelist is not a bad idea.

There is also a check in phpmnd for numeric strings which is good to enable as well. Which stops just hiding numbers by converting to a string

@povils
Copy link
Owner

povils commented Dec 1, 2021

I like the feature to ignore specific array keys :) I see how it could be useful

@FlorentTorregrosa FlorentTorregrosa changed the title Ignore line or array specific key declation Ignore line or array specific key declaration Dec 1, 2021
@MGatner
Copy link

MGatner commented Jul 10, 2022

I would love to add this tool to my default workflow but it runs against 30+ projects and being able to "exempt" individual lines would be absolutely crucial. The array keys bit is not a deal-breaker for me, especially since you could always do this:

$weight = 10; // @phpmnd-ignore-line
$data = [
    'weight' => $weight,
];

I would like to put forth a bounty on the line exemption comment feature - anyone willing to match? @exussum12 Can you provide a fair amount or expected time to implement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants