-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor shebang parsing to remove regex dependency (#5690)
## Summary Similar to #5567, we can remove the use of regex, plus simplify the representation (use `Option`), add snapshot tests, etc. This is about 100x faster than using a regex for cases that match (2.5ns vs. 250ns). It's obviously not a hot path, but I prefer the consistency with other similar comment-parsing. I may DRY these up into some common functionality later on.
- Loading branch information
1 parent
30bec3f
commit 511ec0d
Showing
10 changed files
with
161 additions
and
128 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
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
5 changes: 5 additions & 0 deletions
5
...utable/snapshots/ruff__rules__flake8_executable__helpers__tests__shebang_end_of_line.snap
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,5 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_executable/helpers.rs | ||
expression: "ShebangDirective::try_extract(source)" | ||
--- | ||
None |
10 changes: 10 additions & 0 deletions
10
...able/snapshots/ruff__rules__flake8_executable__helpers__tests__shebang_leading_space.snap
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,10 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_executable/helpers.rs | ||
expression: "ShebangDirective::try_extract(source)" | ||
--- | ||
Some( | ||
ShebangDirective { | ||
offset: 4, | ||
contents: "/usr/bin/env python", | ||
}, | ||
) |
10 changes: 10 additions & 0 deletions
10
...8_executable/snapshots/ruff__rules__flake8_executable__helpers__tests__shebang_match.snap
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,10 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_executable/helpers.rs | ||
expression: "ShebangDirective::try_extract(source)" | ||
--- | ||
Some( | ||
ShebangDirective { | ||
offset: 2, | ||
contents: "/usr/bin/env python", | ||
}, | ||
) |
5 changes: 5 additions & 0 deletions
5
...ecutable/snapshots/ruff__rules__flake8_executable__helpers__tests__shebang_non_match.snap
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,5 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_executable/helpers.rs | ||
expression: "ShebangDirective::try_extract(source)" | ||
--- | ||
None |