Check the syntax of the language file
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
e22b957d7f
commit
93fc7fcdbe
4 changed files with 68 additions and 0 deletions
|
@ -28,6 +28,7 @@ namespace OC\Core\Command\App;
|
|||
use OC\App\CodeChecker\CodeChecker;
|
||||
use OC\App\CodeChecker\EmptyCheck;
|
||||
use OC\App\CodeChecker\InfoChecker;
|
||||
use OC\App\CodeChecker\LanguageParseChecker;
|
||||
use OC\App\InfoParser;
|
||||
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
|
||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
|
||||
|
@ -171,6 +172,15 @@ class CheckCode extends Command implements CompletionAwareInterface {
|
|||
$infoErrors = $infoChecker->analyse($appId);
|
||||
|
||||
$errors = array_merge($errors, $infoErrors);
|
||||
|
||||
$languageParser = new LanguageParseChecker();
|
||||
$languageErrors = $languageParser->analyse($appId);
|
||||
|
||||
foreach ($languageErrors as $languageError) {
|
||||
$output->writeln("<error>$languageError</error>");
|
||||
}
|
||||
|
||||
$errors = array_merge($errors, $languageErrors);
|
||||
}
|
||||
|
||||
$this->analyseUpdateFile($appId, $output);
|
||||
|
|
|
@ -336,6 +336,7 @@ return array(
|
|||
'OC\\App\\CodeChecker\\EmptyCheck' => $baseDir . '/lib/private/App/CodeChecker/EmptyCheck.php',
|
||||
'OC\\App\\CodeChecker\\ICheck' => $baseDir . '/lib/private/App/CodeChecker/ICheck.php',
|
||||
'OC\\App\\CodeChecker\\InfoChecker' => $baseDir . '/lib/private/App/CodeChecker/InfoChecker.php',
|
||||
'OC\\App\\CodeChecker\\LanguageParseChecker' => $baseDir . '/lib/private/App/CodeChecker/LanguageParseChecker.php',
|
||||
'OC\\App\\CodeChecker\\NodeVisitor' => $baseDir . '/lib/private/App/CodeChecker/NodeVisitor.php',
|
||||
'OC\\App\\CodeChecker\\PrivateCheck' => $baseDir . '/lib/private/App/CodeChecker/PrivateCheck.php',
|
||||
'OC\\App\\CodeChecker\\StrongComparisonCheck' => $baseDir . '/lib/private/App/CodeChecker/StrongComparisonCheck.php',
|
||||
|
|
|
@ -366,6 +366,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OC\\App\\CodeChecker\\EmptyCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/EmptyCheck.php',
|
||||
'OC\\App\\CodeChecker\\ICheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/ICheck.php',
|
||||
'OC\\App\\CodeChecker\\InfoChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/InfoChecker.php',
|
||||
'OC\\App\\CodeChecker\\LanguageParseChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/LanguageParseChecker.php',
|
||||
'OC\\App\\CodeChecker\\NodeVisitor' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/NodeVisitor.php',
|
||||
'OC\\App\\CodeChecker\\PrivateCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/PrivateCheck.php',
|
||||
'OC\\App\\CodeChecker\\StrongComparisonCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/StrongComparisonCheck.php',
|
||||
|
|
56
lib/private/App/CodeChecker/LanguageParseChecker.php
Normal file
56
lib/private/App/CodeChecker/LanguageParseChecker.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017, Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\App\CodeChecker;
|
||||
|
||||
class LanguageParseChecker {
|
||||
|
||||
/**
|
||||
* @param string $appId
|
||||
* @return array
|
||||
*/
|
||||
public function analyse($appId) {
|
||||
$appPath = \OC_App::getAppPath($appId);
|
||||
if ($appPath === false) {
|
||||
throw new \RuntimeException("No app with given id <$appId> known.");
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$directory = new \DirectoryIterator($appPath . '/l10n/');
|
||||
|
||||
foreach ($directory as $file) {
|
||||
if ($file->getExtension() !== 'json') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getPathname());
|
||||
json_decode($content, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg();
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue