-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up the code that detects labels in
swiftformat_pkg
(#21)
- Loading branch information
Showing
14 changed files
with
198 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- Generated with Stardoc, Do Not Edit! --> | ||
# Build API | ||
|
||
The APIs list below are used by rules_swiftformat. | ||
|
||
* [src_utils](/doc/src_utils.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- Generated with Stardoc, Do Not Edit! --> | ||
# `src_utils` API | ||
|
||
|
||
<a id="#src_utils.is_path"></a> | ||
|
||
## src_utils.is_path | ||
|
||
<pre> | ||
src_utils.is_path(<a href="#src_utils.is_path-src">src</a>) | ||
</pre> | ||
|
||
Determines whether the provided string is a path. | ||
|
||
**PARAMETERS** | ||
|
||
|
||
| Name | Description | Default Value | | ||
| :------------- | :------------- | :------------- | | ||
| <a id="src_utils.is_path-src"></a>src | A <code>string</code> value. | none | | ||
|
||
|
||
<a id="#src_utils.is_label"></a> | ||
|
||
## src_utils.is_label | ||
|
||
<pre> | ||
src_utils.is_label(<a href="#src_utils.is_label-src">src</a>) | ||
</pre> | ||
|
||
Determines whether the provided string is a label. | ||
|
||
**PARAMETERS** | ||
|
||
|
||
| Name | Description | Default Value | | ||
| :------------- | :------------- | :------------- | | ||
| <a id="src_utils.is_label-src"></a>src | A <code>string</code> value. | none | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def _is_label(src): | ||
"""Determines whether the provided string is a label. | ||
Args: | ||
src: A `string` value. | ||
Returns: | ||
A `bool` specifying whether the `string` value looks like a label. | ||
""" | ||
return src.find("//") > -1 or src.find(":") > -1 | ||
|
||
def _is_path(src): | ||
"""Determines whether the provided string is a path. | ||
Args: | ||
src: A `string` value. | ||
Returns: | ||
A `bool` specifying whether the `string` value looks like a path. | ||
""" | ||
return not _is_label(src) | ||
|
||
src_utils = struct( | ||
is_path = _is_path, | ||
is_label = _is_label, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") | ||
load("//swiftformat/internal:src_utils.bzl", "src_utils") | ||
|
||
def _is_label_test(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
asserts.true(env, src_utils.is_label("//Sources/Foo")) | ||
asserts.true(env, src_utils.is_label(":Foo")) | ||
asserts.true(env, src_utils.is_label("//Sources/Foo:bar")) | ||
asserts.false(env, src_utils.is_label("Bar.swift")) | ||
asserts.false(env, src_utils.is_label("path/to/Bar.swift")) | ||
|
||
return unittest.end(env) | ||
|
||
is_label_test = unittest.make(_is_label_test) | ||
|
||
def _is_path_test(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
asserts.true(env, src_utils.is_path("Bar.swift")) | ||
asserts.true(env, src_utils.is_path("path/to/Bar.swift")) | ||
asserts.false(env, src_utils.is_path("//Sources/Foo")) | ||
asserts.false(env, src_utils.is_path(":Foo")) | ||
asserts.false(env, src_utils.is_path("//Sources/Foo:bar")) | ||
|
||
return unittest.end(env) | ||
|
||
is_path_test = unittest.make(_is_path_test) | ||
|
||
def src_utils_test_suite(): | ||
return unittest.suite( | ||
"src_utils_tests", | ||
is_label_test, | ||
is_path_test, | ||
) |