Skip to content

Commit

Permalink
Add swiftlint / swiftformat in Package.swift, fix issues (#168)
Browse files Browse the repository at this point in the history
- Add swiftlint / swiftformat in Package.swift and invoke with `swift
run`
- Fix lint issues
- Format codebase
- Update Makefile and scripts to use `swift run swiftlint` and `swift
run swiftformat`
- Define swiftformat settings to .swiftformat file
- Update lint script to check for formatting errors
  • Loading branch information
rahul-malik authored Feb 28, 2019
1 parent 7d4ceb6 commit 1d44870
Show file tree
Hide file tree
Showing 44 changed files with 1,075 additions and 998 deletions.
3 changes: 3 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--swiftversion 4.2
--disable andOperator

2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ disabled_rules: # rule identifiers to exclude from running
- line_length
- cyclomatic_complexity
- file_length
- trailing_comma
included: # paths to include during linting. `--path` is ignored if present.
- Sources
- Tests
Expand All @@ -18,4 +19,3 @@ type_body_length:
- 500 # error

reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)

1 change: 0 additions & 1 deletion Examples/Cocoa/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import PackageDescription
let package = Package(
name: "Objective_C"
)

2 changes: 1 addition & 1 deletion Examples/Cocoa/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import ObjcTestSuite
import XCTest
XCTMain([
testCase(ObjcTestSuite.allTests),
])
37 changes: 18 additions & 19 deletions Examples/Cocoa/Tests/Objective_CTests/ObjcJSBridgingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import XCTest
@testable import Objective_C

class ObjcJavaScriptCoreBridgingTestSuite: XCTestCase {

static let _context: JSContext = JSContext()!

override class func setUp() {
super.setUp();
injectJSFileIntoContext(fileName: "bundle", context: _context);
super.setUp()
injectJSFileIntoContext(fileName: "bundle", context: _context)
}

// Inject a js file located in plank/Examples/Shared/
class func injectJSFileIntoContext(fileName: String, context: JSContext) {
let jsFileName = "\(fileName).js"
// The currentDirectoryPath is: plank/Examples/Cocoa/
let currentPath = FileManager.default.currentDirectoryPath

let pathURL = URL(fileURLWithPath: currentPath)
let finalPathURL = pathURL.appendingPathComponent("..")
.appendingPathComponent("Shared")
Expand All @@ -30,40 +29,40 @@ class ObjcJavaScriptCoreBridgingTestSuite: XCTestCase {
print("Couldn't inject \(jsFileName) into JSContext")
}
}

var context: JSContext {
return ObjcJavaScriptCoreBridgingTestSuite._context
}

func testImageModelBridgingGetImage() {
// Expected modelc dictionary
let imageModelDictionary: JSONDict = [
"height": 300,
"width": 200,
"url": "https://picsum.photos/200/300"
"url": "https://picsum.photos/200/300",
]
let expectedImage = Image(modelDictionary: imageModelDictionary);
let expectedImage = Image(modelDictionary: imageModelDictionary)
let expectedImageDictionaryRepresentation = expectedImage.dictionaryObjectRepresentation()

// Get image from js context
let getTestImageModelJSONFunction = context.objectForKeyedSubscript("getTestImageModelJSON")!
let jsImageModel = getTestImageModelJSONFunction.call(withArguments:[]).toObject() as! JSONDict
XCTAssert(expectedImage.isEqual(to: Image(modelDictionary:jsImageModel)))
let jsImageModel = getTestImageModelJSONFunction.call(withArguments: []).toObject() as! JSONDict

XCTAssert(expectedImage.isEqual(to: Image(modelDictionary: jsImageModel)))
XCTAssert(jsImageModel == expectedImageDictionaryRepresentation)
}

func testImageModelBridgingSendImage() {
// Expected model dictionary
let imageModelDictionary: JSONDict = [
"height": 300,
"width": 200,
"url": "https://picsum.photos/200/300"
"url": "https://picsum.photos/200/300",
]
let imageModel = Image(modelDictionary: imageModelDictionary);
let imageModel = Image(modelDictionary: imageModelDictionary)
let imageModelDictionaryRepresentation = imageModel.dictionaryObjectRepresentation()

let testImageModelJSON = context.objectForKeyedSubscript("sendTestImageModelJSON")!
XCTAssert(testImageModelJSON.call(withArguments:[imageModelDictionaryRepresentation]).toBool())
XCTAssert(testImageModelJSON.call(withArguments: [imageModelDictionaryRepresentation]).toBool())
}
}
Loading

0 comments on commit 1d44870

Please sign in to comment.