Skip to content

Commit 4466522

Browse files
committed
Change from DRY to Magic String Detector (DRY)
1 parent aff9dbd commit 4466522

14 files changed

Lines changed: 2004 additions & 157 deletions

PROJECT/1-INBOX/NEXT-AUDIT-COPILOT-SONNET.md renamed to AUDIT-COPILOT-SONNET.md

File renamed without changes.

CHANGELOG.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,61 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.74] - 2026-01-02
9+
10+
### Changed
11+
- **Terminology Update: "DRY Violations" → "Magic String Detector"** - Renamed feature for clarity
12+
- "DRY Violation Detection" is now "Magic String Detector ('DRY')"
13+
- User-facing text updated in all scripts, templates, and documentation
14+
- JSON output field renamed from `dry_violations` to `magic_string_violations`
15+
- HTML template labels updated from "DRY Violations" to "Magic Strings"
16+
- Internal variable names kept as `DRY_VIOLATIONS` for backward compatibility
17+
- **Rationale:** "Magic String" is a more widely understood term for hardcoded string literals
18+
19+
### Updated Files
20+
- `dist/bin/check-performance.sh` - Updated section headers and output messages
21+
- `dist/bin/find-dry.sh` - Updated script header and output messages
22+
- `dist/bin/templates/report-template.html` - Updated labels and placeholders
23+
- `dist/patterns/dry/README.md` - Updated documentation terminology
24+
- `CHANGELOG.md` - Updated all DRY-related entries
25+
- `DRY_VIOLATIONS_STATUS.md` - Updated document title and references
26+
- `PROJECT/1-INBOX/DRY-POC-SUMMARY.md` - Updated terminology
27+
- `PROJECT/1-INBOX/NEXT-FIND-DRY.md` - Updated terminology
28+
829
## [1.0.73] - 2026-01-02
930

1031
### Added
11-
- **DRY Violations in HTML Reports** - HTML reports now display DRY violations section
12-
- Added dedicated "DRY Violations" section showing all detected violations
13-
- Added DRY violations count to summary stats card
32+
- **Magic String Detector ("DRY") in HTML Reports** - HTML reports now display magic string violations section
33+
- Added dedicated "Magic String Violations" section showing all detected violations
34+
- Added magic string violations count to summary stats card
1435
- Shows pattern name, duplicated string, file count, and total occurrences
1536
- Lists all locations with clickable file paths
16-
- **Impact:** DRY violations are now visible in HTML reports (previously only in JSON/text)
37+
- **Impact:** Magic string violations are now visible in HTML reports (previously only in JSON/text)
1738

1839
### Changed
19-
- **HTML Template** - Updated `report-template.html` to include DRY violations section
20-
- Added `{{DRY_VIOLATIONS_COUNT}}` placeholder for summary stats
21-
- Added `{{DRY_VIOLATIONS_HTML}}` placeholder for violations content
40+
- **HTML Template** - Updated `report-template.html` to include magic string violations section
41+
- Added `{{MAGIC_STRING_VIOLATIONS_COUNT}}` placeholder for summary stats
42+
- Added `{{MAGIC_STRING_VIOLATIONS_HTML}}` placeholder for violations content
2243
- Styled violations with medium severity (yellow border)
2344

2445
- **HTML Generation** - Enhanced `generate_html_report()` function
25-
- Extracts DRY violations from JSON output
46+
- Extracts magic string violations from JSON output
2647
- Formats violations with pattern details and location lists
2748
- Generates "No violations" message when none detected
2849

2950
### Testing
30-
- Verified with debug-log-manager plugin (6 DRY violations detected)
51+
- Verified with debug-log-manager plugin (6 magic string violations detected)
3152
- HTML report displays all violations with proper formatting
3253
- Clickable file paths work correctly
3354

3455
## [1.0.72] - 2026-01-02
3556

3657
### Fixed
3758
- **Critical: Path Quoting Bug** - Fixed unquoted `$PATHS` variable in grep command
38-
- **Impact:** DRY violation detection was completely broken for paths with spaces
39-
- **Symptom:** Grep returned 0 matches even when violations existed
59+
- **Impact:** Magic String Detector ("DRY") was completely broken for paths with spaces
60+
- **Symptom:** Grep returned 0 matches even when magic strings existed
4061
- **Fix:** Added quotes around `"$PATHS"` in line 1333
41-
- **Result:**DRY violation detection now works correctly
62+
- **Result:**Magic String Detector now works correctly
4263

4364
- **Shell Syntax Error** - Removed `local` keyword from non-function context
4465
- **Impact:** Script threw errors: "local: can only be used in a function"
@@ -49,7 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4970
### Verified
5071
- ✅ Pattern extraction working (75-character regex patterns extracted correctly)
5172
- ✅ Grep finding matches (38 raw matches found in test plugin)
52-
- ✅ Aggregation logic working (2 violations detected correctly)
73+
- ✅ Aggregation logic working (2 magic strings detected correctly)
5374
- ✅ Debug logging working (`/tmp/wp-code-check-debug.log` shows full details)
5475

