I am trying to add a custom rule that I found here to my SwiftLint.yml file.
However when I compile the project I get a fatal_error (see details below)
This is what I add to the bottom of the SwiftLint file:
custom_rules:
void_as_return:
name: "Void as Parameter"
message: "Use Void as return type instead of ()."
regex: "(->[ ]?\(\))"
smiley_face:
name: "Smiley Face"
regex: "(\:\))"
match_kinds:
- comment
- string
message: "A closing parenthesis smiley :) creates a half-hearted smile, and thus is not preferred. Use :]"
severity: warning
I get the following error:
fatal error: Could not read configuration file at path '/Users/-/Documents/Workspace_Xcode/ProjectName/.swiftlint.yml': Error parsing YAML: duplicate key String(name), near ": \"Smiley Face\"\nregex: \"(\:))\"\nmatch_kinds:\n- com": file /Users/jp/Projects/SwiftLint/Source/SwiftLintFramework/Models/Configuration.swift, line 162
What am I missing?
It says that there is a duplicate string, hence I assume that there is already a smiley_face rule in the YAML file. However, when I run swiftlint rulesfrom terminal I don't see it enabled.
Here is what I've got:

@dddppp: you are missing one indentation level in your yml file.
custom_rules:
void_as_return:
name: "Void as Parameter"
message: "Use Void as return type instead of ()."
regex: "(->[ ]?\(\))"
smiley_face:
name: "Smiley Face"
regex: "(\:\))"
match_kinds:
- comment
- string
message: "A closing parenthesis smiley :) creates a half-hearted smile, and thus is not preferred. Use :]"
severity: warning
SwiftLint requires configuration files to be valid YAML.
YAMLlint produces the following error with your original content:
(<unknown>): found unknown escape character while parsing a quoted scalar at line 5 column 12
Also @drodriguez's recommendation isn't sufficient, as the escape character remains.
You probably want this configuration:
custom_rules:
void_as_return:
name: "Void as Parameter"
message: "Use Void as return type instead of ()."
regex: '(->[ ]?\(\))'
smiley_face:
name: "Smiley Face"
regex: '(\:\))'
match_kinds:
- comment
- string
message: "A closing parenthesis smiley :) creates a half-hearted smile, and thus is not preferred. Use :]"
severity: warning
By using single quotes (') rather than double quotes ("), the \ character isn't treated like a YAML escape command but rather as a plain string.
Most helpful comment
SwiftLint requires configuration files to be valid YAML.
YAMLlint produces the following error with your original content:
Also @drodriguez's recommendation isn't sufficient, as the escape character remains.
You probably want this configuration:
By using single quotes (
') rather than double quotes ("), the\character isn't treated like a YAML escape command but rather as a plain string.