{"id":16065594,"url":"https://github.com/thii/rules_swiftlint","last_synced_at":"2025-04-05T10:13:43.293Z","repository":{"id":65909134,"uuid":"602070269","full_name":"thii/rules_swiftlint","owner":"thii","description":"Run SwiftLint in your Bazel build efficiently.","archived":false,"fork":false,"pushed_at":"2023-03-12T02:12:26.000Z","size":40,"stargazers_count":25,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-10T20:56:28.156Z","etag":null,"topics":["bazel","bazel-rules","swiftlint","xcode"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2023-02-15T12:42:15.000Z","updated_at":"2024-05-03T09:05:10.000Z","dependencies_parsed_at":"2024-10-31T01:40:46.303Z","dependency_job_id":"61cc5f94-4a11-4c2b-be04-63e832f50ece","html_url":"https://github.com/thii/rules_swiftlint","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thii%2Frules_swiftlint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thii%2Frules_swiftlint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thii%2Frules_swiftlint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thii%2Frules_swiftlint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thii","download_url":"https://codeload.github.com/thii/rules_swiftlint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318746,"owners_count":20919483,"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":["bazel","bazel-rules","swiftlint","xcode"],"created_at":"2024-10-09T05:13:25.153Z","updated_at":"2025-04-05T10:13:43.273Z","avatar_url":"https://github.com/thii.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rules_swiftlint\n\nRun SwiftLint in your Bazel build efficiently.\n\n## Features\n\n- Runs SwiftLint as part of the build/test. There is no need for a pre-build\n  phase in your Xcode project anymore.\n- Operates on a single Swift file at a time. This takes advantage of Bazel's\n  powerful caching and paralleling mechanism and allows for incremental\n  validation. You can even lint your Swift code with remote execution.\n- Knows your dependency graph. The action won't run on your Swift file until\n  you add it to your dependency tree.\n- Simple integration. You just need to add a flag to your `.bazelrc` file and\n  forget about it.\n\n`rules_swiftlint` leverages Bazel's [Validation\nActions](https://bazel.build/extending/rules#validation_actions) to run\nSwiftLint. This is special in that its outputs are always requested, regardless\nof the value of the `--output_groups` flag; and the validation is skipped when\nthe target is depended upon as an implicit dependency, or as a tool, or is\nbuild in the `exec` (or the legacy `host`) configuration—in short, it only runs\non code that goes into your app. It is, however, possible to validate your\nSwift tools by building or testing your tools directly.\n\nNote that `rules_swiftlint` only validates, but does _not_ format your Swift\ncode, because source files are immutable to Bazel during a build or a test. If\nyour workflow requires you to auto-format your Swift code, you need to run\nSwiftLint with `bazel run`:\n\n```\nbazel run @SwiftLint//:swiftlint -- [\u003cSwiftLint flags\u003e]\n```\n\n## Installation\n\n1. WORKSPACE setup\n\na. If you want to use a prebuilt binary of SwiftLint:\n\n```starlark\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nhttp_archive(\n    name = \"SwiftLint\",\n    build_file_content = \"\"\"exports_files([\"swiftlint\"])\"\"\",\n    # Update these two lines whenever you want to update SwiftLint.\n    sha256 = \"47078845857fa7cf8497f5861967c7ce67f91915e073fb3d3114b8b2486a9270\",\n    url = \"https://github.com/realm/SwiftLint/releases/download/0.50.3/portable_swiftlint.zip\",\n)\n\nhttp_archive(\n    name = \"com_github_thii_rules_swiftlint\",\n    sha256 = \"\u003csee https://github.com/thii/rules_swiftlint/releases\u003e\",\n    url = \"\u003csee https://github.com/thii/rules_swiftlint/releases\u003e\",\n)\n\nload(\n    \"@com_github_thii_rules_swiftlint//swiftlint:repositories.bzl\",\n    \"swiftlint_rules_dependencies\",\n)\n\nswiftlint_rules_dependencies()\n\nload(\n    \"@com_github_thii_rules_swiftlint//swiftlint:defs.bzl\",\n    \"swiftlint_register_toolchains\",\n)\n\nswiftlint_register_toolchains()\n```\n\nb. If you want to build SwiftLint from source:\n\n- Follow instructions from https://github.com/bazelbuild/rules_apple/releases\n  to declare `rules_apple`'s dependencies.\n- Follow instructions from https://github.com/realm/SwiftLint/releases to\n  declare `SwiftLint`'s dependencies.\n- Add the following to your WORKSPACE file:\n\n```starlark\nhttp_archive(\n    name = \"com_github_thii_rules_swiftlint\",\n    sha256 = \"\u003csee https://github.com/thii/rules_swiftlint/releases\u003e\",\n    url = \"\u003csee https://github.com/thii/rules_swiftlint/releases\u003e\",\n)\n\nload(\n    \"@com_github_thii_rules_swiftlint//swiftlint:repositories.bzl\",\n    \"swiftlint_rules_dependencies\",\n)\n\nswiftlint_rules_dependencies()\n\nload(\n    \"@com_github_thii_rules_swiftlint//swiftlint:defs.bzl\",\n    \"swiftlint_register_toolchains\",\n)\n\nswiftlint_register_toolchains()\n```\n\n2. Declare a target for your SwiftLint configuration files\n\nSkip this step if you don't have your own SwiftLint configuration file.\n\nDeclare this in your BUILD file (e.g., in the top-level BUILD file). If you\nhave multiple configuration files, add them all to this `filegroup` target.\n\n```starlark\nfilegroup(\n    name = \"swiftlint_config\",\n    srcs = [\".swiftlint.yml\"],\n)\n```\n\n3. Add the following to your `.bazelrc` file\n\n```\nbuild --aspects=@com_github_thii_rules_swiftlint//swiftlint:defs.bzl%swiftlint_aspect\n\n# This flag is only required if you have your own SwiftLint configuration file.\nbuild --@com_github_thii_rules_swiftlint//swiftlint:config=//:swiftlint_config\n```\n\nThen build your target as usual. SwiftLint validation will run as part of the\nbuild and report violations as build warnings and errors.\n\n```\nbazel build //your:target\n```\n\nIf you only want to run SwiftLint validation alone, add a new Bazel config for\nthat, and explicitly request only the `_validation` output group:\n\n```\nbuild:swiftlint --aspects=@com_github_thii_rules_swiftlint//swiftlint:defs.bzl%swiftlint_aspect\nbuild:swiftlint --@com_github_thii_rules_swiftlint//swiftlint:config=//:swiftlint_config\nbuild:swiftlint --output_groups=_validation\n```\n\nThen you can run SwiftLint validation without building your target with:\n\n```\nbazel build --config=swiftlint //your:target\n```\n\nIf you only want to build your target but skip the SwiftLint validation, you\ncan do so by setting the `--norun_validations` (or\n`--run_validations={0,false,no}`) flag in your build.\n\n```\nbazel build --norun_validations //your:target\n```\n\n## Examples\n\n```\nbazel build //examples:main\n```\n\n## Acknowledgments\n\nThis repository uses the Bazel ruleset template from\nhttps://github.com/bazel-contrib/rules-template.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthii%2Frules_swiftlint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthii%2Frules_swiftlint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthii%2Frules_swiftlint/lists"}