{"id":13466017,"url":"https://github.com/ra1028/swift-mod","last_synced_at":"2025-06-29T12:33:49.569Z","repository":{"id":39796496,"uuid":"228456817","full_name":"ra1028/swift-mod","owner":"ra1028","description":"A tool for Swift code modification intermediating between code generation and formatting.","archived":false,"fork":false,"pushed_at":"2024-11-27T05:25:43.000Z","size":128,"stargazers_count":109,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T19:08:05.742Z","etag":null,"topics":["ast","cli","code-generator","code-modification","formatter","swift","swiftsyntax"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ra1028.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-16T19:10:36.000Z","updated_at":"2025-02-26T08:58:07.000Z","dependencies_parsed_at":"2025-02-11T11:42:26.763Z","dependency_job_id":null,"html_url":"https://github.com/ra1028/swift-mod","commit_stats":{"total_commits":53,"total_committers":3,"mean_commits":"17.666666666666668","dds":"0.24528301886792447","last_synced_commit":"e6f2bca3c9db818d9b71e6f7e7e632a6c8057603"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ra1028%2Fswift-mod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ra1028%2Fswift-mod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ra1028%2Fswift-mod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ra1028%2Fswift-mod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ra1028","download_url":"https://codeload.github.com/ra1028/swift-mod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393572,"owners_count":20931813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","cli","code-generator","code-modification","formatter","swift","swiftsyntax"],"created_at":"2024-07-31T15:00:38.104Z","updated_at":"2025-04-05T20:09:22.774Z","avatar_url":"https://github.com/ra1028.png","language":"Swift","readme":"# swift-mod\n\nA tool for Swift code modification intermediating between code generation and formatting.\n\n[![swift](https://img.shields.io/badge/language-Swift5-orange.svg)](https://developer.apple.com/swift)\n[![release](https://img.shields.io/github/release/ra1028/swift-mod.svg)](https://github.com/ra1028/swift-mod/releases/latest)\n[![test](https://github.com/ra1028/swift-mod/workflows/GitHub%20Actions/badge.svg)](https://github.com/ra1028/swift-mod/actions)\n[![lincense](http://img.shields.io/badge/License-Apache%202.0-black.svg)](https://github.com/ra1028/swift-mod/blob/master/LICENSE)\n\n---\n\n## Overview\n\n`swift-mod` is a tool for Swift code modification that intermediating between code generator and formatter built on top of [apple/SwiftSyntax](https://github.com/apple/swift-syntax).  \nIt can generates boilerplate code, such as access control or memberwise initializers in modularized source code, taking into account the state of the [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree).  \nYou can improve your productivity for writing more advanced Swift codes by introducing `swift-mod`.  \n\n### Example\n\n- **Before**\n\n```swift\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n}\n\nlet avengers = [\n    Avenger(heroName: \"Iron Man\", realName: \"Tony Stark\"),\n    Avenger(heroName: \"Captain America\", realName: \"Steve Rogers\"),\n    Avenger(heroName: \"Thor\"),\n]\n\n```\n\n- **After**\n\n```diff\n+ public struct Avenger {\n+     public var heroName: String\n    internal var realName: String?\n\n+     public init(\n+         heroName: String,\n+         realName: String? = nil\n+     ) {\n+         self.heroName = heroName\n+         self.realName = realName\n+     }\n}\n\n+ public let avengers = [\n    Avenger(heroName: \"Iron Man\", realName: \"Tony Stark\"),\n    Avenger(heroName: \"Captain America\", realName: \"Steve Rogers\"),\n    Avenger(heroName: \"Thor\"),\n]\n```\n\n---\n\n## Getting Started\n\n1. [Install `swift-mod`](#installation).\n\n2. Generates configuration file.\n\n```sh\nswift-mod init\n```\n\n3. Check the all modification rules.\n\n```sh\nswift-mod rules\nswift-mod rules --rule [RULE NAME] # Display more detailed rule description\n```\n\n4. Edit your configuration file with an editor you like, refering to the [documentation](#configuration).\n\n5. Run\n\n```sh\nswift-mod \u003clist of input files\u003e\n```\n\n---\n\n## Command Usage\n\n```sh\nswift-mod [COMMAND] [OPTIONS]\n```\n\nAll commands can be display a usage by option `-h/--help`.\n\n- `run` (or not specified)\n\n```\nOVERVIEW: Runs modification.\n\nUSAGE: swift-mod run [--mode \u003cmode\u003e] [--configuration \u003cconfiguration\u003e] [\u003cpaths\u003e ...]\n\nARGUMENTS:\n  \u003cpaths\u003e                 Zero or more input filenames.\n\nOPTIONS:\n  -m, --mode \u003cmode\u003e                   Overrides running mode: modify|dry-run|check. (default: modify)\n  -c, --configuration \u003cconfiguration\u003e The path to a configuration file.\n  -h, --help                          Show help information.\n```\n\n- `init`\n\n```\nOVERVIEW: Generates a modify configuration file.\n\nUSAGE: swift-mod init [--output \u003coutput\u003e]\n\nOPTIONS:\n  -o, --output \u003coutput\u003e   An output for the configuration file to be generated.\n  -h, --help              Show help information.\n```\n\n- `rules`\n\n```\nOVERVIEW: Display the list of rules.\n\nUSAGE: swift-mod rules [--rule \u003crule\u003e]\n\nOPTIONS:\n  -r, --rule \u003crule\u003e       A rule name to see detail.\n  -h, --help              Show help information.\n```\n\n---\n\n## Configuration\n\nModification rules and targets are defines with YAML-formatted file. By default, it's searched by name `.swift-mod.yml`.  \nAny file name is allowed with passing with option like follows:  \n\n```sh\nswift-mod --configuration \u003cconfiguration\u003e\n```\n\n### Example\n\n```yaml\nformat:\n  indent: 4\n  lineBreakBeforeEachArgument: true\nrules:\n  defaultAccessLevel:\n    accessLevel: openOrPublic\n    implicitInternal: true\n  defaultMemberwiseInitializer:\n    implicitInitializer: false\n    implicitInternal: true\n    ignoreClassesWithInheritance: false\n```\n\n### Format\n\nDetermines the format setting in all rules.  \nFormat according to this setting only when changes occur.  \n\n|KEY|VALUE|REQUIREMENT|DEFAULT|\n|:-|:-|:-|:-|\n|indent|The number of spaces, or `tab` by text|Optional|4|\n|lineBreakBeforeEachArgument|Indicating whether to insert new lines before each function argument|Optional|true|\n\n### Rules\n\n#### Default Access Level\n\n|IDENTIFIER|OVERVIEW|\n|:-|:-|\n|defaultAccessLevel|Assigns the suitable access level to all declaration syntaxes if not present|\n\n|KEY|VALUE|REQUIREMENT|DEFAULT|\n|:-|:-|:-|:-|\n|accessLevel|\\|openOrPublic\\|public\\|internal\\|fileprivate\\|private\\||Required||\n|implicitInternal|Indicating whether to omit the `internal` access level|Optional|true|\n\n```swift\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n}\n```\n\n```diff\n+ public struct Avenger {\n+    public var heroName: String\n    internal var realName: String?\n}\n```\n\n#### Default Memberwise Initializer\n\n|IDENTIFIER|OVERVIEW|\n|:-|:-|\n|defaultMemberwiseInitializer|Defines a memberwise initializer according to the access level in the type declaration if not present|\n\n|KEY|VALUE|REQUIREMENT|DEFAULT|\n|:-|:-|:-|:-|\n|implicitInitializer|Indicating whether to omit the `internal` initializer in struct decalaration|Optional|false|\n|implicitInternal|Indicating whether to omit the `internal` access level|Optional|true|\n|ignoreClassesWithInheritance|Indicating whether to skip the classes having inheritance including protocol|Optional|false|\n\n```swift\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n}\n```\n\n```diff\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n\n+    init(\n+        heroName: String,\n+        realName: String? = nil\n+    ) {\n+        self.heroName = heroName\n+        self.realName = realName\n+    }\n}\n```\n\n---\n\n### Ignoring Rules\n\n`swift-mod` allows users to suppress modification for node and its children by comment like below.  \n\n- **Ignore all rules**  \n\n`// swift-mod-ignore`  \n\n```swift\n// swift-mod-ignore\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n}\n```\n\n- **Ignore specific rule(s)**  \n\n`// swift-mod-ignore: [COMMA DELIMITED RULE IDENTIFIERS]`\n\n```swift\n// swift-mod-ignore: defaultAccessLevel, defaultMemberwiseInitializer\nstruct Avenger {\n    var heroName: String\n    internal var realName: String?\n}\n```\n\n---\n\n## Installation\n\n### [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nAdd the following to the dependencies of your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/ra1028/swift-mod.git\", from: \"swift-mod version\"),\n]\n```\n\nRun command:\n\n```sh\nswift run -c release swift-mod [COMMAND] [OPTIONS]\n```\n\n### [Mint](https://github.com/yonaskolb/Mint)\n\nInstall with Mint by following command:\n\n```sh\nmint install ra1028/swift-mod\n```\n\nRun command:\n\n```sh\nmint run ra1028/swift-mod [COMMAND] [OPTIONS]\n```\n\n### Using a pre-built binary\n\nYou can also install swift-mod by downloading `swift-mod.zip` from the latest GitHub release.\n\n### Swift Version Support\n\n`swift-mod` depends on [SwiftSyntax](https://github.com/apple/swift-syntax) version that matches the toolchain version in use.  \nSo you should use swift-mod version that built with compatible version of Swift you are using.\n\n|Swift Version|Last Supported `swift-mod`      |\n|:------------|:-------------------------------|\n|5.1          |0.0.2                           |\n|5.2          |0.0.4                           |\n|5.3          |0.0.5                           |\n|5.4          |0.0.6                           |\n|5.5          |0.0.7                           |\n|5.6          |0.1.0                           |\n|5.7          |0.1.1                           |\n|5.8          |0.2.0                           |\n|5.9          |0.2.0                           |\n|5.10         |0.2.1                           |\n\n---\n\n## Development\n\nPull requests, bug reports and feature requests are welcome 🚀.  \nSee [CONTRIBUTING.md](./CONTRIBUTING.md) file to learn how to contribute to swift-mod.  \n\nPlease validate and test your code before you submit your changes by following commands:  \n\n```sh\n make autocorrect # Modifying, formatting, linting codes and generating Linux XCTest manifests.  \n make test\n ```\n\nIn addition, swift-mod supports running on Linux, so you should test by installing Docker and following command:  \n\n```sh\nmake docker-test\n```\n\n---\n\n## License\n\nswift-mod is released under the [Apache 2.0 License](https://github.com/ra1028/swift-mod/blob/master/LICENSE).\n","funding_links":[],"categories":["Libs","Quality [🔝](#readme)"],"sub_categories":["Quality"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fra1028%2Fswift-mod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fra1028%2Fswift-mod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fra1028%2Fswift-mod/lists"}