From 93fc7fcdbef0fdd0fda1ea2be9047817bb68524c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 May 2017 15:46:33 +0200 Subject: [PATCH] Check the syntax of the language file Signed-off-by: Joas Schilling --- core/Command/App/CheckCode.php | 10 ++++ lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + .../App/CodeChecker/LanguageParseChecker.php | 56 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 lib/private/App/CodeChecker/LanguageParseChecker.php diff --git a/core/Command/App/CheckCode.php b/core/Command/App/CheckCode.php index aa618b26cec..1effed99566 100644 --- a/core/Command/App/CheckCode.php +++ b/core/Command/App/CheckCode.php @@ -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("$languageError"); + } + + $errors = array_merge($errors, $languageErrors); } $this->analyseUpdateFile($appId, $output); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 59cac3db775..19380f6571b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index b7e584c324a..46285356489 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.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', diff --git a/lib/private/App/CodeChecker/LanguageParseChecker.php b/lib/private/App/CodeChecker/LanguageParseChecker.php new file mode 100644 index 00000000000..29331d1e648 --- /dev/null +++ b/lib/private/App/CodeChecker/LanguageParseChecker.php @@ -0,0 +1,56 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + +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; + } +} -- 2.39.5