Skip to content
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
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template: |
## What’s Changed
$CHANGES
44 changes: 44 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Create Release

on:
push:
branches:
- master

jobs:
# We create a new version if the branch is master.
version_and_publish:
name: Create Release
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.generate_version.outputs.release_version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
# In future we should run tests to ensure if it's worth making a release.
- name: Install semantic-release
run: |
npm set registry https://registry.npmjs.org/
sudo npm install -g \
semantic-release \
@semantic-release/commit-analyzer \
@semantic-release/github \
@semantic-release/exec \
@semantic-release/release-notes-generator \
conventional-changelog-conventionalcommits

- name: Generate version
id: generate_version
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
npx semantic-release --ci

- name: No Releases Done
if: "!steps.generate_version.outputs.release_version"
run: |
echo "No Release was done either due to wrong commit or no major changes."
23 changes: 23 additions & 0 deletions .github/workflows/release_drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- dev
pull_request:
types: [opened, reopened, synchronize]

permissions:
contents: read

jobs:
update_release_draft:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
47 changes: 47 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"branches": ["main"],
"tagFormat": "${version}",
"plugins": [
[
"@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"releaseRules": [
{"type": "doc", "release": false},
{"type": "test", "release": false},
{"type": "chore", "release": "patch"},
{"type": "devx", "release": false}
],
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
}
}
],
"@semantic-release/github",
[
"@semantic-release/exec", {
"publishCmd": "echo \"::set-output name=release_version::${nextRelease.version}\""
}
],
[
"@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{"type": "feat", "section": "Features"},
{"type": "fix", "section": "Bug Fixes"},
{"type": "doc", "section": "Documentation", "hidden": true},
{"type": "test", "section": "Tests", "hidden": true},
{"type": "chore", "section": "Chore / Improvements"},
{"type": "devx", "section": "Improved Developer Experience", "hidden": false}
]
},
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
},
"writerOpts": {
"commitsSort": ["subject", "scope"]
}
}
]
]
}
8 changes: 3 additions & 5 deletions Core/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ enum AccessControl: String, CaseIterable {
case .internal:
// The default access control type, no need to explicitly set it
return ""
case .private:
return "private "
case .public:
return "public "
default:
return rawValue
}
}
}
Expand Down Expand Up @@ -76,6 +74,6 @@ enum PropertyType: String {
}

