33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-12-29 04:42:36 +00:00

use new report features in rules

This commit is contained in:
Denis Ryabov 2021-09-09 10:32:52 +03:00
parent 067a21f8c1
commit b7a6a923da
8 changed files with 39 additions and 28 deletions

View File

@ -238,7 +238,7 @@ class JedcheckerRulesFramework extends JEDcheckerRule
break;
default:
// Case 'notice':
$this->report->addInfo($file, $error_message, $line_number);
$this->report->addNotice($file, $error_message, $line_number);
break;
}
}

View File

@ -74,6 +74,8 @@ class JedcheckerRulesGpl extends JEDcheckerRule
*/
public function check()
{
$this->report->setDefaultSubtype($this->id);
// Prepare regexp
$this->init();
@ -210,7 +212,7 @@ class JedcheckerRulesGpl extends JEDcheckerRule
if (preg_match($this->regexGPLLicenses, $content, $match, PREG_OFFSET_CAPTURE))
{
$lineno = substr_count($content, "\n", 0, $match[0][1]) + 1;
$this->report->addInfo(
$this->report->addPassed(
$file,
JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND'),
$lineno,

View File

@ -81,6 +81,8 @@ class JedcheckerRulesJexec extends JEDcheckerRule
*/
public function check()
{
$this->report->setDefaultSubtype($this->id);
$this->initJexec();
// Find all php files of the extension

View File

@ -127,7 +127,7 @@ class JedcheckerRulesLanguage extends JEDcheckerRule
// Check EOL format is \n (not \r or \n\r)
if (strpos($content, "\r") !== false)
{
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_INCORRECT_EOL', false, false));
$this->report->addNotice($file, JText::_('COM_JEDCHECKER_LANG_INCORRECT_EOL', false, false));
}
$lines = file($file);
@ -263,7 +263,7 @@ class JedcheckerRulesLanguage extends JEDcheckerRule
// Check for empty value
if ($value === '""')
{
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_EMPTY'), $startLineno, $line);
$this->report->addNotice($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_EMPTY'), $startLineno, $line);
continue;
}
@ -350,7 +350,7 @@ class JedcheckerRulesLanguage extends JEDcheckerRule
// Check spaces around (but allow trailing space after colon)
if (preg_match('/^\s|[^:]\s+$/', $value))
{
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_SPACES_AROUND'), $startLineno, $line);
$this->report->addNotice($file, JText::_('COM_JEDCHECKER_LANG_SPACES_AROUND'), $startLineno, $line);
}
}
}
@ -406,7 +406,7 @@ class JedcheckerRulesLanguage extends JEDcheckerRule
if (!isset($this->langKeys[$key]))
{
$lineno = substr_count($content, "\n", 0, $match[1]);
$this->report->addInfo($file, JText::sprintf('COM_JEDCHECKER_LANG_UNKNOWN_KEY_IN_CODE', htmlspecialchars($key)), $lineno + 1, $lines[$lineno]);
$this->report->addNotice($file, JText::sprintf('COM_JEDCHECKER_LANG_UNKNOWN_KEY_IN_CODE', htmlspecialchars($key)), $lineno + 1, $lines[$lineno]);
}
}

View File

@ -172,7 +172,8 @@ class JedcheckerRulesXMLinfo extends JEDcheckerRule
// (and other reserved words)
if (preg_match('/\b(?:module|plugin|component|template|extension|free)\b/i', $extensionName, $match))
{
$this->report->addError($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_RESERVED_KEYWORDS', $extensionName, strtolower($match[0])));
$this->report->addIssue(JEDcheckerReport::LEVEL_ERROR, 'NM3', $file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_RESERVED_KEYWORDS', $extensionName, strtolower($match[0])));
}
// Extension name shouldn't start with extension type prefix
@ -184,14 +185,16 @@ class JedcheckerRulesXMLinfo extends JEDcheckerRule
// NM5 - Version in name/title
if (preg_match('/(?:\bversion\b|\d\.\d)/i', $extensionName))
{
$this->report->addError($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_VERSION', $extensionName));
$this->report->addIssue(JEDcheckerReport::LEVEL_ERROR, 'NM5', $file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_VERSION', $extensionName));
}
// Check for "Joomla" in the name
if (stripos($extensionName, 'joomla') === 0)
{
// An extension name can't start with the word "Joomla"
$this->report->addError($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_JOOMLA', $extensionName));
$this->report->addIssue(JEDcheckerReport::LEVEL_ERROR, 'TM2', $file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_JOOMLA', $extensionName));
}
else
{
@ -200,9 +203,8 @@ class JedcheckerRulesXMLinfo extends JEDcheckerRule
if (stripos($cleanName, 'joom') !== false)
{
// Extensions that use "Joomla" or a derivative of Joomla in the extension name need to be licensed by OSM
$this->report->addWarning($file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_JOOMLA_DERIVATIVE', $extensionName, 'https://tm.joomla.org/approved-domains.html')
);
$this->report->addIssue(JEDcheckerReport::LEVEL_WARNING, 'TM2', $file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_JOOMLA_DERIVATIVE', $extensionName, 'https://tm.joomla.org/approved-domains.html'));
}
}
@ -364,7 +366,8 @@ class JedcheckerRulesXMLinfo extends JEDcheckerRule
if (stripos($domain, 'joomla') !== false)
{
// Extensions that use "Joomla" or a derivative of Joomla in the domain name need to be licensed by OSM
$this->report->addError($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_URL_JOOMLA_DERIVATIVE', $url, 'https://tm.joomla.org/approved-domains.html'));
$this->report->addIssue(JEDcheckerReport::LEVEL_ERROR, 'TM1', $file,
JText::sprintf('COM_JEDCHECKER_INFO_XML_URL_JOOMLA_DERIVATIVE', $url, 'https://tm.joomla.org/approved-domains.html'));
}
}
}

View File

@ -62,6 +62,8 @@ class JedcheckerRulesXMLlicense extends JEDcheckerRule
*/
public function check()
{
$this->report->setDefaultSubtype($this->id);
// Find all XML files of the extension
$files = JEDCheckerHelper::findManifests($this->basedir);

View File

@ -69,11 +69,11 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
protected $warnings;
/**
* List of infos.
* List of notices.
*
* @var string[]
*/
protected $infos;
protected $notices;
/**
* Rules for XML nodes
@ -183,7 +183,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
$this->errors = array();
$this->warnings = array();
$this->infos = array();
$this->notices = array();
// Validate manifest
$this->validateXml($xml, 'extension');
@ -198,9 +198,9 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
$this->report->addWarning($file, implode('<br />', $this->warnings));
}
if (count($this->infos))
if (count($this->notices))
{
$this->report->addInfo($file, implode('<br />', $this->infos));
$this->report->addNotice($file, implode('<br />', $this->notices));
}
// All checks passed. Return true
@ -226,7 +226,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
// No known attributes for this node
foreach ($node->attributes() as $attr)
{
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_ATTRIBUTE', $name, (string) $attr->getName());
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_ATTRIBUTE', $name, (string) $attr->getName());
}
}
elseif ($DTDattributes[0] !== '*') // Skip node with arbitrary attributes (e.g. "field")
@ -238,7 +238,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
if (!in_array($attrName, $DTDattributes, true))
{
// The node has unknown attribute
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_ATTRIBUTE', $name, $attrName);
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_ATTRIBUTE', $name, $attrName);
}
}
}
@ -254,7 +254,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
// No known children for this node
if ($node->count() > 0)
{
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_CHILDREN', $name);
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_CHILDREN', $name);
}
}
elseif (!isset($DTDchildRules['*'])) // Skip node with arbitrary children
@ -295,7 +295,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
if ($count === 0)
{
// The node doesn't contain optional child element
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_MISSED_OPTIONAL', $name, $child);
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_MISSED_OPTIONAL', $name, $child);
}
elseif ($count > 1)
{
@ -324,7 +324,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
if (!isset($DTDchildToRule[$child]))
{
// The node contains unknown child element
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_CHILD', $name, $child);
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_UNKNOWN_CHILD', $name, $child);
}
else
{
@ -341,7 +341,7 @@ class JedcheckerRulesXMLManifest extends JEDcheckerRule
{
if ($child->count() === 0 && $child->attributes()->count() === 0 && (string) $child === '')
{
$this->infos[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_EMPTY_CHILD', $child->getName());
$this->notices[] = JText::sprintf('COM_JEDCHECKER_MANIFEST_EMPTY_CHILD', $child->getName());
}
}
}

View File

@ -62,6 +62,8 @@ class JedcheckerRulesXMLUpdateServer extends JEDcheckerRule
*/
public function check()
{
$this->report->setDefaultSubtype($this->id);
// Find all XML files of the extension
$files = JEDCheckerHelper::findManifests($this->basedir);
@ -213,13 +215,13 @@ class JedcheckerRulesXMLUpdateServer extends JEDcheckerRule
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_XML_UPDATE_SERVER_LINK_NOT_FOUND'));
return false;
} else {
$this->report->addInfo($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_UPDATE_SERVER_LINK', (string) $server));
}
else
{
$this->report->addPassed($file, JText::sprintf('COM_JEDCHECKER_INFO_XML_UPDATE_SERVER_LINK', (string) $server));
}
}
// All checks passed. Return true
return true;
}