Skip to content

Commit

Permalink
Fix false positive on file_name rule when using nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelofabri authored and sjavora committed Mar 9, 2019
1 parent 6d77463 commit e684e09
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#2345](https://github.com/realm/SwiftLint/pull/2345)

* Fix false positive on `file_name` rule when using nested types.
[Marcelo Fabri](https://github.com/marcelofabri)
[#2325](https://github.com/realm/SwiftLint/issues/2325)

## 0.27.0: Heavy Duty

#### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct FileNameRule: ConfigurationProviderRule, OptInRule {
let prefixRegex = regex("\\A\(configuration.prefixPattern)")
let suffixRegex = regex("\(configuration.suffixPattern)\\z")

var typeInFileName = fileName.components(separatedBy: ".").first ?? fileName
var typeInFileName = fileName.bridge().deletingPathExtension

if let match = prefixRegex.firstMatch(in: typeInFileName, options: [], range: typeInFileName.fullNSRange),
let range = typeInFileName.nsrangeToIndexRange(match.range) {
Expand Down
8 changes: 8 additions & 0 deletions SwiftLint.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
D48AE2CC1DFB58C5001C6A4A /* AttributesRuleExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48AE2CB1DFB58C5001C6A4A /* AttributesRuleExamples.swift */; };
D48B51211F4F5DEF0068AB98 /* RuleList+Documentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B51201F4F5DEF0068AB98 /* RuleList+Documentation.swift */; };
D48B51231F4F5E4B0068AB98 /* DocumentationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B51221F4F5E4B0068AB98 /* DocumentationTests.swift */; };
D495B1A221165DAA00E2CD7B /* FileNameRuleFixtures in Resources */ = {isa = PBXBuildFile; fileRef = D495B1A021165DAA00E2CD7B /* FileNameRuleFixtures */; };
D495B1A321165DAA00E2CD7B /* FileHeaderRuleFixtures in Resources */ = {isa = PBXBuildFile; fileRef = D495B1A121165DAA00E2CD7B /* FileHeaderRuleFixtures */; };
D49896F12026B36C00814A83 /* RedundantSetAccessControlRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D49896F02026B36C00814A83 /* RedundantSetAccessControlRule.swift */; };
D4998DE71DF191380006E05D /* AttributesRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE61DF191380006E05D /* AttributesRuleTests.swift */; };
D4998DE91DF194F20006E05D /* FileHeaderRuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4998DE81DF194F20006E05D /* FileHeaderRuleTests.swift */; };
Expand Down Expand Up @@ -653,6 +655,8 @@
D48AE2CB1DFB58C5001C6A4A /* AttributesRuleExamples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributesRuleExamples.swift; sourceTree = "<group>"; };
D48B51201F4F5DEF0068AB98 /* RuleList+Documentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RuleList+Documentation.swift"; sourceTree = "<group>"; };
D48B51221F4F5E4B0068AB98 /* DocumentationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentationTests.swift; sourceTree = "<group>"; };
D495B1A021165DAA00E2CD7B /* FileNameRuleFixtures */ = {isa = PBXFileReference; lastKnownFileType = folder; path = FileNameRuleFixtures; sourceTree = "<group>"; };
D495B1A121165DAA00E2CD7B /* FileHeaderRuleFixtures */ = {isa = PBXFileReference; lastKnownFileType = folder; path = FileHeaderRuleFixtures; sourceTree = "<group>"; };
D49896F02026B36C00814A83 /* RedundantSetAccessControlRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedundantSetAccessControlRule.swift; sourceTree = "<group>"; };
D4998DE61DF191380006E05D /* AttributesRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributesRuleTests.swift; sourceTree = "<group>"; };
D4998DE81DF194F20006E05D /* FileHeaderRuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHeaderRuleTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -815,6 +819,8 @@
3B12C9BE1C3209AC000B423F /* Resources */ = {
isa = PBXGroup;
children = (
D495B1A121165DAA00E2CD7B /* FileHeaderRuleFixtures */,
D495B1A021165DAA00E2CD7B /* FileNameRuleFixtures */,
3B12C9BF1C3209AC000B423F /* test.yml */,
3BDB224A1C345B4900473680 /* ProjectMock */,
F9D73F021D0CF15E00222FC4 /* test.txt */,
Expand Down Expand Up @@ -1558,10 +1564,12 @@
B3935371E92E0CF3F7668303 /* CannedJunitReporterOutput.xml in Resources */,
B39357173B43C9B5E351C360 /* CannedCheckstyleReporterOutput.xml in Resources */,
B3935A32BE03C4D11B4364D6 /* CannedCSVReporterOutput.csv in Resources */,
D495B1A321165DAA00E2CD7B /* FileHeaderRuleFixtures in Resources */,
B3935522DC192D38D4852FA3 /* CannedXcodeReporterOutput.txt in Resources */,
6CC898A71EA0E1F7003DC0E2 /* CannedEmojiReporterOutputNonObjC.txt in Resources */,
B39358AA2D2AF5219D3FD7C0 /* CannedEmojiReporterOutput.txt in Resources */,
B3935A1C3BCA03A6B902E7AF /* CannedJSONReporterOutput.json in Resources */,
D495B1A221165DAA00E2CD7B /* FileNameRuleFixtures in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ extension FileNameRuleTests {
("testClassNameDoesntTrigger", testClassNameDoesntTrigger),
("testStructNameDoesntTrigger", testStructNameDoesntTrigger),
("testExtensionNameDoesntTrigger", testExtensionNameDoesntTrigger),
("testNestedExtensionDoesntTrigger", testNestedExtensionDoesntTrigger),
("testMisspelledNameDoesTrigger", testMisspelledNameDoesTrigger),
("testMisspelledNameDoesntTriggerWithOverride", testMisspelledNameDoesntTriggerWithOverride),
("testMainDoesTriggerWithoutOverride", testMainDoesTriggerWithoutOverride),
Expand Down
4 changes: 4 additions & 0 deletions Tests/SwiftLintFrameworkTests/FileNameRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class FileNameRuleTests: XCTestCase {
XCTAssert(try validate(fileName: "NSString+Extension.swift").isEmpty)
}

func testNestedExtensionDoesntTrigger() {
XCTAssert(try validate(fileName: "Notification.Name+Extension.swift").isEmpty)
}

func testMisspelledNameDoesTrigger() {
XCTAssertEqual(try validate(fileName: "MyStructf.swift").count, 1)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Foundation

extension Notification.Name {
}

0 comments on commit e684e09

Please sign in to comment.