0

there is an open source php project i would like to contribute by reducing some coding guidline violations. as there are about 5000 violations for a specific sniff i guess it would be appropriate to use some regex.

the coding guidline rule is called "FunctionCallArgumentSpacingNoSpaceAfterComma". this means that all arguemts should be separated by a comma followed by a space.

these example snippets violate this rule:

$this->message('About', 'Warning, very important!', $this->securityRisk().$this->alterPasswordForm(),2);
$sFiles = t3lib_div::getFilesInDir(PATH_typo3conf,'sql',1,1);
if (!strstr(implode(',',$sFiles).',', '/database.sql,')) {

can anybody help in creating a useful regex to fix these coding guidline violations? i tried some hours but i am unfortunately not capable to solve this on my own.

4

2 回答 2

0

我会尝试的第一件事是这样的:

sed 's/,\([^ ]\)/, \1/g' someFile.php

将逗号后跟非空格的逗号替换为逗号、空格和逗号后的字符

在考虑了片刻之后,这可能有点工作。

但一定有很多我没有想到的事情......

于 2012-05-11T20:51:42.130 回答
0

您不能使用正则表达式安全/可靠地执行此操作。在某些语言中,您甚至无法可靠地跳过过去的字符串文字(考虑 Perl 的q语法;尤其是它如何处理它认为是“括号”字符的内容)。即使忽略这些,如果代码库中有多种语言(例如 PHP、Java 和 Perl 中的字符串/字符文字之间存在细微差异),您也会遇到麻烦。

于 2012-05-11T21:06:15.380 回答