Skip to content

Conversation

azu
Copy link
Member

@azu azu commented Aug 24, 2025

Summary

This PR adds support for specifying multiple patterns as an array in @secretlint/secretlint-rule-pattern. The new patterns field allows grouping related regex patterns into a single rule configuration, improving maintainability and readability.

What's Changed

  • Introduced a new patterns array field that accepts multiple regex patterns
  • Deprecated the existing singular pattern field (soft deprecation with backward compatibility)
  • Added validation to prevent simultaneous use of both patterns and pattern fields
  • Refactored pattern collection logic into a dedicated collectPatterns() function

Key Changes

  • src/index.ts:

    • Added patterns?: string[] field to PatternType interface
    • Created collectPatterns() function for cleaner pattern resolution logic
    • Added validation to throw error when both fields are specified together
    • Maintained backward compatibility with deprecated pattern field
  • README.md:

    • Updated usage examples to demonstrate the new patterns array
    • Added "Deprecated options" section explaining migration path
    • Updated all examples to use the preferred patterns format

Usage Example

Before (Multiple separate rules)

{
  "patterns": [
    {
      "name": "password",
      "pattern": "/password\\s*=\\s*[\\w\\d]+/"
    },
    {
      "name": "apikey", 
      "pattern": "/apikey\\s*=\\s*[\\w\\d]+/"
    }
  ]
}

After (Single rule with multiple patterns)

{
  "patterns": [
    {
      "name": "credentials",
      "patterns": [
        "/password\\s*=\\s*[\\w\\d]+/",
        "/apikey\\s*=\\s*[\\w\\d]+/",
        "/token\\s*=\\s*[\\w\\d]+/"
      ]
    }
  ]
}

Test Plan

  • Verify new patterns array correctly detects multiple patterns
  • Confirm existing pattern field continues to work (backward compatibility)
  • Test that specifying both patterns and pattern throws appropriate error
  • Verify filePathGlobs works correctly with new patterns array
  • Test error handling when neither patterns nor filePathGlobs are specified
  • Validate README examples work as documented

Breaking Changes

  • Minor breaking change: Specifying both patterns and pattern fields together now throws an error. Users must choose one or the other.

Additional Notes

🤖 Generated with Claude Code

- Add new patterns field (array) to PatternType interface
- Deprecate existing pattern field (singular) with soft deprecation
- Implement collectPatterns() function for pattern collection logic
- Add validation to prevent simultaneous use of patterns and pattern
- Update documentation to explain new patterns array usage
- Maintain backward compatibility with deprecated pattern field

BREAKING CHANGE: Using both patterns and pattern fields together now throws an error

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@azu azu added the Type: Feature New Feature label Aug 24, 2025
@azu azu marked this pull request as ready for review August 24, 2025 12:27
- Add tests for multiple patterns in single rule
- Add tests for allows functionality with patterns array
- Verify all patterns are correctly detected
@azu azu merged commit 1b7fc21 into master Aug 25, 2025
16 checks passed
@azu azu deleted the feat/add-patterns-array-support branch August 25, 2025 00:37
This was referenced Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant