Repository navigation
Match applies_to_file_regex / exclude_file_regex against the scan-relative path in devskim analyze - #798
Draft
Giulia Stocco (gfs) with Copilot wants to merge 3 commits into
Draft
Match applies_to_file_regex / exclude_file_regex against the scan-relative path in devskim analyze#798Giulia Stocco (gfs) with Copilot wants to merge 3 commits into
applies_to_file_regex / exclude_file_regex against the scan-relative path in devskim analyze#798Giulia Stocco (gfs) with Copilot wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
…elative path Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate file regex behavior in DevSkim analysis
Match Oct 27, 2026
applies_to_file_regex / exclude_file_regex against the scan-relative path in devskim analyze
This branch has not been deployed
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.
devskim analyzematched a custom rule's file regexes against the bare file name only, so a pattern that names a directory never matched:With this rule,
project/tests/e2e/fixtures/prepare-ner.pywas still reported.This is an oversight dating from the move to the Application Inspector engine (#390), not a regression.
AnalyzeCommandpassedfileEntry.NametoDevSkimRuleProcessor.Analyze, which wraps it in a newFileEntry. AI matches these regexes againstFileEntry.FullPath, so it only ever saw the file name. The older engine had no file-regex fields at all.Changes
AnalyzeCommand: passesGetPathForFileRegexes(scanPath, fileEntry)instead offileEntry.Name:project/tests/e2e/fixtures/prepare-ner.py.--crawl-archives: each entry's path inside the archive./, on every OS, so one pattern works everywhere.--base-path/--absolute-pathstill affect only output, not matching.DevSkimRuleProcessor.Analyze: XML doc comment explaining thatfileNameis what the file regexes are matched against. No behaviour change.AnalyzeTest.cs): cover the reporter's case, start-anchored patterns, a directory-scopedapplies_to_file_regex, file-name patterns, and the helper's/output and single-file case.1.0.102.Behaviour change for custom rules
Patterns now see the whole relative path:
project/tests/project/tests/^prepare-ner\.py$test(exclude)testtests/,latest/, ….*\.config$(default rules)To match only the file name, anchor the pattern to the last segment, e.g.
(^|/)prepare-ner\.py$.Notes for reviewers
exclude_file_regexscope: it only filters rules selected throughapplies_to_file_regex. A rule still runs on files matching itsapplies_tolanguages, and on every file if it sets neither field. This is existing AI behaviour, noted in the changelog but not changed here...fromFileEntry.FullPathbut not from the scan path. If the scanned path contains a name likev1..2, the relative path starts with../and start-anchored patterns won't match. Falling back tofileEntry.Namein that case would fix it; it is left as is here.