Skip to content

Commit

Permalink
Update indentation logic to support non-whitespace characters (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytswd committed Sep 30, 2021
1 parent 5b30b85 commit cee3b7f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/marker/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func processIndentOption(marker *Marker, match *RawMarker) error {
case "extra":
marker.Indentation = &Indentation{Mode: ExtraIndentation}
case "align":
markerIndentation := len(match.PrecedingIndentation) - len(strings.TrimLeft(match.PrecedingIndentation, " ")) // Naïve count
markerIndentation := len(match.PrecedingIndentation)
marker.Indentation = &Indentation{
Mode: AlignIndentation,
MarkerIndentation: markerIndentation,
Expand Down
2 changes: 1 addition & 1 deletion internal/marker/marker_regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
ImporterMarkerMarkdown = `<!-- == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) == -->`

// ImporterMarkerYAML is the annotation used for importer to find match.
ImporterMarkerYAML = `(?P<importer_marker_indentation>\s*)# == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) ==`
ImporterMarkerYAML = `(?P<importer_marker_indentation>.*)# == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) ==`

// OptionFilePathIndicator is the pattern used for parsing Importer file options.
OptionFilePathIndicator = `from: (?P<importer_target_path>\S+)\s*\#(?P<importer_target_detail>[0-9a-zA-Z,-_\~]+)\s?`
Expand Down
2 changes: 1 addition & 1 deletion internal/marker/marker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestNewMarker(t *testing.T) {
IsEndFound: true,
LineToInsertAt: 3,
Options: "from: ./abc.yaml#[from-exporter-marker] indent: align",
PrecedingIndentation: " ",
PrecedingIndentation: " - ", // As if yaml list input is used for indentation
},
want: &marker.Marker{
Name: "simple-marker",
Expand Down
10 changes: 5 additions & 5 deletions testdata/yaml/align-with-exporter-before.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ data:
indentation:
for:
demo:
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
anything: here
would: be
purged: by Importer
# == importer: abc-tree / end ==
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
anything: here
would: be
purged: by Importer
# == importer: abc-tree / end ==

some-data:
description: |
Expand Down
4 changes: 2 additions & 2 deletions testdata/yaml/align-with-exporter-purged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ data:
indentation:
for:
demo:
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
# == importer: abc-tree / end ==
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
# == importer: abc-tree / end ==

some-data:
description: |
Expand Down
26 changes: 13 additions & 13 deletions testdata/yaml/align-with-exporter-updated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ data:
indentation:
for:
demo:
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
a:
b:
c:
d:
e:
f:
g:
h:
i:
j:
k: {}
# == importer: abc-tree / end ==
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
a:
b:
c:
d:
e:
f:
g:
h:
i:
j:
k: {}
# == importer: abc-tree / end ==

some-data:
description: |
Expand Down

0 comments on commit cee3b7f

Please sign in to comment.