/// Place to store actual constants that don't fit in classes.
struct Constants {
enum Constants {
static let filePathKey: String = "path"
}
2 changes: 1 addition & 1 deletion Core/Generator/FileGeneratorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension FileGenerator {

- returns: Boolean indicating if the process was successful.
*/
internal static func writeToFileWith(_ name: String, content: String, path: String) throws {
static func writeToFileWith(_ name: String, content: String, path: String) throws {
let filename = path.appendingFormat("%@", name + ".swift")
try FileManager.default.createDirectory(at: URL(fileURLWithPath: path),
withIntermediateDirectories: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ struct SwiftJSONModelFile: ModelFile {

func genPrimitiveVariableDeclaration(_ name: String, _ type: String, _ isOptional: Bool) -> String {
let optionalSuffix = isOptional ? "?" : ""
return "\(accessControl.declarationPrefix)var \(name): \(type)\(optionalSuffix)"
var declrationPrefix = ""
if !accessControl.declarationPrefix.isEmpty {
declrationPrefix = "\(accessControl.declarationPrefix) "
}
return "\(declrationPrefix)var \(name): \(type)\(optionalSuffix)"
}

/// Generate the variable declaration string
Expand Down
2 changes: 1 addition & 1 deletion Core/Generator/MultipleModelGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum MultipleModelGeneratorError: Error, Equatable {
}

/// A structure to generate multiple mdoels from JSON files at once.
struct MultipleModelGenerator {
enum MultipleModelGenerator {
/// Generate models for the JSON files in the given path. Use the `.config.json` to load config.
///
/// - Parameter forPath: Path with the JSON files.
Expand Down
45 changes: 22 additions & 23 deletions Core/Generator/NameGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,36 @@ struct NameGenerator {
/// - Parameter currentName: The current name which has to be checked.
/// - Returns: New name for the variable.
static func replaceKeywords(_ currentName: String) -> String {

/// Swift keywords from https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413 as of 2020-10-10
/// Does not include the "sometimes" keywords
/// Thanks to a PR from @TheMadBug.
let swiftKeywords: Set = [
"associatedtype", "class", "deinit",
"enum", "extension", "fileprivate",
"func", "import", "init",
"inout", "internal", "let",
"open", "operator", "private",
"protocol", "public", "rethrows",
"static", "struct", "subscript",
"typealias", "var",
"break", "case", "continue",
"default", "defer", "do",
"else", "fallthrough", "for",
"guard", "if", "in",
"repeat", "return", "switch",
"where", "while",
"as", "Any", "catch",
"false", "is", "nil",
"super", "self", "Self",
"throw", "throws", "true",
"try"
]
"associatedtype", "class", "deinit",
"enum", "extension", "fileprivate",
"func", "import", "init",
"inout", "internal", "let",
"open", "operator", "private",
"protocol", "public", "rethrows",
"static", "struct", "subscript",
"typealias", "var",
"break", "case", "continue",
"default", "defer", "do",
"else", "fallthrough", "for",
"guard", "if", "in",
"repeat", "return", "switch",
"where", "while",
"as", "Any", "catch",
"false", "is", "nil",
"super", "self", "Self",
"throw", "throws", "true",
"try",
]

var keywordsWithReplacements: [String: String] = [:]
for keyword in swiftKeywords {
keywordsWithReplacements[keyword] = "\(keyword)Value"
}

if let value = keywordsWithReplacements[currentName] {
return value
}
Expand Down
9 changes: 6 additions & 3 deletions Core/Helpers/JSONHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct JSONParserResponse {
}

/// Provide helpers to handle JSON content that the user provided.
struct JSONHelper {
enum JSONHelper {
/// Validate if the string that is provided can be converted into a valid JSON.
///
/// - Parameter jsonString: Input string that is to be checked as JSON.
Expand Down Expand Up @@ -77,16 +77,19 @@ struct JSONHelper {
/// - Parameter items: An array of JSON items that have to be reduced.
/// - Returns: Reduced JSON with the common key/value pairs.
static func reduce(_ items: [JSON]) -> JSON {
return items.reduce([:]) { (source, item) -> JSON in
return items.reduce([:]) { source, item -> JSON in
var finalObject = source
for (key, jsonValue) in item {
if let newValue = jsonValue.dictionary {
finalObject[key] = reduce([JSON(newValue), finalObject[key]])
} else if let newValue = jsonValue.array, newValue.first != nil && (newValue.first!.dictionary != nil || newValue.first!.array != nil) {
finalObject[key] = JSON([reduce(newValue + finalObject[key].arrayValue)])
// swiftlint:disable all
// swift-format-ignore
} else if jsonValue != JSON.null || !finalObject[key].exists() {
finalObject[key] = jsonValue
}
// swiftlint:enable all
}
return finalObject
}
Expand Down Expand Up @@ -126,7 +129,7 @@ extension JSON {
.cgFloatType,
.doubleType:
return .float
// Covers any future types for CFNumber.
// Covers any future types for CFNumber.
@unknown default:
return .float
}
Expand Down
6 changes: 5 additions & 1 deletion SwiftyJSONAccelerator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1030;
LastUpgradeCheck = 1030;
LastUpgradeCheck = 1340;
ORGANIZATIONNAME = "Karthikeya Udupa";
TargetAttributes = {
93E0F10322E859D5008D3B16 = {
Expand Down Expand Up @@ -617,6 +617,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -678,6 +679,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -712,6 +714,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 14;
Expand All @@ -735,6 +738,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SwiftyJSONAccelerator/Support/SwiftyJSONAccelerator.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 14;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,11 +26,20 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
systemAttachmentLifetime = "keepNever"
userAttachmentLifetime = "keepAlways"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
onlyGenerateCoverageForSpecifiedTargets = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "93E0F10322E859D5008D3B16"
BuildableName = "SwiftyJSONAccelerator.app"
BlueprintName = "SwiftyJSONAccelerator"
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
</BuildableReference>
</MacroExpansion>
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -54,17 +63,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "93E0F10322E859D5008D3B16"
BuildableName = "SwiftyJSONAccelerator.app"
BlueprintName = "SwiftyJSONAccelerator"
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -86,8 +84,6 @@
ReferencedContainer = "container:SwiftyJSONAccelerator.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,17 @@ class LineNumberRulerView: NSRulerView {
ruleThickness = 40
}

@available(*, unavailable)
required init(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func drawHashMarksAndLabels(in _: NSRect) {
if let textView = self.clientView as? NSTextView {
if let textView = clientView as? NSTextView {
if let layoutManager = textView.layoutManager {
let relativePoint = convert(NSZeroPoint, from: textView)
let lineNumberAttributes = [NSAttributedString.Key.font.rawValue: textView.font!, NSAttributedString.Key.foregroundColor: NSColor.gray] as! [NSAttributedString.Key: Any]
let drawLineNumber = { (lineNumberString: String, y: CGFloat) -> Void in
let drawLineNumber = { (lineNumberString: String, y: CGFloat) in
let attString = NSAttributedString(string: lineNumberString, attributes: lineNumberAttributes)
let x = 35 - attString.size().width
attString.draw(at: NSPoint(x: x, y: relativePoint.y + y))
Expand Down
Loading