Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update SwiftLint configuration #212

Merged
merged 2 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ opt_in_rules:
- implicit_return
- implicitly_unwrapped_optional
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_random
- let_var_whitespace
- literal_expression_end_indentation
Expand All @@ -38,13 +40,16 @@ opt_in_rules:
- multiline_literal_brackets
- multiline_parameters
- nimble_operator
- nslocalizedstring_key
- operator_usage_whitespace
- overridden_super_call
- override_in_extension
- pattern_matching_keywords
- private_action
- private_outlet
- prohibited_interface_builder
- prohibited_super_call
- reduce_into
- redundant_nil_coalescing
- single_test_class
- sorted_first_last
Expand All @@ -53,14 +58,18 @@ opt_in_rules:
- toggle_bool
- unavailable_function
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_declaration
- unused_import
- unused_private_declaration
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- xct_specific_matcher
- yoda_condition

disabled_rules:
- cyclomatic_complexity
- identifier_name

colon:
flexible_right_spacing: true
Expand Down
66 changes: 33 additions & 33 deletions Tests/EquatableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// EquatableTests.swift
// OneTimePassword
//
// Copyright (c) 2014-2017 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2014-2019 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -28,55 +28,55 @@ import OneTimePassword

class EquatableTests: XCTestCase {
func testFactorEquality() {
let c0 = Generator.Factor.counter(30)
let c1 = Generator.Factor.counter(60)
let t0 = Generator.Factor.timer(period: 30)
let t1 = Generator.Factor.timer(period: 60)
let smallCounter = Generator.Factor.counter(30)
let bigCounter = Generator.Factor.counter(60)
let shortTimer = Generator.Factor.timer(period: 30)
let longTimer = Generator.Factor.timer(period: 60)

XCTAssertEqual(c0, c0)
XCTAssertEqual(c1, c1)
XCTAssertNotEqual(c0, c1)
XCTAssertNotEqual(c1, c0)
XCTAssertEqual(smallCounter, smallCounter)
XCTAssertEqual(bigCounter, bigCounter)
XCTAssertNotEqual(smallCounter, bigCounter)
XCTAssertNotEqual(bigCounter, smallCounter)

XCTAssertEqual(t0, t0)
XCTAssertEqual(t1, t1)
XCTAssertNotEqual(t0, t1)
XCTAssertNotEqual(t1, t0)
XCTAssertEqual(shortTimer, shortTimer)
XCTAssertEqual(longTimer, longTimer)
XCTAssertNotEqual(shortTimer, longTimer)
XCTAssertNotEqual(longTimer, shortTimer)

XCTAssertNotEqual(c0, t0)
XCTAssertNotEqual(c0, t1)
XCTAssertNotEqual(c1, t0)
XCTAssertNotEqual(c1, t1)
XCTAssertNotEqual(smallCounter, shortTimer)
XCTAssertNotEqual(smallCounter, longTimer)
XCTAssertNotEqual(bigCounter, shortTimer)
XCTAssertNotEqual(bigCounter, longTimer)

XCTAssertNotEqual(t0, c0)
XCTAssertNotEqual(t0, c1)
XCTAssertNotEqual(t1, c0)
XCTAssertNotEqual(t1, c1)
XCTAssertNotEqual(shortTimer, smallCounter)
XCTAssertNotEqual(shortTimer, bigCounter)
XCTAssertNotEqual(longTimer, smallCounter)
XCTAssertNotEqual(longTimer, bigCounter)
}

func testGeneratorEquality() {
let g = Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 6)
let generator = Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 6)
let badData = "0".data(using: String.Encoding.utf8)!

XCTAssert(g == Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 6))
XCTAssert(g != Generator(factor: .counter(1), secret: Data(), algorithm: .sha1, digits: 6))
XCTAssert(g != Generator(factor: .counter(0), secret: badData, algorithm: .sha1, digits: 6))
XCTAssert(g != Generator(factor: .counter(0), secret: Data(), algorithm: .sha256, digits: 6))
XCTAssert(g != Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 8))
XCTAssert(generator == Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 6))
XCTAssert(generator != Generator(factor: .counter(1), secret: Data(), algorithm: .sha1, digits: 6))
XCTAssert(generator != Generator(factor: .counter(0), secret: badData, algorithm: .sha1, digits: 6))
XCTAssert(generator != Generator(factor: .counter(0), secret: Data(), algorithm: .sha256, digits: 6))
XCTAssert(generator != Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 8))
}

func testTokenEquality() {
guard let generator = Generator(factor: .counter(0), secret: Data(), algorithm: .sha1, digits: 6),
let other_generator = Generator(factor: .counter(1), secret: Data(), algorithm: .sha512, digits: 8) else {
let otherGenerator = Generator(factor: .counter(1), secret: Data(), algorithm: .sha512, digits: 8) else {
XCTFail("Failed to construct Generator.")
return
}

let t = Token(name: "Name", issuer: "Issuer", generator: generator)
let token = Token(name: "Name", issuer: "Issuer", generator: generator)

XCTAssertEqual(t, Token(name: "Name", issuer: "Issuer", generator: generator))
XCTAssertNotEqual(t, Token(name: "", issuer: "Issuer", generator: generator))
XCTAssertNotEqual(t, Token(name: "Name", issuer: "", generator: generator))
XCTAssertNotEqual(t, Token(name: "Name", issuer: "Issuer", generator: other_generator))
XCTAssertEqual(token, Token(name: "Name", issuer: "Issuer", generator: generator))
XCTAssertNotEqual(token, Token(name: "", issuer: "Issuer", generator: generator))
XCTAssertNotEqual(token, Token(name: "Name", issuer: "", generator: generator))
XCTAssertNotEqual(token, Token(name: "Name", issuer: "Issuer", generator: otherGenerator))
}
}
36 changes: 18 additions & 18 deletions Tests/GeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// GeneratorTests.swift
// OneTimePassword
//
// Copyright (c) 2014-2018 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2014-2019 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -47,28 +47,28 @@ class GeneratorTests: XCTestCase {
XCTAssertEqual(generator?.digits, digits)

