Skip to content

Commit aeb043e

Browse files
authored
feat: add options to the prettier command (#6882)
Support passing options to the prettier command, regardless of the language. Close #6772
1 parent e2ac8dd commit aeb043e

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ You can configure Super-linter using the following environment variables:
303303
| **PHP_CONFIG_FILE** | `php.ini` | Filename for [PHP Configuration](https://www.php.net/manual/en/configuration.file.php) (ex: `php.ini`) |
304304
| **PHP_PHPCS_FILE_NAME** | `phpcs.xml` | Filename for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) (ex: `.phpcs.xml`, `.phpcs.xml.dist`) |
305305
| **PHP_PHPSTAN_CONFIG_FILE** | `phpstan.neon` | Filename for [PHPStan Configuration](https://phpstan.org/config-reference) (ex: `phpstan.neon`) |
306+
| **PRETTIER_COMMAND_OPTIONS** | not set | Additional options and arguments to add to the command when running Prettier. These options will be added to all Prettier invocations, regardless of the LANGUAGE. |
306307
| **PROTOBUF_CONFIG_FILE** | `.protolintrc.yml` | Filename for [protolint configuration](https://github.com/yoheimuta/protolint/blob/master/_example/config/.protolint.yaml) (ex: `.protolintrc.yml`) |
307308
| **PYTHON_BLACK_CONFIG_FILE** | `.python-black` | Filename for [black configuration](https://github.com/psf/black/blob/main/docs/guides/using_black_with_other_tools.md#black-compatible-configurations) (ex: `.isort.cfg`, `pyproject.toml`) |
308309
| **PYTHON_FLAKE8_CONFIG_FILE** | `.flake8` | Filename for [flake8 configuration](https://flake8.pycqa.org/en/latest/user/configuration.html) (ex: `.flake8`, `tox.ini`) |
@@ -314,7 +315,7 @@ You can configure Super-linter using the following environment variables:
314315
| **REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT** | `false` | If set to `true`, Super-linter removes ANSI color codes from linters stdout and stderr files, and from the Super-linter log file. |
315316
| **RUBY_CONFIG_FILE** | `.ruby-lint.yml` | Filename for [rubocop configuration](https://docs.rubocop.org/rubocop/configuration.html) (ex: `.ruby-lint.yml`, `.rubocop.yml`) |
316317
| **RUN_LOCAL** | `false` | Set this to `true` when running outside GitHub Actions or when you want to disable getting environment information from the GitHub Actions environment. For more information about running Super-linter outside GitHub Actions, see [Run Super-Linter outside GitHub Actions](#run-super-linter-outside-github-actions). |
317-
| **RUST_CLIPPY_COMMAND_OPTIONS** | not set | Additional options and arguments to pass to the command when running Clippy. |
318+
| **RUST_CLIPPY_COMMAND_OPTIONS** | not set | Additional options and arguments to add to the command when running Clippy. |
318319
| **SAVE_SUPER_LINTER_OUTPUT** | `false` | If set to `true`, Super-linter will save its output in the workspace. For more information, see [Super-linter outputs](#super-linter-outputs). |
319320
| **SAVE_SUPER_LINTER_SUMMARY** | `false` | If set to `true`, Super-linter will save a summary. For more information, see [Summary outputs](#summary-outputs). |
320321
| **SCALAFMT_CONFIG_FILE** | `.scalafmt.conf` | Filename for [scalafmt configuration](https://scalameta.org/scalafmt/docs/configuration.html) (ex: `.scalafmt.conf`) |

lib/functions/linterCommands.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ AddOptionsToCommand() {
9595

9696
# These commands are reused across several languages
9797
PRETTIER_COMMAND=(prettier)
98+
if [ -n "${PRETTIER_COMMAND_OPTIONS:-}" ]; then
99+
export PRETTIER_COMMAND_OPTIONS
100+
if ! AddOptionsToCommand "PRETTIER_COMMAND" "${PRETTIER_COMMAND_OPTIONS}"; then
101+
fatal "Error while adding options to Prettier command"
102+
fi
103+
fi
104+
98105
DOTNET_FORMAT_COMMAND=(dotnet format)
99106

100107
LINTER_COMMANDS_ARRAY_ANSIBLE=(ansible-lint -c "${ANSIBLE_LINTER_RULES}")

test/lib/linterCommandsTest.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ BASE_LINTER_COMMANDS_ARRAY_GO_MODULES=("${LINTER_COMMANDS_ARRAY_GO_MODULES[@]}")
6464
BASE_LINTER_COMMANDS_ARRAY_JAVA=("${LINTER_COMMANDS_ARRAY_JAVA[@]}")
6565
BASE_LINTER_COMMANDS_ARRAY_JSCPD=("${LINTER_COMMANDS_ARRAY_JSCPD[@]}")
6666
BASE_LINTER_COMMANDS_ARRAY_PERL=("${LINTER_COMMANDS_ARRAY_PERL[@]}")
67+
BASE_LINTER_COMMANDS_ARRAY_PRETTIER=("${PRETTIER_COMMAND[@]}")
6768
BASE_LINTER_COMMANDS_ARRAY_RUST_CLIPPY=("${LINTER_COMMANDS_ARRAY_RUST_CLIPPY[@]}")
6869
BASE_LINTER_COMMANDS_ARRAY_XML=("${LINTER_COMMANDS_ARRAY_XML[@]}")
6970

@@ -413,6 +414,8 @@ CommandOptionsTest() {
413414
# shellcheck disable=SC2034
414415
local PERL_PERLCRITIC_OPTIONS="${ARGS_TO_ADD}"
415416
# shellcheck disable=SC2034
417+
local PRETTIER_COMMAND_OPTIONS="${ARGS_TO_ADD}"
418+
# shellcheck disable=SC2034
416419
local RUST_CLIPPY_COMMAND_OPTIONS="${ARGS_TO_ADD}"
417420

418421
# Source the file again so it accounts for modifications
@@ -450,6 +453,13 @@ CommandOptionsTest() {
450453
fatal "${FUNCTION_NAME} test failed"
451454
fi
452455

456+
# shellcheck disable=SC2034
457+
local EXPECTED_LINTER_COMMANDS_ARRAY_PRETTIER=("${BASE_LINTER_COMMANDS_ARRAY_PRETTIER[@]}")
458+
AddOptionsToCommand "EXPECTED_LINTER_COMMANDS_ARRAY_PRETTIER" "${PRETTIER_COMMAND_OPTIONS}"
459+
if ! AssertArraysElementsContentMatch "PRETTIER_COMMAND" "EXPECTED_LINTER_COMMANDS_ARRAY_PRETTIER"; then
460+
fatal "${FUNCTION_NAME} test failed"
461+
fi
462+
453463
# shellcheck disable=SC2034
454464
local EXPECTED_LINTER_COMMANDS_ARRAY_RUST_CLIPPY=("${BASE_LINTER_COMMANDS_ARRAY_RUST_CLIPPY[@]}")
455465
AddOptionsToCommand "EXPECTED_LINTER_COMMANDS_ARRAY_RUST_CLIPPY" "${RUST_CLIPPY_COMMAND_OPTIONS}"

0 commit comments

Comments
 (0)