Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/FileNameLinter.php
<?php | <?php | ||||
/** | /** | ||||
* Check that source code file names are compliant with naming conventions. | * Check that source code file names are compliant with naming conventions. | ||||
*/ | */ | ||||
final class FileNameLinter extends ArcanistLinter { | final class FileNameLinter extends ArcanistLinter { | ||||
const INVALID_FILENAME_FOUND = 1; | const INVALID_FILENAME_FOUND = 1; | ||||
const EXCEPTIONS = array( | |||||
// None so far | |||||
); | |||||
public function getInfoName() { | public function getInfoName() { | ||||
return 'lint-source-filename'; | return 'lint-source-filename'; | ||||
} | } | ||||
public function getInfoDescription() { | public function getInfoDescription() { | ||||
return pht('Check that source code file names are compliant with naming '. | return pht('Check that source code file names are compliant with naming '. | ||||
'conventions.'); | 'conventions.'); | ||||
} | } | ||||
Show All 15 Lines | final class FileNameLinter extends ArcanistLinter { | ||||
public function getLintNameMap() { | public function getLintNameMap() { | ||||
return array( | return array( | ||||
self::INVALID_FILENAME_FOUND => pht('The file name violates the naming '. | self::INVALID_FILENAME_FOUND => pht('The file name violates the naming '. | ||||
'conventions'), | 'conventions'), | ||||
); | ); | ||||
} | } | ||||
public function lintPath($path) { | public function lintPath($path) { | ||||
// If file is in the exception list, let it go | |||||
if (in_array($path, self::EXCEPTIONS)) { | |||||
return; | |||||
} | |||||
$abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | $abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | ||||
$fileContent = Filesystem::readFile($abspath); | $fileContent = Filesystem::readFile($abspath); | ||||
if(preg_match('/[^a-z0-9_-]/', pathinfo($path, PATHINFO_FILENAME))) { | if(preg_match('/[^a-z0-9_-]/', pathinfo($path, PATHINFO_FILENAME))) { | ||||
$this->raiseLintAtPath( | $this->raiseLintAtPath( | ||||
self::INVALID_FILENAME_FOUND, | self::INVALID_FILENAME_FOUND, | ||||
pht('Source code file names should only contain [a-z0-9_-] chars (see '. | pht('Source code file names should only contain [a-z0-9_-] chars (see '. | ||||
'doc/developer-notes.md).')); | 'doc/developer-notes.md).')); | ||||
} | } | ||||
} | } | ||||
} | } |