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

Use .gitignore as .secretlintignore when necessary #1210

Merged
merged 2 commits into from
Jan 27, 2022
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
1 change: 1 addition & 0 deletions .automation/test/credentials/bad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yolooo/**
1 change: 1 addition & 0 deletions .automation/test/credentials/bad/.secretlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yalaaa/**
1 change: 1 addition & 0 deletions .automation/test/credentials/good/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yoooo/**
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Note: Can be used with `megalinter/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `megalinter/megalinter:beta` docker image

- New reporter **GITLAB_COMMENT_REPORTER** allowing to post MegaLinter results as comments on Gitlab merge requests
- secretlint: Use .gitignore as .secretlintignore if --secretlintignore is not defined and .secretlintignore not found ([#1207](https://github.com/megalinter/megalinter/issues/1207))
- Fix v5 doc deployment when there is a new release ([1190](https://github.com/megalinter/megalinter/issues/1190))
- Fix issue when using `VALIDATE_ALL_CODEBASE: false` on Azure Pipelines by defining auth header in CI env variable GIT_AUTHORIZATION_BEARER ([#1125](https://github.com/megalinter/megalinter/issues/1125))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ descriptor_flavors:
lint_all_files: true
linters:
# SECRETLINT
- linter_name: secretlint
- class: SecretLintLinter
linter_name: secretlint
linter_url: https://github.com/secretlint/secretlint
linter_repo: https://github.com/secretlint/secretlint
linter_banner_image_url: https://github.com/secretlint/secretlint/raw/main/docs/assets/SecretLintLP.png
Expand Down
22 changes: 22 additions & 0 deletions megalinter/linters/SecretLintLinter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""
Use secretlint to find secrets in sources
https://github.com/secretlint/secretlint
"""

import os

from megalinter import Linter


class SecretLintLinter(Linter):

# Called before linting files
def before_lint_files(self):
# Use .gitignore as .secretlintignore
# only if --secretlintignore is not defined and .secretlintignore not found
if "--secretlintignore" not in self.cli_lint_user_args and (
os.path.isfile(os.path.join(self.workspace, ".gitignore"))
and (not os.path.isfile(os.path.join(self.workspace, ".secretlintignore")))
):
self.cli_lint_extra_args += ["--secretlintignore", ".gitignore"]