5576
### Testing
@@ -59,7 +80,7 @@ Tested against real WordPress plugin:
5980
- **Results:**
6081
- Duplicate transient keys: ✓ No violations
6182
- Duplicate capability strings: ✓ No violations (3 matches, below threshold)
62-
- Duplicate option names: ⚠ Found 2 violations (38 matches)
83+
- Duplicate option names: ⚠ Found 2 magic strings (38 matches)
6384

6485
## [1.0.71] - 2026-01-01
6586

@@ -77,9 +98,9 @@ Tested against real WordPress plugin:
7798
- Helps diagnose pattern loading and matching issues
7899
- **Usage:** Check `/tmp/wp-code-check-debug.log` after running the scanner
79100

80-
- **Enhanced Output** - Improved DRY violation detection output
101+
- **Enhanced Output** - Improved Magic String Detector ("DRY") output
81102
- Shows pattern search string in output (for debugging)
82-
- Shows count of violations found per pattern
103+
- Shows count of magic strings found per pattern
83104
- Better visual feedback for debugging pattern issues
84105

85106
### Changed
@@ -96,34 +117,34 @@ Tested against real WordPress plugin:
96117
## [1.0.70] - 2026-01-01
97118

98119
### Added
99-
- **DRY Violation Detection (Aggregated Patterns)** - New pattern type for detecting code duplication
120+
- **Magic String Detector ("DRY") (Aggregated Patterns)** - New pattern type for detecting magic strings (hardcoded string literals)
100121
- Added `detection_type` field to pattern schema (`direct` or `aggregated`)
101-
- Created 3 aggregated patterns for detecting duplicate string literals:
122+
- Created 3 aggregated patterns for detecting duplicate string literals (magic strings):
102123
- `dist/patterns/duplicate-option-names.json` - Duplicate WordPress option names across files
103124
- `dist/patterns/duplicate-transient-keys.json` - Duplicate transient keys across files
104125
- `dist/patterns/duplicate-capability-strings.json` - Duplicate capability strings across files
105126
- Aggregated patterns group matches by captured string and report violations when:
106127
- String appears in >= 3 distinct files (configurable via `min_distinct_files`)
107128
- String appears >= 6 total times (configurable via `min_total_matches`)
108-
- **Purpose:** Detect DRY violations where hardcoded strings should be constants
129+
- **Purpose:** Detect magic strings (DRY violations) where hardcoded strings should be constants
109130
- **Example:** Option name `'my_plugin_settings'` used in 5 files (8 times) → suggests creating a constant
110131

111-
- **JSON Output Enhancement** - Extended JSON schema to include DRY violations
112-
- Added `dry_violations` array to JSON output with structure:
132+
- **JSON Output Enhancement** - Extended JSON schema to include magic string violations
133+
- Added `magic_string_violations` array to JSON output with structure:
113134
- `pattern`: Pattern title (e.g., "Duplicate option names across files")
114135
- `severity`: Pattern severity (MEDIUM/HIGH/CRITICAL)
115-
- `duplicated_string`: The duplicated string literal
136+
- `duplicated_string`: The duplicated string literal (magic string)
116137
- `file_count`: Number of distinct files containing the string
117138
- `total_count`: Total occurrences across all files
118139
- `locations`: Array of `{file, line}` objects showing all occurrences
119-
- Added `dry_violations` count to summary section
140+
- Added `magic_string_violations` count to summary section
120141
- **Example Output:**
121142
```json
122143
{
123144
"summary": {
124-
"dry_violations": 2
145+
"magic_string_violations": 2
125146
},
126-
"dry_violations": [
147+
"magic_string_violations": [
127148
{
128149
"pattern": "Duplicate option names across files",
129150
"severity": "MEDIUM",
@@ -157,16 +178,16 @@ Tested against real WordPress plugin:
157178
- `report_format`: Template for violation messages
158179
- `sort_by`: Sort order for violations (`"file_count_desc"` or `"total_count_desc"`)
159180

160-
- **Text Output** - Added DRY Violation Detection section
181+
- **Text Output** - Added Magic String Detection ("DRY") section
161182
- New section displayed after all direct pattern checks
162183
- Shows pattern title and violation status for each aggregated pattern
163-
- Displays "✓ No violations" or "⚠ Found violations" for each pattern
184+
- Displays "✓ No violations" or "⚠ Found magic strings" for each pattern
164185

165186
### Technical Details
166187
- **Aggregation Algorithm:**
167188
1. Run grep with pattern's search_pattern across all PHP files
168189
2. Extract captured group (e.g., option name from `get_option('name')`)
169-
3. Group matches by captured string
190+
3. Group matches by captured string (magic string)
170191
4. Count distinct files and total occurrences for each string
171192
5. Report strings exceeding both thresholds
172193
- **Performance:** Aggregation runs after all direct checks to avoid duplicate grep operations
@@ -175,7 +196,7 @@ Tested against real WordPress plugin:
175196
### Known Issues
176197
- Pattern extraction may fail on systems without Python if patterns contain complex escaped characters
177198
- Aggregation currently only supports single capture group (group_by: "capture_group")
178-
- HTML report does not yet display DRY violations (JSON output only)
199+
- HTML report does not yet display magic string violations (JSON output only)
179200

180201
## [1.0.69] - 2026-01-01
181202

0 commit comments

Comments
 (0)