-
-
Notifications
You must be signed in to change notification settings - Fork 47
Quote strings that contain :
#284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,11 @@ | |
| from io import StringIO | ||
| from typing import Any, Callable, List, Match, Optional, Tuple | ||
|
|
||
| from ruyaml.comments import CommentedMap, CommentedSeq | ||
| from ruyaml.main import YAML | ||
| from ruyaml.nodes import MappingNode, Node, ScalarNode, SequenceNode | ||
| from ruyaml.representer import RoundTripRepresenter | ||
| from ruyaml.scalarstring import DoubleQuotedScalarString, SingleQuotedScalarString | ||
| from ruyaml.tokens import CommentToken | ||
|
|
||
| from yamlfix.model import YamlfixConfig, YamlNodeStyle | ||
|
|
@@ -379,12 +381,27 @@ def _ruamel_yaml_fixer(self, source_code: str) -> str: | |
| # Return the output to a string | ||
| string_stream = StringIO() | ||
| for source_dict in source_dicts: | ||
| self._quote_gha_container_volumes(source_dict) | ||
| self.yaml.dump(source_dict, string_stream) | ||
| source_code = string_stream.getvalue() | ||
| string_stream.close() | ||
|
|
||
| return source_code.strip() | ||
|
|
||
| def _quote_gha_container_volumes( | ||
| self, source_dict: CommentedMap | CommentedSeq | ||
| ) -> None: | ||
| """Quote jobs.*.container.volumes entries.""" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the phrasing of the docstring confusing. Wouldn't it be clearer something like I'd add an example of what this function fixes (the one in the issue is just fine) I'd also change the name of the method, as it's not specific to gha_container_volumes, there may be other strings with colons that will benefit from this method |
||
| if not isinstance(source_dict, CommentedMap): | ||
| return | ||
| scalar_type = SingleQuotedScalarString | ||
| if self.config.quote_representation == '"': | ||
| scalar_type = DoubleQuotedScalarString | ||
| for job in source_dict.get("jobs", {}).values(): | ||
| if volumes := job.get("container", {}).get("volumes", []): | ||
| for i, _ in enumerate(volumes): | ||
| volumes[i] = scalar_type(volumes[i]) | ||
|
|
||
| @staticmethod | ||
| def _fix_top_level_lists(source_code: str) -> str: | ||
| """Deindent the source with a top level list. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say this is a feature, but a fix for an unexpected behavior, isn't it? If you agree I'd remove this line