Skip to content

Instantly share code, notes, and snippets.

@r-plus
Last active August 19, 2017 14:34
Show Gist options
  • Save r-plus/f3d41e5c93c9c11e777c19752348694e to your computer and use it in GitHub Desktop.
Save r-plus/f3d41e5c93c9c11e777c19752348694e to your computer and use it in GitHub Desktop.
Observable.create内でonNextしたらonCompletedが次の行に無いと警告するSwiftlint custom rule

Observable.create内でonNextしたらonCompletedが次の行に無いと警告するSwiftlint custom rule

Task/Promise/Future代わりにObservableを利用する場合、Observable.createするのだが、onNextは1回しかしないのでonNextの次行にonCompletedがなかったら警告する。

custom_rules:
  next_with_completed:
    regex: "\\.create\\s*\\{\\s*\\(?\\w+\\)?\\s*->\\s+Disposable in\\n[\\S\\s]*(onNext\\([\\w]+\\)|on\\(\\.next\\(\\w+\\)\\))\\n(?![^//]+\\.onCompleted)"
    message: "Must call onCompleted event next line of onNext."
    severity: warning

正規表現図(regexper.com)
https://goo.gl/ucZxn9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment