Skip to content
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

Only check for @generated-like markers in file header #2654

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"SHFMT",
"SNAKEFMT",
"SOQL",
"SOURCEFILEHEADER",
"SOURCEPATHS",
"SQLFLUFF",
"STDLIB",
Expand Down Expand Up @@ -1466,4 +1467,4 @@
"zaach",
"zricethezav"
]
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Core
- mega-linter-runner: Convert to ES6 and upgrade npm dependencies
- Add rust to checkov as it is a required dependency (to do that, allow to define empty string packages as cargo dependencies in descriptors)
- Optimize `@generated` marker scanning ([#2654](https://github.com/oxsecurity/megalinter/pull/2654))

- Media
- [Achieve Code Consistency: MegaLinter Integration in Azure DevOps](https://techcommunity.microsoft.com/t5/azure-devops-blog/achieve-code-consistency-megalinter-integration-in-azure-devops/ba-p/3939448), by [Don Koning](https://techcommunity.microsoft.com/t5/user/viewprofilepage/user-id/2039143#profile) on [Microsoft Tech Community](https://techcommunity.microsoft.com/)
Expand Down
9 changes: 5 additions & 4 deletions megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from megalinter import config
from megalinter.constants import DEFAULT_DOCKER_WORKSPACE_DIR

SIZE_MAX_SOURCEFILEHEADER = 1024
sanmai-NL marked this conversation as resolved.
Show resolved Hide resolved

REPO_HOME_DEFAULT = (
DEFAULT_DOCKER_WORKSPACE_DIR
if os.path.isdir(DEFAULT_DOCKER_WORKSPACE_DIR)
Expand Down Expand Up @@ -278,10 +280,9 @@ def file_contains(file_name: str, regex_object: Optional[Pattern[str]]) -> bool:


def file_is_generated(file_name: str) -> bool:
with open(file_name, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
is_generated = "@generated" in content and "@not-generated" not in content
return is_generated
with open(file_name, "rb") as f:
content = f.read(SIZE_MAX_SOURCEFILEHEADER)
sanmai-NL marked this conversation as resolved.
Show resolved Hide resolved
return b"@generated" in content and b"@not-generated" not in content


def decode_utf8(stdout):
Expand Down
Loading