Skip to content

Support for multiple regexes #122

@pete-murphy

Description

@pete-murphy

Hello!
I've been using rustywind to sort Tailwind classes in an Elm app. To get Intellisense working in VS Code, I'm using regexes from this article, which I've adapted to a rustywind.sh script:

#!/usr/bin/env bash
set -eu

# Default to write mode
MODE="--write"

# Check if --check-formatted flag is passed
if [ "$#" -gt 0 ] && [ "$1" = "--check-formatted" ]; then
    MODE="--check-formatted"
fi

rustywind $MODE --custom-regex "\bclass[\s(<|]+\"([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclass[\s(]+\"[^\"]*\"[\s+]+\"([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclassList[\s\[\(]+\"([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclassList[\s\[\(]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"([^\"]*)\"" .
rustywind $MODE --custom-regex "\bclassList[\s\[\(]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"([^\"]*)\"" .

Running ./shell-scripts/rustywind.sh --check-formatted for example outputs the following

only printing changed files

only printing changed files

only printing changed files

only printing changed files

only printing changed files

only printing changed files

only printing changed files

only printing changed files

It would be slightly nicer to avoid the duplicate output, if we had support for multiple --custom-regex flags, something like

rustywind --custom-regex "\bclass[\s(<|]+\"([^\"]*)\"" \
  --custom-regex "\bclass[\s(]+\"[^\"]*\"[\s+]+\"([^\"]*)\"" \
  --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" \
  --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" \
  --custom-regex "\bclass[\s<|]+\"[^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" [^\"]*\"\s*\+{2}\s*\" ([^\"]*)\"" \
  --custom-regex "\bclassList[\s\[\(]+\"([^\"]*)\"" \
  --custom-regex "\bclassList[\s\[\(]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"([^\"]*)\"" \
  --custom-regex "\bclassList[\s\[\(]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"[^\"]*\",\s[^\)]+\)[\s\[\(,]+\"([^\"]*)\"" .

The issue of "multiple regexes" seems to have been raised before in #27, and that issue was closed as "completed". Is there a way of using multiple regexes? If not, would that be a welcomed change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions