Repository navigation
Report unmatched ignoreErrors entries of the analysed files when analysing only files - #7047
Merged
Merged
Conversation
…ysing only files When only files are analysed, unmatched entries with a path were never reported. UnmatchedIgnoredErrorJudge already decides which entries can be judged in a partial analysis, so it now decides for a list of files too: an entry for an analysed file is reported when the file is analysed together with its traits, and a count that is too high is reported for it. Entries without a path, and directory and pattern entries, are reported only when the analysed files cover them. Without paths in the configuration, the analysed directories are taken as the whole project, but a list of files is only a part of an unknown one, so every trait that is not analysed counts against a file then. Amp-Thread-ID: https://ampcode.com/threads/T-01a1ba2c-2885-703b-90d3-0df9bf93b430
This was referenced Nov 12, 2026
Their scope is Scope&CollectedDataEmitter&DependencyTracker, so a collector can emit data for another collector besides the data it returns, like a rule can. DependencyTracker, DeclarationDependencyTracker, NodeCallbackInvoker and CollectedDataEmitter are @api-do-not-implement: only PHPStan's scope implements them. Amp-Thread-ID: https://ampcode.com/threads/T-01a1ba2c-2885-703b-90d3-0df9bf93b430
… depends on files that are not analysed Rules on CollectedDataNode report errors in a file based on data collected in other files, like a call to a function that is pure only when its declaration is analysed too. In a partial analysis, the ignoreErrors entries of such a file were reported as unmatched, and removed by --fix. The collectors of possibly pure calls, the trait files of classes and calls with named arguments emit the files what is reported in the analysed file depends on as AnalysedFileDependencyCollector data, or null for the whole project. It is kept in the result cache with relative paths, and UnmatchedIgnoredErrorJudge follows it transitively. Amp-Thread-ID: https://ampcode.com/threads/T-01a1ba2c-2885-703b-90d3-0df9bf93b430
ondrejmirtes
force-pushed
the
report-unmatched-ignores-in-only-files-runs
branch
from
November 12, 2026 20:27
c384580 to
62c079e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #7044, #7045 and #7046. Two changes for a partial analysis:
Unmatched entries when analysing only files
When only files were analysed (a list of files on the command line, like git hooks or editor integrations pass), unmatched
ignoreErrorsentries with a path were never reported. That gate was added in c9df2f4 for an error in a trait, which is reported in the file of the class using it only when the trait is analysed too. #7046 handles that for every partial analysis, so the gate goes, andUnmatchedIgnoredErrorJudgedecides for a list of files too:countthat is too high.pathsin the configuration, the analysed directories are taken as the whole project (Report unmatched ignoreErrors entries with a directory or pattern path only under the analysed paths #7044), but a list of files is only a part of an unknown one. Every dependency that isn't analysed counts against a file then, even one from vendor.This means only-files and editor runs now report unmatched entries of the files they analyse. That's what makes
--fix-ignoredwith a list of files remove the baseline entries of the files it fixed.What the errors of a file depend on
Rules on
CollectedDataNodereport errors in a file based on data collected in other files.CallToFunctionStatementWithoutImpurePointsRuleand its siblings report a call only when the declaration of the called function, and of everything it calls, is analysed too. Soanalyse src/Callsreported thefunction.resultUnusedentry of a call to a function declared elsewhere as unmatched, and--fixremoved it. That happens in a directory run on2.3.x; without this, removing the only-files gate would have brought it to lists of files as well.The collectors emit what the errors of the analysed file depend on as
AnalysedFileDependencyCollectordata: a file, ornullfor the whole project. It's internal, not a new API. The data is aCollectorWithPaths, so it's kept in the result cache with relative paths, andUnmatchedIgnoredErrorJudgefollows it transitively. A file that isn't analysed even in the whole project (outside the configuredpaths,excludePaths: analyse:) doesn't count.PossiblyPureCallTransitivePurityResolveremit the files declaring the called functions, methods and constructorsUsedTraitFilesCollectorfrom Report unmatched ignoreErrors entries in a partial analysis only for files analysed together with their traits #7046 emits the trait files instead of collecting themMethodCallWithPossiblyRenamedNamedArgumentRulereports depending on subclasses anywhere, depends on the whole projectCollectors can emit collected data
Collector::processNode()now getsScope&CollectedDataEmitter&DependencyTracker, like rules getCollectedDataEmitter, so a collector can emit data for another collector besides the data it returns. Existing collectors keep working, because theirScopeparameter is wider.DependencyTracker,DeclarationDependencyTracker,NodeCallbackInvokerandCollectedDataEmitterare now@api-do-not-implement.When a rule on collected data skips its errors because only files are analysed, nothing is reported (#7045). PHPStan's own
NotAnalysedTraitRuledoes that whenever an analysed file declares a trait, so on level 4 and up, a list of files that includes a trait file reports no unmatched entries.Tests
e2e/bug-15659: case 1 of the issue as reported, directory runs and--fix --fix-ignored lib; fails before Report unmatched ignoreErrors entries with a directory or pattern path only under the analysed paths #7044e2e/ignore-errors-partial-analysis/only-files_test.sh: entries and counts of the analysed files, entries of other files, directories, patterns and global entries, files with traits, a file declaring a traitcollected-data-dependencies_test.sh:function.resultUnusedwith the declaration analysed or not, transitively pure functions, a list of files, the result cache, and the named-argument ruleCollectedDataEmitterCollectorTest: a collector emitting data for another collectorno-config-paths_test.sh: a list of files withoutpathsin the configuratione2e/fix-ignored-entries:--fix-ignoredwith a list of filesOn
2.3.x, 11 of the new e2e tests fail andCollectedDataEmitterCollectorTestdoesn't load;e2e/bug-15659passes there, as #7044 and #7046 fixed case 1, and fails before #7044.Closes phpstan/phpstan#14480
Closes phpstan/phpstan#15704
Refs phpstan/phpstan#15659: case 1 was fixed by #7044 and #7046, and this adds its e2e test. Case 2 is not fixed: a rule on
CollectedDataNodewith a fix still cannot tell a run of a part of the configuredpaths, likeanalyse src --fix, from a full one. Paths on the command line replace the configured ones rather than select a part of them, so PHPStan cannot know whether a run covers the whole project; that is the same question as phpstan/phpstan#14506.