mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
Allow users to ignore missing ignorefiles
This commit is contained in:
parent
45058ea494
commit
b5059f45a0
18
config.xsd
18
config.xsd
@ -52,14 +52,7 @@
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="directory" minOccurs="0" maxOccurs="unbounded" type="ProjectDirectoryAttributeType" />
|
||||
<xs:element name="file" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
|
||||
<xs:element name="ignoreFiles" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="directory" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
|
||||
<xs:element name="file" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="ignoreFiles" minOccurs="0" maxOccurs="1" type="IgnoreFilesType" />
|
||||
</xs:choice>
|
||||
</xs:complexType>
|
||||
|
||||
@ -67,6 +60,15 @@
|
||||
<xs:attribute name="name" type="xs:string" use="required" />
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="IgnoreFilesType">
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="directory" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
|
||||
<xs:element name="file" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
|
||||
</xs:choice>
|
||||
|
||||
<xs:attribute name="allowMissingFiles" type="xs:string" />
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ProjectDirectoryAttributeType">
|
||||
<xs:attribute name="name" type="xs:string" use="required" />
|
||||
<xs:attribute name="ignoreTypeStats" type="xs:string" />
|
||||
|
@ -81,6 +81,8 @@ class FileFilter
|
||||
$base_dir,
|
||||
$inclusive
|
||||
) {
|
||||
$allow_missing_files = ((string) $e['allowMissingFiles']) === 'true';
|
||||
|
||||
$filter = new static($inclusive);
|
||||
|
||||
if ($e->directory) {
|
||||
@ -110,6 +112,10 @@ class FileFilter
|
||||
);
|
||||
|
||||
if (empty($globs)) {
|
||||
if ($allow_missing_files) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo 'Could not resolve config path to ' . $base_dir . DIRECTORY_SEPARATOR .
|
||||
(string)$directory['name'] . PHP_EOL;
|
||||
exit(1);
|
||||
@ -117,11 +123,19 @@ class FileFilter
|
||||
|
||||
foreach ($globs as $glob_index => $directory_path) {
|
||||
if (!$directory_path) {
|
||||
if ($allow_missing_files) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo 'Could not resolve config path to ' . $base_dir . DIRECTORY_SEPARATOR .
|
||||
(string)$directory['name'] . ':' . $glob_index . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!$directory_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($ignore_type_stats && $filter instanceof ProjectFileFilter) {
|
||||
$filter->ignore_type_stats[$directory_path] = true;
|
||||
}
|
||||
@ -138,6 +152,10 @@ class FileFilter
|
||||
$directory_path = realpath($prospective_directory_path);
|
||||
|
||||
if (!$directory_path) {
|
||||
if ($allow_missing_files) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo 'Could not resolve config path to ' . $base_dir . DIRECTORY_SEPARATOR .
|
||||
(string)$directory['name'] . PHP_EOL;
|
||||
exit(1);
|
||||
|
@ -139,6 +139,33 @@ class ConfigTest extends TestCase
|
||||
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringAnalyzer.php')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testIgnoreMissingProjectDirectory()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
Config::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<ignoreFiles allowMissingFiles="true">
|
||||
<directory name="does/not/exist" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$config = $this->project_analyzer->getConfig();
|
||||
|
||||
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
|
||||
$this->assertFalse($config->isInProjectDirs(realpath('does/not/exist/FileAnalyzer.php')));
|
||||
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringAnalyzer.php')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user