diff --git a/.github/linters/.python-black b/.github/linters/.python-black new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index 549657d8..743756aa 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ But if you wish to select or exclude specific linters, we give you full control | **OUTPUT_DETAILS** | `simpler` | What level of details to be reported. Supported formats: simpler or detailed. | | **PYTHON_PYLINT_CONFIG_FILE** | `.python-lint` | Filename for [pylint configuration](http://pylint.pycqa.org/en/latest/user_guide/run.html?highlight=rcfile#command-line-options) (ex: `.python-lint`, `.pylintrc`) | | **PYTHON_FLAKE8_CONFIG_FILE** | `.flake8` | Filename for [flake8 configuration](https://flake8.pycqa.org/en/latest/user/configuration.html) (ex: `.flake8`, `tox.ini`) | +| **PYTHON_BLACK_CONFIG_FILE** | `.python-black` | Filename for [black configuration](https://github.com/psf/black/blob/master/docs/compatible_configs.md) (ex: `.isort.cfg`, `pyproject.toml`) | | **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) | | **TYPESCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [eslint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **VALIDATE_ALL_CODEBASE** | `true` | Will parse the entire repository and find all files to validate across all types. **NOTE:** When set to `false`, only **new** or **edited** files will be parsed for validation. | diff --git a/TEMPLATES/.python-black b/TEMPLATES/.python-black new file mode 100644 index 00000000..e69de29b diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 7a8d949b..16100f5d 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -948,7 +948,10 @@ var = "terrible code down here..." ### Black Config file -- There is no top level _configuration file_ available at this time +- `.github/linters/.python-black` + - You can pass multiple rules and overwrite default rules +- File should be located at: .github/linters/.python-black +- [Python Black compatible configurations](https://github.com/psf/black/blob/master/docs/compatible_configs.md) ### Black disable single line diff --git a/lib/linter.sh b/lib/linter.sh index 2b0030b3..8282bee8 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -110,6 +110,8 @@ PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}" PYTHON_PYLINT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_PYLINT_FILE_NAME}" # Path to the python lint rules PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}" # Name of the file PYTHON_FLAKE8_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_FLAKE8_FILE_NAME}" # Path to the python lint rules +PYTHON_BLACK_FILE_NAME="${PYTHON_BLACK_CONFIG_FILE:-.python-black}" # Name of the file +PYTHON_BLACK_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${PYTHON_BLACK_FILE_NAME}" # Path to the python lint rules # R Vars R_FILE_NAME='.lintr' # Name of the file R_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${R_FILE_NAME}" # Path to the R lint rules @@ -1278,6 +1280,8 @@ GetLinterRules "POWERSHELL" GetLinterRules "PYTHON_PYLINT" # Get Python flake8 rules GetLinterRules "PYTHON_FLAKE8" +# Get Python black rules +GetLinterRules "PYTHON_BLACK" # Get R rules GetLinterRules "R" # Get Ruby rules @@ -1777,7 +1781,7 @@ if [ "${VALIDATE_PYTHON_BLACK}" == "true" ]; then # Lint the python files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON_BLACK" "black" "black --diff --check" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_BLACK[@]}" + LintCodebase "PYTHON_BLACK" "black" "black --config ${PYTHON_BLACK_LINTER_RULES} --diff --check" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON_BLACK[@]}" fi ######################### diff --git a/lib/worker.sh b/lib/worker.sh index c6eb4ccd..dc0ad6cf 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -695,7 +695,7 @@ function RunTestCases() { TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell" TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf" - TestCodebase "PYTHON_BLACK" "black" "black --diff --check" ".*\.\(py\)\$" "python" + TestCodebase "PYTHON_BLACK" "black" "black --config ${PYTHON_BLACK_LINTER_RULES} --diff --check" ".*\.\(py\)\$" "python" TestCodebase "PYTHON_FLAKE8" "flake8" "flake8 --config ${PYTHON_FLAKE8_LINTER_RULES}" ".*\.\(py\)\$" "python" TestCodebase "PYTHON_PYLINT" "pylint" "pylint --rcfile ${PYTHON_PYLINT_LINTER_RULES}" ".*\.\(py\)\$" "python" TestCodebase "R" "lintr" "lintr::lint()" ".*\.\(r\|rmd\)\$" "r"