diff --git a/.gersemirc.example b/.gersemirc.example index 10595b7..4a91ffd 100644 --- a/.gersemirc.example +++ b/.gersemirc.example @@ -7,6 +7,6 @@ indent: 4 line_length: 80 list_expansion: favour-inlining quiet: false -require_definitions: true unsafe: false +warn_about_unknown_commands: true workers: 8 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b87ee..52044cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # Changelog +## [0.15.0] 2024-08-04 +### Added +- cache can be disabled through `--no-cache`/`cache: false`, cache is still enabled by default +- warnings about unknown commands can be suppressed through `--no-warn-about-unknown-commands`/`warn_about_unknown_commands: false`, warnings are enabled by default + +### Fixed +- only those files that were checked or formatted without warning will be cached + ## [0.14.0] 2024-07-15 ### Added - warnings about unknown commands when `quiet` isn't used diff --git a/README.md b/README.md index ee7fa69..0089259 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ usage: gersemi [-c] [-i] [--diff] [--default-config] [--version] [-h] [-l INTEGE [--indent (INTEGER | tabs)] [--unsafe] [-q] [--color] [--definitions src [src ...]] [--list-expansion {favour-inlining,favour-expansion}] [-w INTEGER] - [--cache] [--require-definitions] + [--cache] [--warn-about-unknown-commands] [src ...] A formatter to make your CMake code the real treasure. @@ -75,13 +75,11 @@ configuration: --cache, --no-cache Enables cache with data about files that are known to be formatted to speed up execution. [default: cache enabled] - --require-definitions, --no-require-definitions - Require definitions of custom commands. When enabled file which - has unknown custom commands will have warnings issued about - that and result won't be cached. When disabled it will be - assumed that original formatting of unknown command is the - correct one. See: "Let's make a deal" section in README. - [default: definitions are required] + --warn-about-unknown-commands, --no-warn-about-unknown-commands + When enabled file which has unknown custom commands will have + warnings issued about that and result won't be cached. + See: "Let's make a deal" section in README. + [default: warnings enabled] ``` ### [pre-commit](https://pre-commit.com/) hook @@ -91,7 +89,7 @@ You can use gersemi with a pre-commit hook by adding the following to `.pre-comm ```yaml repos: - repo: https://github.com/BlankSpruce/gersemi - rev: 0.14.0 + rev: 0.15.0 hooks: - id: gersemi ``` diff --git a/gersemi/__main__.py b/gersemi/__main__.py index ce9b5ba..54f77be 100644 --- a/gersemi/__main__.py +++ b/gersemi/__main__.py @@ -173,15 +173,15 @@ def create_argparser(): """, ) configuration_group.add_argument( - "--require-definitions", - "--no-require-definitions", - dest="require_definitions", + "--warn-about-unknown-commands", + "--no-warn-about-unknown-commands", + dest="warn_about_unknown_commands", action=ToggleAction, nargs=0, default=None, help=f""" - {conf_doc["require_definitions"]} - [default: definitions are required] + {conf_doc["warn_about_unknown_commands"]} + [default: warnings enabled] """, ) diff --git a/gersemi/__version__.py b/gersemi/__version__.py index 7fb6e44..b854693 100644 --- a/gersemi/__version__.py +++ b/gersemi/__version__.py @@ -4,4 +4,4 @@ __license__ = "MPL 2.0" __title__ = "gersemi" __url__ = "https://github.com/BlankSpruce/gersemi" -__version__ = "0.14.0" +__version__ = "0.15.0" diff --git a/gersemi/configuration.py b/gersemi/configuration.py index 71bce9f..9526074 100644 --- a/gersemi/configuration.py +++ b/gersemi/configuration.py @@ -171,17 +171,15 @@ class Configuration: # pylint: disable=too-many-instance-attributes ), ) - require_definitions: bool = field( + warn_about_unknown_commands: bool = field( default=True, metadata=dict( - title="Require definitions", + title="Warn about unknown commands", description=doc( """ - Require definitions of custom commands. When enabled - file which has unknown custom commands will have warnings - issued about that and result won't be cached. When disabled - it will be assumed that original formatting of unknown command - is the correct one. See: "Let's make a deal" section in README. + When enabled file which has unknown custom commands will have warnings + issued about that and result won't be cached. See: "Let's make a deal" + section in README. """ ), ), diff --git a/gersemi/configuration.schema.json b/gersemi/configuration.schema.json index 3878d38..8b2aace 100644 --- a/gersemi/configuration.schema.json +++ b/gersemi/configuration.schema.json @@ -89,10 +89,10 @@ "title": "Enable cache", "type": "boolean" }, - "require_definitions": { + "warn_about_unknown_commands": { "default": true, - "description": "Require definitions of custom commands. When enabled file which has unknown custom commands will have warnings issued about that and result won't be cached. When disabled it will be assumed that original formatting of unknown command is the correct one. See: \"Let's make a deal\" section in README.", - "title": "Require definitions", + "description": "When enabled file which has unknown custom commands will have warnings issued about that and result won't be cached. See: \"Let's make a deal\" section in README.", + "title": "Warn about unknown commands", "type": "boolean" } }, diff --git a/gersemi/runner.py b/gersemi/runner.py index e0c4c4b..edab54d 100644 --- a/gersemi/runner.py +++ b/gersemi/runner.py @@ -140,7 +140,7 @@ def consume_task_result( warnings = ( [w for w in task_result.warnings if not isinstance(w, UnknownCommandWarning)] - if not configuration.require_definitions + if not configuration.warn_about_unknown_commands else task_result.warnings ) diff --git a/tests/test_executable.py b/tests/test_executable.py index f67ca29..0e4c44d 100644 --- a/tests/test_executable.py +++ b/tests/test_executable.py @@ -905,9 +905,9 @@ def check_warnings(result, stderr): [ ((), False), (("--check",), True), - (("--require-definitions", "--check"), True), + (("--warn-about-unknown-commands", "--check"), True), (("--in-place",), True), - (("--require-definitions", "--in-place"), True), + (("--warn-about-unknown-commands", "--in-place"), True), (("--diff",), False), ], ) @@ -1035,7 +1035,7 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required( cmakelists = Path(target) / "CMakeLists.txt" without_definition = gersemi_( - *args, "--no-require-definitions", cmakelists, cwd=tmpdir + *args, "--no-warn-about-unknown-commands", cmakelists, cwd=tmpdir ) assert without_definition.returncode == 0, ( without_definition.returncode, @@ -1053,7 +1053,7 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required( inspector.assert_that_has_no_tables() cmakelists = Path(target) / "CMakeLists.txt" - with create_dot_gersemirc(where=target, require_definitions=False): + with create_dot_gersemirc(where=target, warn_about_unknown_commands=False): without_definition = gersemi_(*args, cmakelists, cwd=tmpdir) assert without_definition.returncode == 0, ( without_definition.returncode, @@ -1071,9 +1071,9 @@ def test_dont_warn_about_unknown_commands_when_definition_arent_required( inspector.assert_that_has_no_tables() cmakelists = Path(target) / "CMakeLists.txt" - with create_dot_gersemirc(where=target, require_definitions=True): + with create_dot_gersemirc(where=target, warn_about_unknown_commands=True): without_definition = gersemi_( - *args, "--no-require-definitions", cmakelists, cwd=tmpdir + *args, "--no-warn-about-unknown-commands", cmakelists, cwd=tmpdir ) assert without_definition.returncode == 0, ( without_definition.returncode,