mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-21 13:41:19 -05:00
feat: implement a linter to check git conflicts (#6113)
Implement a linter to check if files contain Git conflict markers or whitespace errors.
This commit is contained in:
parent
94920ffcc7
commit
e0d8b4fb2f
19 changed files with 230 additions and 171 deletions
|
@ -67,6 +67,16 @@
|
|||
"source": "${localWorkspaceFolder}/dependencies/package-lock.json",
|
||||
"target": "/package-lock.json",
|
||||
"type": "bind"
|
||||
},
|
||||
{
|
||||
"source": "${localWorkspaceFolder}/scripts/bash-exec.sh",
|
||||
"target": "/usr/bin/bash-exec",
|
||||
"type": "bind"
|
||||
},
|
||||
{
|
||||
"source": "${localWorkspaceFolder}/scripts/git-merge-conflict-markers.sh",
|
||||
"target": "/usr/bin/git-merge-conflict-markers",
|
||||
"type": "bind"
|
||||
}
|
||||
],
|
||||
"runArgs": ["--env-file", ".devcontainer/devcontainer.env"]
|
||||
|
|
|
@ -383,10 +383,11 @@ COPY --from=python-builder /venvs /venvs
|
|||
#################
|
||||
COPY --from=lintr-installer /usr/lib/R /usr/lib/R
|
||||
|
||||
#####################
|
||||
# Install Bash-Exec #
|
||||
#####################
|
||||
##########################################
|
||||
# Install linters implemented as scripts #
|
||||
##########################################
|
||||
COPY --chmod=555 scripts/bash-exec.sh /usr/bin/bash-exec
|
||||
COPY --chmod=555 scripts/git-merge-conflict-markers.sh /usr/bin/git-merge-conflict-markers
|
||||
|
||||
#########################
|
||||
# Install dotenv-linter #
|
||||
|
|
2
Makefile
2
Makefile
|
@ -151,6 +151,8 @@ open-shell-super-linter-container: ## Open a shell in the Super-linter container
|
|||
-v "$(CURDIR)/dependencies/Gemfile":/Gemfile \
|
||||
-v "$(CURDIR)/dependencies/package-lock.json":/package-lock.json \
|
||||
-v "$(CURDIR)/dependencies/package.json":/package.json \
|
||||
-v "$(CURDIR)/scripts/bash-exec.sh":/usr/bin/bash-exec \
|
||||
-v "$(CURDIR)/scripts/git-merge-conflict-markers.sh":/usr/bin/git-merge-conflict-markers \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: validate-container-image-labels
|
||||
|
|
|
@ -69,6 +69,7 @@ Super-linter supports the following tools:
|
|||
| **EditorConfig** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | |
|
||||
| **.env** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | |
|
||||
| **Gherkin** | [gherkin-lint](https://github.com/vsiakka/gherkin-lint) | |
|
||||
| **Git merge conflict markers** | [Git conflict markers presence in files](https://git-scm.com/docs/git-config#Documentation/git-config.txt-mergeconflictStyle) | N/A |
|
||||
| **GitHub Actions** | [actionlint](https://github.com/rhysd/actionlint) | See YAML formatters |
|
||||
| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | |
|
||||
| **GoReleaser** | [GoReleaser](https://github.com/goreleaser/goreleaser) | See YAML formatters |
|
||||
|
@ -95,7 +96,7 @@ Super-linter supports the following tools:
|
|||
| **Python3** | [pylint](https://pylint.pycqa.org/), [flake8](https://flake8.pycqa.org/en/latest/), [isort](https://pypi.org/project/isort/), [ruff](https://github.com/astral-sh/ruff) | [black](https://github.com/psf/black), [pyink](https://github.com/google/pyink) |
|
||||
| **R** | [lintr](https://github.com/jimhester/lintr) | |
|
||||
| **Raku** | [Raku](https://raku.org) | |
|
||||
| **Renovate** | [renovate-config-validator](https://docs.renovatebot.com/config-validation/) | N/A |
|
||||
| **Renovate** | [renovate-config-validator](https://docs.renovatebot.com/config-validation/) | See JSON formatters |
|
||||
| **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | |
|
||||
| **Rust** | [Clippy](https://github.com/rust-lang/rust-clippy) | [Rustfmt](https://github.com/rust-lang/rustfmt) |
|
||||
| **Scala** | | [scalafmt](https://github.com/scalameta/scalafmt) |
|
||||
|
@ -339,6 +340,7 @@ You can configure Super-linter using the following environment variables:
|
|||
| **VALIDATE_EDITORCONFIG** | `true` | Flag to enable or disable the linting process with the EditorConfig. |
|
||||
| **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the ENV language. |
|
||||
| **VALIDATE_GHERKIN** | `true` | Flag to enable or disable the linting process of the Gherkin language. |
|
||||
| **VALIDATE_GIT_MERGE_CONFLICT_MARKERS** | `true` | Option to enable or disable checking if files contain Git merge conflict markers. |
|
||||
| **VALIDATE_GITHUB_ACTIONS** | `true` | Flag to enable or disable the linting process of the GitHub Actions. |
|
||||
| **VALIDATE_GITLEAKS** | `true` | Flag to enable or disable the linting process of the secrets. |
|
||||
| **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the individual Golang files. Set this to `false` if you want to lint Go modules. See the `VALIDATE_GO_MODULES` variable. |
|
||||
|
|
|
@ -157,6 +157,7 @@ new tool, it should include:
|
|||
Example: `ANSIBLE_FIX_MODE_OPTIONS=(--fix)`
|
||||
|
||||
- Provide the logic to populate the list of files or directories to examine: `lib/functions/buildFileList.sh`
|
||||
- Provide the logic to populate the versions file: `scripts/linterVersions.sh`
|
||||
- If necessary, provide elaborate logic to detect if the tool should examine a file or a directory: `lib/functions/detectFiles.sh`
|
||||
- If the tool needs to take into account special cases, reach out to the
|
||||
maintainers by creating a draft pull request and ask relevant questions
|
||||
|
|
|
@ -296,6 +296,7 @@ BuildFileArrays() {
|
|||
debug "Don't include ${FILE} in the list of files to lint with editorconfig-checker because the workspace doesn't contain an EditorConfig file: ${EDITORCONFIG_FILE_PATH}"
|
||||
fi
|
||||
|
||||
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-GIT_MERGE_CONFLICT_MARKERS"
|
||||
echo "${FILE}" >>"${FILE_ARRAYS_DIRECTORY_PATH}/file-array-GITLEAKS"
|
||||
|
||||
if IsAnsibleDirectory "${FILE}"; then
|
||||
|
|
|
@ -68,6 +68,7 @@ if [ -n "${GITLEAKS_LOG_LEVEL:-}" ]; then
|
|||
fi
|
||||
LINTER_COMMANDS_ARRAY_GITLEAKS+=(--source)
|
||||
LINTER_COMMANDS_ARRAY_GHERKIN=(gherkin-lint -c "${GHERKIN_LINTER_RULES}")
|
||||
LINTER_COMMANDS_ARRAY_GIT_MERGE_CONFLICT_MARKERS=(git-merge-conflict-markers)
|
||||
LINTER_COMMANDS_ARRAY_GO=(golangci-lint run -c "${GO_LINTER_RULES}" --fast)
|
||||
LINTER_COMMANDS_ARRAY_GO_MODULES=(golangci-lint run --allow-parallel-runners -c "${GO_LINTER_RULES}")
|
||||
LINTER_COMMANDS_ARRAY_GO_RELEASER=(goreleaser check)
|
||||
|
|
|
@ -13,7 +13,9 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT'
|
|||
'EDITORCONFIG'
|
||||
'ENV'
|
||||
'GITHUB_ACTIONS'
|
||||
'GITLEAKS' 'GHERKIN' 'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT'
|
||||
'GITLEAKS' 'GHERKIN'
|
||||
"GIT_MERGE_CONFLICT_MARKERS"
|
||||
'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT'
|
||||
"GRAPHQL_PRETTIER"
|
||||
'GROOVY'
|
||||
'HTML'
|
||||
|
|
19
scripts/git-merge-conflict-markers.sh
Executable file
19
scripts/git-merge-conflict-markers.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
GIT_MERGE_CONFLICT_EXPRESSION='^(<<<<<<<|=======|>>>>>>>)'
|
||||
|
||||
if [[ "$*" == "--version" ]]; then
|
||||
echo "1.0.0"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if grep -l -E "${GIT_MERGE_CONFLICT_EXPRESSION}" "$@"; then
|
||||
echo "Found Git merge conflict markers"
|
||||
exit 1
|
||||
else
|
||||
echo "No merge conflicts found in $*"
|
||||
fi
|
|
@ -24,6 +24,7 @@ LINTER_NAMES_ARRAY['ENV']="dotenv-linter"
|
|||
LINTER_NAMES_ARRAY['GITHUB_ACTIONS']="actionlint"
|
||||
LINTER_NAMES_ARRAY['GITLEAKS']="gitleaks"
|
||||
LINTER_NAMES_ARRAY['GHERKIN']="gherkin-lint"
|
||||
LINTER_NAMES_ARRAY['GIT_MERGE_CONFLICT_MARKERS']="git-merge-conflict-markers"
|
||||
LINTER_NAMES_ARRAY['GO']="golangci-lint"
|
||||
LINTER_NAMES_ARRAY['GO_MODULES']="${LINTER_NAMES_ARRAY['GO']}"
|
||||
LINTER_NAMES_ARRAY['GO_RELEASER']="goreleaser"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<!-- textlint-disable terminology -->
|
||||
|
||||
| Language | Validation result |
|
||||
| ---------------------- | ----------------- |
|
||||
| -------------------------- | ----------------- |
|
||||
| ANSIBLE | Fail ❌ |
|
||||
| BASH | Fail ❌ |
|
||||
| BASH_EXEC | Fail ❌ |
|
||||
|
@ -22,6 +22,7 @@
|
|||
| GITHUB_ACTIONS | Fail ❌ |
|
||||
| GITLEAKS | Fail ❌ |
|
||||
| GHERKIN | Fail ❌ |
|
||||
| GIT_MERGE_CONFLICT_MARKERS | Fail ❌ |
|
||||
| GO | Fail ❌ |
|
||||
| GO_MODULES | Fail ❌ |
|
||||
| GO_RELEASER | Fail ❌ |
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
| GITHUB_ACTIONS | Fail ❌ |
|
||||
| GITLEAKS | Fail ❌ |
|
||||
| GHERKIN | Fail ❌ |
|
||||
| GIT_MERGE_CONFLICT_MARKERS | Fail ❌ |
|
||||
| GO | Fail ❌ |
|
||||
| GO_MODULES | Fail ❌ |
|
||||
| GO_RELEASER | Fail ❌ |
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<!-- textlint-disable terminology -->
|
||||
|
||||
| Language | Validation result |
|
||||
| ---------------------- | ----------------- |
|
||||
| -------------------------- | ----------------- |
|
||||
| ANSIBLE | Pass ✅ |
|
||||
| BASH | Pass ✅ |
|
||||
| BASH_EXEC | Pass ✅ |
|
||||
|
@ -22,6 +22,7 @@
|
|||
| GITHUB_ACTIONS | Pass ✅ |
|
||||
| GITLEAKS | Pass ✅ |
|
||||
| GHERKIN | Pass ✅ |
|
||||
| GIT_MERGE_CONFLICT_MARKERS | Pass ✅ |
|
||||
| GO | Pass ✅ |
|
||||
| GO_MODULES | Pass ✅ |
|
||||
| GO_RELEASER | Pass ✅ |
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
| GITHUB_ACTIONS | Pass ✅ |
|
||||
| GITLEAKS | Pass ✅ |
|
||||
| GHERKIN | Pass ✅ |
|
||||
| GIT_MERGE_CONFLICT_MARKERS | Pass ✅ |
|
||||
| GO | Pass ✅ |
|
||||
| GO_MODULES | Pass ✅ |
|
||||
| GO_RELEASER | Pass ✅ |
|
||||
|
|
|
@ -162,6 +162,7 @@ control "super-linter-installed-commands" do
|
|||
{ linter_name: "eslint"},
|
||||
{ linter_name: "flake8"},
|
||||
{ linter_name: "gherkin-lint", expected_exit_status: 1}, # expect a return code = 1 because this linter doesn't support a "get linter version" command
|
||||
{ linter_name: "git-merge-conflict-markers"},
|
||||
{ linter_name: "gitleaks", version_option: "version"},
|
||||
{ linter_name: "golangci-lint"},
|
||||
{ linter_name: "goreleaser"},
|
||||
|
@ -526,6 +527,8 @@ control "super-linter-validate-files" do
|
|||
"/action/lib/.automation/phpcs.xml",
|
||||
"/action/lib/.automation/phpstan.neon",
|
||||
"/action/lib/.automation/psalm.xml",
|
||||
"/usr/bin/bash-exec",
|
||||
"/usr/bin/git-merge-conflict-markers",
|
||||
"/usr/bin/helm", # needed for checkov's helm framework
|
||||
"/usr/bin/kustomize", # needed for checkov's kustomize checks
|
||||
]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<<<<<<< HEAD:file.txt
|
||||
Hello world 1
|
||||
=======
|
||||
Goodbye 1
|
||||
>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
|
|
@ -0,0 +1,5 @@
|
|||
<<<<<<< HEAD:file.txt
|
||||
Hello world 2
|
||||
=======
|
||||
Goodbye 2
|
||||
>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
|
|
@ -0,0 +1 @@
|
|||
Hello world 1
|
|
@ -0,0 +1 @@
|
|||
Hello world 2
|
Loading…
Reference in a new issue