From 5289388f48e158f25cfab318d1fc0f1afd6b7406 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Sat, 27 Apr 2019 17:06:03 -0400 Subject: [PATCH 1/2] [Lint] Clean up identifier names in the tests --- .swiftlint.yml | 1 - Tests/EquatableTests.swift | 66 +++++++++++++++++++------------------- Tests/GeneratorTests.swift | 36 ++++++++++----------- Tests/TokenTests.swift | 40 +++++++++++------------ 4 files changed, 71 insertions(+), 72 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 4bb6053f..ea0d50d5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -60,7 +60,6 @@ opt_in_rules: - yoda_condition disabled_rules: - cyclomatic_complexity - - identifier_name colon: flexible_right_spacing: true diff --git a/Tests/EquatableTests.swift b/Tests/EquatableTests.swift index c822115f..639003e5 100644 --- a/Tests/EquatableTests.swift +++ b/Tests/EquatableTests.swift @@ -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 @@ -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)) } } diff --git a/Tests/GeneratorTests.swift b/Tests/GeneratorTests.swift index 0251814b..0c51ee1f 100644 --- a/Tests/GeneratorTests.swift +++ b/Tests/GeneratorTests.swift @@ -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 @@ -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() { diff --git a/Tests/TokenTests.swift b/Tests/TokenTests.swift index a1ba2495..1f0aa279 100644 --- a/Tests/TokenTests.swift +++ b/Tests/TokenTests.swift @@ -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 @@ -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, @@ -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() { @@ -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) From 8dc579767e205dc6892184aaa98c02f2be75ed0e Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Sat, 24 Aug 2019 12:40:05 -0400 Subject: [PATCH 2/2] [Lint] Enable several new opt-in SwiftLint rules Also, update the entry for the renamed `unused_declaration` rule. --- .swiftlint.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index ea0d50d5..1a360b29 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -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 @@ -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 @@ -53,11 +58,16 @@ 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