-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing fix mode options and test cases (#5987)
- Add missing fix mode options for: CLANG_FORMAT, ENV, GOOGLE_JAVA_FORMAT, NATURAL_LANGUAGE, PYTHON_ISORT, RUST_CLIPPY. - Refactor linter tests to make them shorter because there's no need to have big test files. - Refactor 'bad' linter tests for linters that support fix mode so they contain only automatically fixable issues. This is needed to avoid adding another set of 'bad' linter tests for fix mode. - Provide configuration files for linters that support fix mode and for which the default configuration is not suitable to enable fix mode: ansible-lint, ESLint, golangci-lint. - Add a test case for linter commands options for linters that support fix mode, to ensure that fix mode and check-only mode options have been defined. - Refactor the fix mode test to check if linters actually applied modifications to files. - Update documentation about adding test cases for linters that support fix mode. - Don't exit with a fatal error if VALIDATE_xxx is false when testing fix mode because not all linters support fix mode. To enable this, set the new FIX_MODE_TEST_CASE_RUN variable to true.
- Loading branch information
1 parent
ea16cd9
commit 91dc6d7
Showing
41 changed files
with
594 additions
and
711 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
env: | ||
browser: true | ||
es6: true | ||
jest: true | ||
node: true | ||
|
||
extends: | ||
- "eslint:recommended" | ||
|
||
ignorePatterns: | ||
- "!.*" | ||
- "**/node_modules/.*" | ||
|
||
parser: '@typescript-eslint/parser' | ||
|
||
plugins: | ||
- '@typescript-eslint' | ||
|
||
# Don't set the jsonSyntax parser option for JSON, JSON5, and JSONC | ||
# so we can use eslint-plugin-jsonc to automatically fix issues | ||
# in tests, otherwise ESLint reports parsing errors and stops | ||
overrides: | ||
- files: | ||
- "*.json" | ||
extends: | ||
- plugin:jsonc/recommended-with-json | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.jsonc" | ||
extends: | ||
- plugin:jsonc/recommended-with-jsonc | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.json5" | ||
extends: | ||
- plugin:jsonc/recommended-with-json5 | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.jsx" | ||
- "*.tsx" | ||
extends: | ||
- plugin:react/recommended | ||
... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
# This file is only used in tests | ||
# TODO: move in a dedicated directory in test/linters-config | ||
linters: | ||
enable: | ||
- gofmt | ||
... |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
# Default log level | ||
# shellcheck disable=SC2034 | ||
LOG_LEVEL="DEBUG" | ||
|
||
# shellcheck source=/dev/null | ||
source "lib/functions/log.sh" | ||
|
||
# shellcheck source=/dev/null | ||
source "test/testUtils.sh" | ||
|
||
# The sqlfluff command needs this, but we don't want to make this test | ||
# dependant on other files | ||
# shellcheck disable=SC2034 | ||
SQLFLUFF_LINTER_RULES="SQLFLUFF_LINTER_RULES" | ||
|
||
# shellcheck source=/dev/null | ||
source "lib/globals/linterCommandsOptions.sh" | ||
|
||
LanguagesWithFixModeTest() { | ||
local FUNCTION_NAME | ||
FUNCTION_NAME="${FUNCNAME[0]}" | ||
info "${FUNCTION_NAME} start" | ||
|
||
for LANGUAGE in "${LANGUAGES_WITH_FIX_MODE[@]}"; do | ||
local FIX_MODE_OPTIONS_VARIABLE_NAME="${LANGUAGE}_FIX_MODE_OPTIONS" | ||
local CHECK_ONLY_MODE_OPTIONS_VARIABLE_NAME="${LANGUAGE}_CHECK_ONLY_MODE_OPTIONS" | ||
if [[ -v "${FIX_MODE_OPTIONS_VARIABLE_NAME}" ]] || | ||
[[ -v "${CHECK_ONLY_MODE_OPTIONS_VARIABLE_NAME}" ]]; then | ||
debug "${LANGUAGE} has check-only mode or fix mode options as expected" | ||
else | ||
fatal "${LANGUAGE} is in the list of languages that support fix mode, but neither check-only mode, nor fix mode options were found" | ||
fi | ||
done | ||
|
||
notice "${FUNCTION_NAME} PASS" | ||
} | ||
|
||
LanguagesWithFixModeTest |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
# Customize the ansible-lint configuration file because fix mode needs the | ||
# yaml rule not to be disabled, but we disable the yaml rule in the default | ||
# ansible-lint configuration | ||
parseable: true | ||
quiet: true | ||
use_default_rules: true | ||
verbosity: 1 | ||
... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
env: | ||
browser: true | ||
es6: true | ||
jest: true | ||
node: true | ||
|
||
extends: | ||
- "eslint:recommended" | ||
|
||
ignorePatterns: | ||
- "!.*" | ||
- "**/node_modules/.*" | ||
|
||
parser: '@typescript-eslint/parser' | ||
|
||
plugins: | ||
- '@typescript-eslint' | ||
|
||
# Don't set the jsonSyntax parser option for JSON, JSON5, and JSONC | ||
# so we can use eslint-plugin-jsonc to automatically fix issues | ||
# in tests, otherwise ESLint reports parsing errors and stops | ||
overrides: | ||
- files: | ||
- "*.json" | ||
extends: | ||
- plugin:jsonc/recommended-with-json | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.jsonc" | ||
extends: | ||
- plugin:jsonc/recommended-with-jsonc | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.json5" | ||
extends: | ||
- plugin:jsonc/recommended-with-json5 | ||
parser: jsonc-eslint-parser | ||
- files: | ||
- "*.jsx" | ||
- "*.tsx" | ||
extends: | ||
- plugin:react/recommended | ||
... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
linters: | ||
enable: | ||
- gofmt | ||
... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
--- | ||
- name: Remove temp files | ||
become: true | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
with_items: | ||
- "/tmp/test-1" | ||
- name: Test playbook | ||
hosts: all | ||
tasks: | ||
- name: Remove temp files | ||
become: true | ||
file: | ||
path: "{{ item }}" | ||
state: absent | ||
with_items: | ||
- "/tmp/test-1" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
path: "{{ item }}" | ||
state: absent | ||
with_items: | ||
- "/tmp/test-1" | ||
- /tmp/test-1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
if len(in) == 0 { | ||
return "", fmt.Errorf("Input is empty") | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("hello world") | ||
} |
Oops, something went wrong.