markdown-merge 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +251 -0
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +134 -0
  6. data/CONTRIBUTING.md +227 -0
  7. data/FUNDING.md +74 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +1087 -0
  10. data/REEK +0 -0
  11. data/RUBOCOP.md +71 -0
  12. data/SECURITY.md +21 -0
  13. data/lib/markdown/merge/cleanse/block_spacing.rb +253 -0
  14. data/lib/markdown/merge/cleanse/code_fence_spacing.rb +294 -0
  15. data/lib/markdown/merge/cleanse/condensed_link_refs.rb +405 -0
  16. data/lib/markdown/merge/cleanse.rb +42 -0
  17. data/lib/markdown/merge/code_block_merger.rb +300 -0
  18. data/lib/markdown/merge/conflict_resolver.rb +128 -0
  19. data/lib/markdown/merge/debug_logger.rb +26 -0
  20. data/lib/markdown/merge/document_problems.rb +190 -0
  21. data/lib/markdown/merge/file_aligner.rb +196 -0
  22. data/lib/markdown/merge/file_analysis.rb +353 -0
  23. data/lib/markdown/merge/file_analysis_base.rb +629 -0
  24. data/lib/markdown/merge/freeze_node.rb +93 -0
  25. data/lib/markdown/merge/gap_line_node.rb +136 -0
  26. data/lib/markdown/merge/link_definition_formatter.rb +49 -0
  27. data/lib/markdown/merge/link_definition_node.rb +157 -0
  28. data/lib/markdown/merge/link_parser.rb +421 -0
  29. data/lib/markdown/merge/link_reference_rehydrator.rb +320 -0
  30. data/lib/markdown/merge/markdown_structure.rb +123 -0
  31. data/lib/markdown/merge/merge_result.rb +166 -0
  32. data/lib/markdown/merge/node_type_normalizer.rb +126 -0
  33. data/lib/markdown/merge/output_builder.rb +166 -0
  34. data/lib/markdown/merge/partial_template_merger.rb +334 -0
  35. data/lib/markdown/merge/smart_merger.rb +221 -0
  36. data/lib/markdown/merge/smart_merger_base.rb +621 -0
  37. data/lib/markdown/merge/table_match_algorithm.rb +504 -0
  38. data/lib/markdown/merge/table_match_refiner.rb +136 -0
  39. data/lib/markdown/merge/version.rb +12 -0
  40. data/lib/markdown/merge/whitespace_normalizer.rb +251 -0
  41. data/lib/markdown/merge.rb +149 -0
  42. data/lib/markdown-merge.rb +4 -0
  43. data/sig/markdown/merge.rbs +341 -0
  44. data.tar.gz.sig +0 -0
  45. metadata +365 -0
  46. metadata.gz.sig +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9acf350fe99fe21eb039f5b1921b67b3a34f69d02186ca64d5bd48ac73096819
