Swiftlint: Valid regex not supported (found unknown escape character) -> \w, \s

Created on 30 Jul 2019  路  1Comment  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

Custom regex does not work even though it is valid regex.

image

image

Complete output when running SwiftLint, including the stack trace and command used
/.../.swiftlint.yml:26:31: error: scanner: while parsing a quoted scalar in line 26, column 12
found unknown escape character:
    regex: "(\/\/ MARK: [^-])[\w\s]+\s+((func)|(var))"
                              ^
Could not read configuration file at path '/.../.swiftlint.yml': file Configuration.swift, line 139
[1]    76069 abort      swiftlint lint

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.34.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? CocoaPods
  • Paste your configuration file:
# TextRecruit SwiftLint Configuration

disabled_rules: # rule identifiers to exclude from running
  - large_tuple
  - unused_optional_binding
  - cyclomatic_complexity
  - closure_parameter_position
  - private_over_fileprivate
opt_in_rules: # some rules are only opt-in
  # Find all the available rules by running:
  # swiftlint rules
  private_outlet
  private_action
included: # paths to include during linting. `--path` is ignored if present.
  - TextRecruit
  - TextRecruitTests
  - TextRecruitUITests
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - TextRecruit/Localization
#  - Source/ExcludedFolder
#  - Source/ExcludedFile.swiftb
custom_rules:
  mark_format:
    regex: "(\/\/ MARK: [^-])[\w\s]+\s+((func)|(var))"
    match_kinds: 
      - comment
      - identifier
    name: "MARK Formatting"
    message: "Use a '-' after the colon if marking a new group of methods or properties"

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
trailing_whitespace:
  ignores_empty_lines: true
force_cast: warning # implicitly
force_try:
  severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 130
# they can set both implicitly with an array
type_body_length:
  - 400 # warning
  - 500 # error
# or they can set both explicitly
file_length:
  warning: 700
  error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
  min_length: 1 # only warning
  max_length: # warning and error
    warning: 50
    error: 60
  excluded:
    - iPhone # excluded via string
identifier_name:
  min_length: 1 # only min_length
    #error: 4 # only error
  excluded: # excluded via string array
    - id
    - URL
    - GlobalAPIKey
  allowed_symbols:
    - '_'
function_body_length:
 - 120 # warning
 - 120 # error
function_parameter_count: 6
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)

  • Are you using nested configurations? No
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcode-select -p)? 10.3
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
// This triggers a violation:
let foo = try! bar()

Most helpful comment

This is not valid YAML. You can use ' instead of " when defining the regex and it should work.

>All comments

This is not valid YAML. You can use ' instead of " when defining the regex and it should work.

Was this page helpful?
0 / 5 - 0 ratings