-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x2cpg: extracted file exclusion by regex and file path #2741
Conversation
This lives in x2cpg now and may be used by all frontends. jssrc2cpg and c2cpg already made use of it. To all frontend maintainers: If your frontend should support file exclusion please use `def determine(inputPath: String, sourceFileExtensions: Set[String], config: X2CpgConfig[_]): List[String]` from `x2cpg.SourceFiles` to retrieve a file list for your extension(s) in the input path. `X2CpgConfig` provides three fields for the filter process: - `ignoredFilesRegex`: a regex that the user may supply via `--exclude-regex`. Filters out files or folders (the absolute file path is matched against the regex) - `ignoredFiles`: a list of files that the user may supply via `--exclude`. Filters out files or folders (paths relative to <input-dir> as well as absolute paths) - `defaultIgnoredFilesRegex`: a list of regex that the frontend maintainer may provide. Filters out files or folders (the absolute file path is matched against the regex) by default (e.g., unwanted test folders). `--exclude-regex` and `--exclude` are now available for all frontends making use of `X2Cpg.parseCommandLine`.
Why is the absolute used for the regex methods? This could lead to surprising (at least to me) results, for example when using a directory structure like Using the relative (to the project root) path when filtering would avoid this issue, while still giving users control over excluding files outside of the project dir by not providing those as input files. |
Yes, you are right. I will change this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! This is very useful for source-based frontends in general :-)
* x2cpg: extracted file exclusion by regex and file path This lives in x2cpg now and may be used by all frontends. jssrc2cpg and c2cpg already made use of it. To all frontend maintainers: If your frontend should support file exclusion please use `def determine(inputPath: String, sourceFileExtensions: Set[String], config: X2CpgConfig[_]): List[String]` from `x2cpg.SourceFiles` to retrieve a file list for your extension(s) in the input path. `X2CpgConfig` provides three fields for the filter process: - `ignoredFilesRegex`: a regex that the user may supply via `--exclude-regex`. Filters out files or folders (the absolute file path is matched against the regex) - `ignoredFiles`: a list of files that the user may supply via `--exclude`. Filters out files or folders (paths relative to <input-dir> as well as absolute paths) - `defaultIgnoredFilesRegex`: a list of regex that the frontend maintainer may provide. Filters out files or folders (the absolute file path is matched against the regex) by default (e.g., unwanted test folders). `--exclude-regex` and `--exclude` are now available for all frontends making use of `X2Cpg.parseCommandLine`. * Fix for review comment.
This lives in x2cpg now and may be used by all frontends. jssrc2cpg and c2cpg already made use of it.
To all frontend maintainers:
If your frontend should support file exclusion please use
def determine(inputPath: String, sourceFileExtensions: Set[String], config: X2CpgConfig[_]): List[String]
fromx2cpg.SourceFiles
to retrieve a file list for your extension(s) in the input path.X2CpgConfig
provides three fields for the filter process:ignoredFilesRegex
: a regex that the user may supply via--exclude-regex
. Filters out files or folders (path relative to the input is matched against the regex)ignoredFiles
: a list of files that the user may supply via--exclude
. Filters out files or folders (paths relative to the input dir as well as absolute paths)defaultIgnoredFilesRegex
: a list of regex that the frontend maintainer may provide. Filters out files or folders (path relative to the input is matched against the regex) by default (e.g., unwanted test folders).--exclude-regex
and--exclude
are now available for all frontends making use ofX2Cpg.parseCommandLine
.