4
+ data.tar.gz: 87ee2b867a12495e3e5d92ef17b1de91f946757ead984fe03c164921e3b14336
5
+ SHA512:
6
+ metadata.gz: 787b4f4719021199155ce78bcebfdecb42a33b883a809b1e17f93ffe88c844b007749cd8ceea6c3a9deabe3e0ad8e7dfcd0ffc78a1ced9683cd1a600a9b20693
7
+ data.tar.gz: 8d4787d8d2f882b51a2bd256da055654f42707c4ace34be07558908434ffced53ecc6d0c1ce2881daf44955e1e92aea7e02284e1ae9091af7316e8dce57946f9
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,251 @@
1
+ # Changelog
2
+
3
+ [![SemVer 2.0.0][📌semver-img]][📌semver] [![Keep-A-Changelog 1.0.0][📗keep-changelog-img]][📗keep-changelog]
4
+
5
+ All notable changes to this project will be documented in this file.
6
+
7
+ The format is based on [Keep a Changelog][📗keep-changelog],
8
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
9
+ and [yes][📌major-versions-not-sacred], platform and engine support are part of the [public API][📌semver-breaking].
10
+ Please file a bug if you notice a violation of semantic versioning.
11
+
12
+ [📌semver]: https://semver.org/spec/v2.0.0.html
13
+ [📌semver-img]: https://img.shields.io/badge/semver-2.0.0-FFDD67.svg?style=flat
14
+ [📌semver-breaking]: https://github.com/semver/semver/issues/716#issuecomment-869336139
15
+ [📌major-versions-not-sacred]: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html
16
+ [📗keep-changelog]: https://keepachangelog.com/en/1.0.0/
17
+ [📗keep-changelog-img]: https://img.shields.io/badge/keep--a--changelog-1.0.0-FFDD67.svg?style=flat
18
+
19
+ ## [Unreleased]
20
+
21
+ ### Added
22
+
23
+ ### Changed
24
+
25
+ ### Deprecated
26
+
27
+ ### Removed
28
+
29
+ ### Fixed
30
+
31
+ ### Security
32
+
33
+ ## [1.0.0] - 2026-01-19
34
+
35
+ - TAG: [v1.0.0][1.0.0t]
36
+ - COVERAGE: 91.43% -- 1803/1972 lines in 29 files
37
+ - BRANCH COVERAGE: 79.10% -- 579/732 branches in 29 files
38
+ - 96.92% documented
39
+
40
+ ### Added
41
+
42
+ - **Cleanse Module**: New namespace for document cleansing/repair utilities
43
+ - `Cleanse::CondensedLinkRefs` - Fixes condensed link reference definitions caused by previous merge bugs
44
+ - Parslet-based PEG parser (linear-time, ReDoS-safe) for detecting and expanding `[label]: url[label2]: url2` → separate lines
45
+ - Detects two corruption patterns: (1) multiple definitions on same line, (2) content before definition without newline
46
+ - Methods: `#condensed?`, `#expand`, `#definitions`, `#count`
47
+ - `Cleanse::CodeFenceSpacing` - Fixes malformed code fence language tags
48
+ - Fixes ` ``` console` → ` ```console` (removes space between backticks and language)
49
+ - Parslet-based PEG parser (linear-time, ReDoS-safe) for detecting code blocks and their info strings
50
+ - Supports any indentation level (handles code blocks nested in lists)
51
+ - Methods: `#malformed?`, `#malformed_count`, `#code_blocks`, `#fix`
52
+ - `Cleanse::BlockSpacing` - Fixes missing blank lines between block elements
53
+ - Detects and fixes missing blank lines after thematic breaks (`---`)
54
+ - Detects and fixes missing blank lines between list items and headings
55
+ - Detects and fixes missing blank lines between markdown and HTML blocks
56
+ - Detects and fixes missing blank lines before HTML when preceded by markdown
57
+ - Special handling for markdown container closing tags (e.g., `</details>`) - adds blank lines before them even when inside HTML blocks, since their content may be markdown
58
+ - Methods: `#malformed?`, `#issue_count`, `#issues`, `#fix`
59
+ - **Security Note**: `CondensedLinkRefs` and `CodeFenceSpacing` use PEG parsers instead of regex to eliminate ReDoS vulnerabilities. Both process untrusted Markdown input safely in O(n) time.
60
+ - **LinkParser tree-based nesting detection**:
61
+ - `#find_all_link_constructs(content)` - Returns tree structure with `:children` for nested items
62
+ - `#build_link_tree(links, images)` - Detects containment and builds parent-child relationships
63
+ - `#flatten_leaf_first(items)` - Flattens tree in post-order (children before parents) for safe replacement
64
+ - Properly handles linked images like `[![alt](img-url)](link-url)` as parent link with child image
65
+ - **`bin/fix_readme_formatting`**: Updated to include `BlockSpacing` cleanse fix
66
+ - Now fixes missing blank lines between block elements (thematic breaks, lists, headings, HTML)
67
+ - Runs as Phase 1c after CondensedLinkRefs and CodeFenceSpacing
68
+ - **MergeGemRegistry Integration**: Registers with `Ast::Merge::RSpec::MergeGemRegistry`
69
+ - Enables automatic RSpec dependency tag support
70
+ - Registers as category `:markdown` with `skip_instantiation: true` (requires backend)
71
+ - **TestableNode-based spec helpers**: New helper methods using `TreeHaver::RSpec::TestableNode`
72
+ for creating real node instances in tests instead of fragile mocks
73
+ - `create_test_node(type, text:, start_line:, ...)` - Create any node type
74
+ - `create_test_table_node(rows:, text:)` - Create table nodes
75
+ - `create_test_row_node(cells:, start_line:)` - Create table row nodes
76
+ - `create_test_cell_node(content:, start_line:)` - Create table cell nodes
77
+ - `create_test_paragraph_node(content:, start_line:)` - Create paragraph nodes
78
+ - `create_test_heading_node(level:, content:, start_line:)` - Create heading nodes
79
+ - `create_test_code_block_node(content:, language:, start_line:)` - Create code block nodes
80
+ - `create_test_list_node(items:, ordered:, start_line:)` - Create list nodes
81
+ - `create_test_block_quote_node(content:, start_line:)` - Create block quote nodes
82
+ - `create_test_thematic_break_node(start_line:)` - Create thematic break nodes
83
+ - `create_test_html_block_node(content:, start_line:)` - Create HTML block nodes
84
+ - **LinkParser**: New Parslet-based PEG parser for markdown link structures
85
+ - Properly handles emoji in labels (e.g., `[🖼️galtzo-discord]`)
86
+ - Handles multi-byte UTF-8 characters without regex limitations
87
+ - Handles nested brackets (for linked images like `[![alt][ref]](url)`)
88
+ - Parses link reference definitions: `[label]: url` and `[label]: url "title"`
89
+ - Parses inline links: `[text](url)` and `[text](url "title")`
90
+ - Parses inline images: `![alt](url)` and `![alt](url "title")`
91
+ - Methods: `#parse_definitions`, `#parse_definition_line`, `#find_inline_links`, `#find_inline_images`, `#build_url_to_label_map`
92
+ - **DocumentProblems**: New class for tracking document issues found during merge
93
+ - Categories: `:duplicate_link_definition`, `:excessive_whitespace`, `:link_has_title`, `:image_has_title`, `:link_ref_spacing`
94
+ - Severity levels: `:info`, `:warning`, `:error`
95
+ - Methods: `#add`, `#by_category`, `#by_severity`, `#warnings`, `#errors`, `#infos`, `#merge!`, `#summary_by_category`, `#summary_by_severity`
96
+ - Accessible via `MergeResult#problems` after merge
97
+ - **WhitespaceNormalizer**: New class for normalizing excessive whitespace
98
+ - Supports multiple normalization modes:
99
+ - `:basic` (or `true`) - Collapse excessive blank lines (3+ → 2)
100
+ - `:link_refs` - Basic + remove blank lines between consecutive link reference definitions
101
+ - `:strict` - All normalizations (same as :link_refs currently)
102
+ - Class method: `WhitespaceNormalizer.normalize(content, mode: :basic)`
103
+ - Instance usage tracks problems for introspection
104
+ - New `:link_ref_spacing` problem category for tracking removed blank lines between link refs
105
+ - **LinkReferenceRehydrator**: New class for converting inline links to reference style
106
+ - Converts inline links `[text](url)` to `[text][label]` when matching definition exists
107
+ - Converts inline images `![alt](url)` to `![alt][label]` when matching definition exists
108
+ - Skips links/images with titles (would lose title information)
109
+ - Tracks duplicate definitions and title conflicts in problems
110
+ - Prefers shortest label when multiple labels point to same URL
111
+ - **SmartMergerBase options**:
112
+ - `normalize_whitespace: false | true | :basic | :link_refs | :strict` - whitespace normalization mode
113
+ - `rehydrate_link_references: false` - convert inline links to reference style
114
+ - **PartialTemplateMerger options**:
115
+ - `normalize_whitespace: false | true | :basic | :link_refs | :strict` - whitespace normalization mode
116
+ - `rehydrate_link_references: false` - convert inline links to reference style
117
+ - **MergeResult#problems**: Access `DocumentProblems` instance for introspection
118
+ - **OutputBuilder**: New class for building markdown output from merge operations
119
+ - Consolidates all output assembly logic in one place
120
+ - Handles node source extraction, link definition reconstruction, gap lines
121
+ - Replaces manual string concatenation with clean builder pattern
122
+ - Public methods: `add_node_source`, `add_link_definition`, `add_gap_line`, `add_raw`, `to_s`, `empty?`, `clear`
123
+ - **LinkDefinitionFormatter**: New module for formatting link reference definitions
124
+ - Reconstructs link definitions that parsers consume during parsing
125
+ - Methods: `format(node)`, `format_all(nodes)`
126
+ - **Position-based signature generator for PartialTemplateMerger**:
127
+ - Tables (and other elements) at the same relative position in their sections now match
128
+ - Fixes the "duplicate tables" bug where tables with different column structures weren't merged
129
+ - Template table replaces destination table when both are at the same position within the section
130
+ - Position counters reset for each document, ensuring template and destination tables match
131
+ - **PartialTemplateMerger**: Markdown-specific implementation for partial template merging
132
+ - Extends `Ast::Merge::PartialTemplateMergerBase` with markdown-specific logic
133
+ - Heading-level-aware section boundaries (finds next heading of same or higher level)
134
+ - Source-based text extraction via `analysis.source_range` to preserve:
135
+ - Link reference definitions (no conversion to inline links)
136
+ - Table column padding/alignment
137
+ - Original formatting exactly as written
138
+ - Supports both Markly and Commonmarker backends via tree_haver
139
+ - **SmartMergerBase**: `add_template_only_nodes` now accepts a callable filter
140
+ - Boolean `true`/`false` still works as before (add all or none)
141
+ - Callable (Proc/Lambda) receives `(node, entry)` and returns truthy to add the node
142
+ - Enables selective addition of template-only nodes based on signature, type, or content
143
+ - Useful for partial template merging where only specific template nodes should be added
144
+
145
+ ### Changed
146
+
147
+ - Upgrade to [ast-merge v4.0.2](https://github.com/kettle-rb/ast-merge/releases/tag/v4.0.2)
148
+ - Upgrade to [tree_haver v5.0.2](https://github.com/kettle-rb/tree_haver/releases/tag/v5.0.2)
149
+ - **WhitespaceNormalizer refactored to use LinkParser**
150
+ - Removed `LINK_REF_PATTERN` regex constant
151
+ - Now uses `LinkParser#parse_definition_line` for link definition detection
152
+ - Supports all link definition formats that LinkParser handles:
153
+ - Angle-bracketed URLs: `[label]: <url>`
154
+ - Emoji in labels: `[🎨logo]: url`
155
+ - Definitions with titles in any quote style
156
+ - Completely regex-free implementation
157
+ - **LinkDefinitionNode**: Now uses `LinkParser` (Parslet-based) instead of regex for parsing
158
+ - Properly handles emoji in labels (e.g., `[🖼️galtzo-discord]`)
159
+ - More robust parsing of multi-byte UTF-8 characters
160
+ - **LinkReferenceRehydrator**: Rewritten to use `LinkParser` (Parslet-based) for all parsing
161
+ - Uses `LinkParser#parse_definitions` to parse link reference definitions
162
+ - Uses `LinkParser#find_inline_links` and `#find_inline_images` to find inline constructs
163
+ - Properly handles linked images (e.g., `[![alt][ref]](url)`)
164
+ - Properly handles emoji in link text and URLs
165
+ - No regex used - all parsing via PEG grammar
166
+ - **PartialTemplateMerger#find_section_end**: For headings, now always uses heading-level-aware logic, ignoring tree-depth-based boundary from `InjectionPointFinder`
167
+ - Fixes duplicate H4 section bug where nested headings (e.g., H4 inside H3) were incorrectly treated as section boundaries
168
+ - In Markdown, all headings are siblings at the same tree depth regardless of level (H2, H3, H4), so tree depth cannot determine section boundaries
169
+ - Heading level semantics require comparing actual heading level numbers (H3 < H4 means H4 is nested)
170
+ - **SmartMergerBase**: Refactored to use OutputBuilder throughout
171
+ - `process_alignment` now returns OutputBuilder instead of array
172
+ - New methods: `process_match_to_builder`, `process_template_only_to_builder`, `process_dest_only_to_builder`
173
+ - Old methods deprecated but kept for compatibility
174
+ - Inner merge for code blocks now uses `try_inner_merge_code_block_to_builder`
175
+ - **OutputBuilder**: Enhanced node extraction to handle `source_position` method
176
+ - Supports nodes with `source_position` hash
177
+ - Falls back to `to_commonmark` if position unavailable
178
+ - Handles FreezeNode, LinkDefinitionNode, GapLineNode, and parser nodes
179
+ - **FileAnalysisBase**: Added `@errors` instance variable and `errors` attr_reader
180
+ - `valid?` now checks both `@errors.empty?` and `!@document.nil?`
181
+ - Consistent with bash-merge, json-merge, jsonc-merge, and toml-merge patterns
182
+ - **FileAnalysis error handling**: Now rescues `TreeHaver::Error` in `parse_document`
183
+ - `TreeHaver::Error` inherits from `Exception`, not `StandardError`
184
+ - `TreeHaver::NotAvailable` is a subclass of `TreeHaver::Error`, so it's also caught
185
+ - Stores error in `@errors` and returns nil, so `valid?` returns false
186
+ - `SmartMergerBase#parse_and_analyze` then raises the appropriate parse error
187
+ - **Dependency tags**: Refactored to use shared `TreeHaver::RSpec::DependencyTags` from tree_haver gem
188
+ - All dependency detection is now centralized in tree_haver
189
+ - Use `require "tree_haver/rspec"` for shared RSpec configuration
190
+ - `MarkdownMergeDependencies` is now an alias to `TreeHaver::RSpec::DependencyTags`
191
+ - Enables `MARKDOWN_MERGE_DEBUG=1` for dependency summary output
192
+ - Inner-merge dependencies (`:toml_merge`, `:json_merge`, `:prism_merge`, `:psych_merge`) now available
193
+ - **CodeBlockMerger**: Refactored class methods to remove redundant error handling
194
+ - Removed duplicate `rescue` blocks from `merge_with_prism`, `merge_with_psych`, `merge_with_json`, `merge_with_toml`
195
+ - Error handling is now consolidated in `merge_code_blocks` instance method
196
+ - Class methods now raise exceptions which are caught by `merge_code_blocks`
197
+ - Updated specs to test through `merge_code_blocks` (the intended API) instead of class methods directly
198
+
199
+ ### Fixed
200
+
201
+ - **CondensedLinkRefs false positive**: Fixed bug where reference-style links followed by colon
202
+ (e.g., `**[Floss-Funding.dev][🖇floss-funding.dev]:**`) were incorrectly detected as condensed
203
+ link reference definitions
204
+ - The pattern `][label]:` was matching, but this is a reference link with punctuation, not a link def
205
+ - Now requires URL-like content after `]:` to confirm it's a real link def
206
+ - Supports both full URLs (`https://...`) and relative paths (`CONTRIBUTING.md`, `LICENSE.txt`)
207
+ - The relative path pattern matches `UPPERCASE.ext` format common in repo files
208
+ - Prevents incorrect newline insertion inside markdown links
209
+ - **LinkReferenceRehydrator content corruption**: Fixed critical bug where rehydrating linked images
210
+ like `[![alt](img-url)](link-url)` would corrupt document content
211
+ - The parser was finding both the outer link and inner image as separate items
212
+ - Replacing both overlapping items corrupted the content, losing significant portions of documents
213
+ - Now uses tree-based approach: builds parent-child relationships for nested constructs
214
+ - Processes replacements recursively: children are processed first, then parent text is updated
215
+ to include child replacements before parent is processed
216
+ - Single pass now handles all nested structures (no more multi-pass workaround needed)
217
+ - Test fixture showed 68 lines lost (1023 → 955) before fix, now preserves all content
218
+ - **OutputBuilder**: Fixed link definitions being concatenated without newlines
219
+ - `extract_source` for `LinkDefinitionNode` now includes trailing newline
220
+ - Link definitions are now properly output on separate lines
221
+ - **OutputBuilder**: Fixed auto-spacing to properly handle link_definition transitions
222
+ - Removed `link_definition` from the skip list for auto-spacing
223
+ - Now correctly adds blank lines when transitioning FROM link_definition TO other content (e.g., headings)
224
+ - `MarkdownStructure.needs_blank_between?` now handles contiguous types properly
225
+ - **MarkdownStructure**: Added support for contiguous node types
226
+ - New `CONTIGUOUS_TYPES` constant for node types that should not have blank lines between consecutive instances
227
+ - `link_definition` is now a contiguous type - consecutive link definitions won't have blank lines inserted
228
+ - Added `link_definition` to `NEEDS_BLANK_AFTER` - link definition blocks get blank line after when followed by other content
229
+ - New `contiguous_type?` method to check if a type is contiguous
230
+ - `needs_blank_between?` now returns `false` for consecutive nodes of the same contiguous type
231
+ - **PartialTemplateMerger#node_to_text**: Fixed double blank line bug
232
+ - `source_range` already adds trailing newlines, so adding another `"\n"` caused double blank lines
233
+ - Removed the extra `+ "\n"` that was causing excessive blank lines in merged output
234
+ - **Lint cleanup**: Fixed RSpec/ReceiveMessages cops by combining multiple `receive` stubs
235
+ - **Style fixes**: Fixed Style/ClassMethodsDefinitions in `LinkDefinitionNode` using `class << self`
236
+ - **Layout fixes**: Removed extra blank lines in `mock_helpers.rb`
237
+ - **Freeze block detection**: Fixed `find_freeze_markers` to handle both raw parser types
238
+ (`:html`) and TreeHaver normalized types (`"html_block"`, `:html_block`). Previously,
239
+ freeze markers were not detected when using TreeHaver backends because the node type
240
+ check only looked for `:html`.
241
+ - **Freeze marker content extraction**: Now uses a three-tier fallback for extracting
242
+ HTML comment content:
243
+ 1. `string_content` (raw Markly/Commonmarker nodes)
244
+ 2. `to_commonmark` on the wrapper node
245
+ 3. `inner_node.to_commonmark` (TreeHaver Commonmarker wrapper)
246
+ This fixes freeze block detection for Commonmarker where the TreeHaver wrapper's
247
+ content methods return empty but the inner node has the actual content.
248
+
249
+ [Unreleased]: https://github.com/kettle-rb/markdown-merge/compare/v1.0.0...HEAD
250
+ [1.0.0]: https://github.com/kettle-rb/markdown-merge/compare/76f2230840b236dd10fdd7baf322c082762dddb0...v1.0.0
251
+ [1.0.0t]: https://github.com/kettle-rb/markdown-merge/tags/v1.0.0
data/CITATION.cff ADDED
@@ -0,0 +1,20 @@
1
+ cff-version: 1.2.0
2
+ title: markdown-merge
3
+ message: >-
4
+ If you use this work and you want to cite it,
5
+ then you can use the metadata from this file.
6
+ type: software
7
+ authors:
8
+ - given-names: Peter Hurn
9
+ family-names: Boling
10
+ email: peter@railsbling.com
11
+ affiliation: railsbling.com
12
+ orcid: 'https://orcid.org/0009-0008-8519-441X'
13
+ identifiers:
14
+ - type: url
15
+ value: 'https://github.com/kettle-rb/markdown-merge'
16
+ description: markdown-merge
17
+ repository-code: 'https://github.com/kettle-rb/markdown-merge'
18
+ abstract: >-
19
+ markdown-merge
20
+ license: See license file
@@ -0,0 +1,134 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [![Contact Maintainer][🚂maint-contact-img]][🚂maint-contact].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
133
+ [🚂maint-contact]: http://www.railsbling.com/contact
134
+ [🚂maint-contact-img]: https://img.shields.io/badge/Contact-Maintainer-0093D0.svg?style=flat&logo=rubyonrails&logoColor=red
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,227 @@
1
+ # Contributing
2
+
3
+ Bug reports and pull requests are welcome on [CodeBerg][📜src-cb], [GitLab][📜src-gl], or [GitHub][📜src-gh].
4
+ This project should be a safe, welcoming space for collaboration, so contributors agree to adhere to
5
+ the [code of conduct][🤝conduct].
6
+
7
+ To submit a patch, please fork the project, create a patch with tests, and send a pull request.
8
+
9
+ Remember to [![Keep A Changelog][📗keep-changelog-img]][📗keep-changelog] if you make changes.
10
+
11
+ ## Help out!
12
+
13
+ Take a look at the `reek` list which is the file called `REEK` and find something to improve.
14
+
15
+ Follow these instructions:
16
+
17
+ 1. Fork the repository
18
+ 2. Create a feature branch (`git checkout -b my-new-feature`)
19
+ 3. Make some fixes.
20
+ 4. Commit changes (`git commit -am 'Added some feature'`)
21
+ 5. Push to the branch (`git push origin my-new-feature`)
22
+ 6. Make sure to add tests for it. This is important, so it doesn't break in a future release.
23
+ 7. Create new Pull Request.
24
+
25
+ ## Executables vs Rake tasks
26
+
27
+ Executables shipped by dependencies, such as kettle-dev, and stone_checksums, are available
28
+ after running `bin/setup`. These include:
29
+
30
+ - gem_checksums
31
+ - kettle-changelog
32
+ - kettle-commit-msg
33
+ - kettle-dev-setup
34
+ - kettle-dvcs
35
+ - kettle-pre-release
36
+ - kettle-readme-backers
37
+ - kettle-release
38
+
39
+ There are many Rake tasks available as well. You can see them by running:
40
+
41
+ ```shell
42
+ bin/rake -T
43
+ ```
44
+
45
+ ## Environment Variables for Local Development
46
+
47
+ Below are the primary environment variables recognized by stone_checksums (and its integrated tools). Unless otherwise noted, set boolean values to the string "true" to enable.
48
+
49
+ General/runtime
50
+ - DEBUG: Enable extra internal logging for this library (default: false)
51
+ - REQUIRE_BENCH: Enable `require_bench` to profile requires (default: false)
52
+ - CI: When set to true, adjusts default rake tasks toward CI behavior
53
+
54
+ Coverage (kettle-soup-cover / SimpleCov)
55
+ - K_SOUP_COV_DO: Enable coverage collection (default: true in .envrc)
56
+ - K_SOUP_COV_FORMATTERS: Comma-separated list of formatters (html, xml, rcov, lcov, json, tty)
57
+ - K_SOUP_COV_MIN_LINE: Minimum line coverage threshold (integer, e.g., 100)
58
+ - K_SOUP_COV_MIN_BRANCH: Minimum branch coverage threshold (integer, e.g., 100)
59
+ - K_SOUP_COV_MIN_HARD: Fail the run if thresholds are not met (true/false)
60
+ - K_SOUP_COV_MULTI_FORMATTERS: Enable multiple formatters at once (true/false)
61
+ - K_SOUP_COV_OPEN_BIN: Path to browser opener for HTML (empty disables auto-open)
62
+ - MAX_ROWS: Limit console output rows for simplecov-console (e.g., 1)
63
+ Tip: When running a single spec file locally, you may want `K_SOUP_COV_MIN_HARD=false` to avoid failing thresholds for a partial run.
64
+
65
+ GitHub API and CI helpers
66
+ - GITHUB_TOKEN or GH_TOKEN: Token used by `ci:act` and release workflow checks to query GitHub Actions status at higher rate limits
67
+
68
+ Releasing and signing
69
+ - SKIP_GEM_SIGNING: If set, skip gem signing during build/release
70
+ - GEM_CERT_USER: Username for selecting your public cert in `certs/<USER>.pem` (defaults to $USER)
71
+ - SOURCE_DATE_EPOCH: Reproducible build timestamp.
72
+ - `kettle-release` will set this automatically for the session.
73
+ - Not needed on bundler >= 2.7.0, as reproducible builds have become the default.
74
+
75
+ Git hooks and commit message helpers (exe/kettle-commit-msg)
76
+ - GIT_HOOK_BRANCH_VALIDATE: Branch name validation mode (e.g., `jira`) or `false` to disable
77
+ - GIT_HOOK_FOOTER_APPEND: Append a footer to commit messages when goalie allows (true/false)
78
+ - GIT_HOOK_FOOTER_SENTINEL: Required when footer append is enabled — a unique first-line sentinel to prevent duplicates
79
+ - GIT_HOOK_FOOTER_APPEND_DEBUG: Extra debug output in the footer template (true/false)
80
+
81
+ For a quick starting point, this repository’s `.envrc` shows sane defaults, and `.env.local` can override them locally.
82
+
83
+ ## Appraisals
84
+
85
+ From time to time the [appraisal2][🚎appraisal2] gemfiles in `gemfiles/` will need to be updated.
86
+ They are created and updated with the commands:
87
+
88
+ ```console
89
+ bin/rake appraisal:update
90
+ ```
91
+
92
+ If you need to reset all gemfiles/*.gemfile.lock files:
93
+
94
+ ```console
95
+ bin/rake appraisal:reset
96
+ ```
97
+
98
+ When adding an appraisal to CI, check the [runner tool cache][🏃‍♂️runner-tool-cache] to see which runner to use.
99
+
100
+ ## The Reek List
101
+
102
+ Take a look at the `reek` list which is the file called `REEK` and find something to improve.
103
+
104
+ To refresh the `reek` list:
105
+
106
+ ```console
107
+ bundle exec reek > REEK
108
+ ```
109
+
110
+ ## Run Tests
111
+
112
+ To run all tests
113
+
114
+ ```console
115
+ bundle exec rake test
116
+ ```
117
+
118
+ ### Spec organization (required)
119
+
120
+ - One spec file per class/module. For each class or module under `lib/`, keep all of its unit tests in a single spec file under `spec/` that mirrors the path and file name exactly: `lib/markdown/merge/my_class.rb` -> `spec/markdown/merge/my_class_spec.rb`.
121
+ - Exception: Integration specs that intentionally span multiple classes. Place these under `spec/integration/` (or a clearly named integration folder), and do not directly mirror a single class. Name them after the scenario, not a class.
122
+
123
+ ## Lint It
124
+
125
+ Run all the default tasks, which includes running the gradually autocorrecting linter, `rubocop-gradual`.
126
+
127
+ ```console
128
+ bundle exec rake
129
+ ```
130
+
131
+ Or just run the linter.
132
+
133
+ ```console
134
+ bundle exec rake rubocop_gradual:autocorrect
135
+ ```
136
+
137
+ For more detailed information about using RuboCop in this project, please see the [RUBOCOP.md](RUBOCOP.md) guide. This project uses `rubocop_gradual` instead of vanilla RuboCop, which requires specific commands for checking violations.
138
+
139
+ ### Important: Do not add inline RuboCop disables
140
+
141
+ Never add `# rubocop:disable ...` / `# rubocop:enable ...` comments to code or specs (except when following the few existing `rubocop:disable` patterns for a rule already being disabled elsewhere in the code). Instead:
142
+
143
+ - Prefer configuration-based exclusions when a rule should not apply to certain paths or files (e.g., via `.rubocop.yml`).
144
+ - When a violation is temporary, and you plan to fix it later, record it in `.rubocop_gradual.lock` using the gradual workflow:
145
+ - `bundle exec rake rubocop_gradual:autocorrect` (preferred)
146
+ - `bundle exec rake rubocop_gradual:force_update` (only when you cannot fix the violations immediately)
147
+
148
+ As a general rule, fix style issues rather than ignoring them. For example, our specs should follow RSpec conventions like using `described_class` for the class under test.
149
+
150
+ ## Contributors
151
+
152
+ Your picture could be here!
153
+
154
+ [![Contributors][🖐contributors-img]][🖐contributors]
155
+
156
+ Made with [contributors-img][🖐contrib-rocks].
157
+
158
+ Also see GitLab Contributors: [https://gitlab.com/kettle-rb/markdown-merge/-/graphs/main][🚎contributors-gl]
159
+
160
+ ## For Maintainers
161
+
162
+ ### One-time, Per-maintainer, Setup
163
+
164
+ **IMPORTANT**: To sign a build,
165
+ a public key for signing gems will need to be picked up by the line in the
166
+ `gemspec` defining the `spec.cert_chain` (check the relevant ENV variables there).
167
+ All releases are signed releases.
168
+ See: [RubyGems Security Guide][🔒️rubygems-security-guide]
169
+
170
+ NOTE: To build without signing the gem set `SKIP_GEM_SIGNING` to any value in the environment.
171
+
172
+ ### To release a new version:
173
+
174
+ #### Automated process
175
+
176
+ 1. Update version.rb to contain the correct version-to-be-released.
177
+ 2. Run `bundle exec kettle-changelog`.
178
+ 3. Run `bundle exec kettle-release`.
179
+ 4. Stay awake and monitor the release process for any errors, and answer any prompts.
180
+
181
+ #### Manual process
182
+
183
+ 1. Run `bin/setup && bin/rake` as a "test, coverage, & linting" sanity check
184
+ 2. Update the version number in `version.rb`, and ensure `CHANGELOG.md` reflects changes
185
+ 3. Run `bin/setup && bin/rake` again as a secondary check, and to update `Gemfile.lock`
186
+ 4. Run `git commit -am "🔖 Prepare release v<VERSION>"` to commit the changes
187
+ 5. Run `git push` to trigger the final CI pipeline before release, and merge PRs
188
+ - NOTE: Remember to [check the build][🧪build].
189
+ 6. Run `export GIT_TRUNK_BRANCH_NAME="$(git remote show origin | grep 'HEAD branch' | cut -d ' ' -f5)" && echo $GIT_TRUNK_BRANCH_NAME`
190
+ 7. Run `git checkout $GIT_TRUNK_BRANCH_NAME`
191
+ 8. Run `git pull origin $GIT_TRUNK_BRANCH_NAME` to ensure latest trunk code
192
+ 9. Optional for older Bundler (< 2.7.0): Set `SOURCE_DATE_EPOCH` so `rake build` and `rake release` use the same timestamp and generate the same checksums
193
+ - If your Bundler is >= 2.7.0, you can skip this; builds are reproducible by default.
194
+ - Run `export SOURCE_DATE_EPOCH=$EPOCHSECONDS && echo $SOURCE_DATE_EPOCH`
195
+ - If the echo above has no output, then it didn't work.
196
+ - Note: `zsh/datetime` module is needed, if running `zsh`.
197
+ - In older versions of `bash` you can use `date +%s` instead, i.e. `export SOURCE_DATE_EPOCH=$(date +%s) && echo $SOURCE_DATE_EPOCH`
198
+ 10. Run `bundle exec rake build`
199
+ 11. Run `bin/gem_checksums` (more context [1][🔒️rubygems-checksums-pr], [2][🔒️rubygems-guides-pr])
200
+ to create SHA-256 and SHA-512 checksums. This functionality is provided by the `stone_checksums`
201
+ [gem][💎stone_checksums].
202
+ - The script automatically commits but does not push the checksums
203
+ 12. Sanity check the SHA256, comparing with the output from the `bin/gem_checksums` command:
204
+ - `sha256sum pkg/<gem name>-<version>.gem`
205
+ 13. Run `bundle exec rake release` which will create a git tag for the version,
206
+ push git commits and tags, and push the `.gem` file to the gem host configured in the gemspec.
207
+
208
+ [📜src-gl]: https://gitlab.com/kettle-rb/markdown-merge/
209
+ [📜src-cb]: https://codeberg.org/kettle-rb/markdown-merge
210
+ [📜src-gh]: https://github.com/kettle-rb/markdown-merge
211
+ [🧪build]: https://github.com/kettle-rb/markdown-merge/actions
212
+ [🤝conduct]: https://gitlab.com/kettle-rb/markdown-merge/-/blob/main/CODE_OF_CONDUCT.md
213
+ [🖐contrib-rocks]: https://contrib.rocks
214
+ [🖐contributors]: https://github.com/kettle-rb/markdown-merge/graphs/contributors
215
+ [🚎contributors-gl]: https://gitlab.com/kettle-rb/markdown-merge/-/graphs/main
216
+ [🖐contributors-img]: https://contrib.rocks/image?repo=kettle-rb/markdown-merge
217
+ [💎gem-coop]: https://gem.coop
218
+ [🔒️rubygems-security-guide]: https://guides.rubygems.org/security/#building-gems
219
+ [🔒️rubygems-checksums-pr]: https://github.com/rubygems/rubygems/pull/6022
220
+ [🔒️rubygems-guides-pr]: https://github.com/rubygems/guides/pull/325
221
+ [💎stone_checksums]: https://github.com/galtzo-floss/stone_checksums
222
+ [📗keep-changelog]: https://keepachangelog.com/en/1.0.0/
223
+ [📗keep-changelog-img]: https://img.shields.io/badge/keep--a--changelog-1.0.0-FFDD67.svg?style=flat
224
+ [📌semver-breaking]: https://github.com/semver/semver/issues/716#issuecomment-869336139
225
+ [📌major-versions-not-sacred]: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html
226
+ [🚎appraisal2]: https://github.com/appraisal-rb/appraisal2
227
+ [🏃‍♂️runner-tool-cache]: https://github.com/ruby/ruby-builder/releases/tag/toolcache