// Create another generator
let other_factor = OneTimePassword.Generator.Factor.timer(period: 123)
let other_secret = "09876543210987654321".data(using: String.Encoding.ascii)!
let other_algorithm = Generator.Algorithm.sha512
let other_digits = 7
let otherFactor = OneTimePassword.Generator.Factor.timer(period: 123)
let otherSecret = "09876543210987654321".data(using: String.Encoding.ascii)!
let otherAlgorithm = Generator.Algorithm.sha512
let otherDigits = 7

let other_generator = Generator(
factor: other_factor,
secret: other_secret,
algorithm: other_algorithm,
digits: other_digits
let otherGenerator = Generator(
factor: otherFactor,
secret: otherSecret,
algorithm: otherAlgorithm,
digits: otherDigits
)

XCTAssertEqual(other_generator?.factor, other_factor)
XCTAssertEqual(other_generator?.secret, other_secret)
XCTAssertEqual(other_generator?.algorithm, other_algorithm)
XCTAssertEqual(other_generator?.digits, other_digits)
XCTAssertEqual(otherGenerator?.factor, otherFactor)
XCTAssertEqual(otherGenerator?.secret, otherSecret)
XCTAssertEqual(otherGenerator?.algorithm, otherAlgorithm)
XCTAssertEqual(otherGenerator?.digits, otherDigits)

// Ensure the generators are different
XCTAssertNotEqual(generator?.factor, other_generator?.factor)
XCTAssertNotEqual(generator?.secret, other_generator?.secret)
XCTAssertNotEqual(generator?.algorithm, other_generator?.algorithm)
XCTAssertNotEqual(generator?.digits, other_generator?.digits)
XCTAssertNotEqual(generator?.factor, otherGenerator?.factor)
XCTAssertNotEqual(generator?.secret, otherGenerator?.secret)
XCTAssertNotEqual(generator?.algorithm, otherGenerator?.algorithm)
XCTAssertNotEqual(generator?.digits, otherGenerator?.digits)
}

func testCounter() {
Expand Down
40 changes: 20 additions & 20 deletions Tests/TokenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TokenTests.swift
// OneTimePassword
//
// Copyright (c) 2014-2017 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2014-2019 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -55,9 +55,9 @@ class TokenTests: XCTestCase {
XCTAssertEqual(token.generator, generator)

// Create another token
let other_name = "Other Test Name"
let other_issuer = "Other Test Issuer"
guard let other_generator = Generator(
let otherName = "Other Test Name"
let otherIssuer = "Other Test Issuer"
guard let otherGenerator = Generator(
factor: .timer(period: 123),
secret: otherSecretData,
algorithm: .sha512,
Expand All @@ -67,20 +67,20 @@ class TokenTests: XCTestCase {
return
}

let other_token = Token(
name: other_name,
issuer: other_issuer,
generator: other_generator
let otherToken = Token(
name: otherName,
issuer: otherIssuer,
generator: otherGenerator
)

XCTAssertEqual(other_token.name, other_name)
XCTAssertEqual(other_token.issuer, other_issuer)
XCTAssertEqual(other_token.generator, other_generator)
XCTAssertEqual(otherToken.name, otherName)
XCTAssertEqual(otherToken.issuer, otherIssuer)
XCTAssertEqual(otherToken.generator, otherGenerator)

// Ensure the tokens are different
XCTAssertNotEqual(token.name, other_token.name)
XCTAssertNotEqual(token.issuer, other_token.issuer)
XCTAssertNotEqual(token.generator, other_token.generator)
XCTAssertNotEqual(token.name, otherToken.name)
XCTAssertNotEqual(token.issuer, otherToken.issuer)
XCTAssertNotEqual(token.generator, otherToken.generator)
}

func testDefaults() {
Expand All @@ -93,15 +93,15 @@ class TokenTests: XCTestCase {
XCTFail("Failed to construct Generator.")
return
}
let n = "Test Name"
let i = "Test Issuer"
let name = "Test Name"
let issuer = "Test Issuer"

let tokenWithDefaultName = Token(issuer: i, generator: generator)
let tokenWithDefaultName = Token(issuer: issuer, generator: generator)
XCTAssertEqual(tokenWithDefaultName.name, "")
XCTAssertEqual(tokenWithDefaultName.issuer, i)
XCTAssertEqual(tokenWithDefaultName.issuer, issuer)

let tokenWithDefaultIssuer = Token(name: n, generator: generator)
XCTAssertEqual(tokenWithDefaultIssuer.name, n)
let tokenWithDefaultIssuer = Token(name: name, generator: generator)
XCTAssertEqual(tokenWithDefaultIssuer.name, name)
XCTAssertEqual(tokenWithDefaultIssuer.issuer, "")

let tokenWithAllDefaults = Token(generator: generator)
Expand Down