/file-pattern-scanner

Simple script that scans flat/plain text files for patterns predefined in rules

Primary LanguageGroovyMIT LicenseMIT

maintainer
buep

File Pattern Scanner

A simple tool for scanning files for predefined patterns and generating messages depending on its matches.

Usage

Defining rules

In a rule you define:

  • The name of the rule
  • The pattern to look for
    • RegEx
  • When the rule is triggered
    • When a match is found
    • When a match isn't found
  • If the script fails when the rule is triggered
  • The message to print when the rule is triggered

Rules follow a simple format:

{NAME}:
  match: {Matcher RegEx}
  type: {onMissing/onFind}
  fail: {true/false}
  message: {Message string}

Example:

failOnNonAscii:
  match: ([^\x00-\x7F]+\ *(?:[^\x00-\x7F]| )*)
  type: onFind
  fail: true
  message: "ERROR: File contains non-ASCII characters"
warnOnComments:
  match: \/\*[\s\S]*?\*\/|\/\/.*
  type: onFind
  fail: false
  message: "WARNING: File still contains JavaScript comments"

Calling the script

After defining the rules, pass them into the script alongside the files you want scanned as arguments.

Example: groovy scanner rules.yml myFile.log

Output for our example:

[FILE: myFile.log]
[RULE: failOnNonAscii]
[4 matches]
ERROR: File contains non-ASCII characters
[RULE: warnOnComments]
[1 match]
WARNING: File still contains JavaScript comments

Process finished with exit code 1

Support, contributions and maintenance

Build and delivery pipeline: http://code.praqma.net/ci/view/Open%20Source%20Pipelines/view/file-pattern-scanner/

Changes

See Releases.