Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform agnostic line endings #6530

Merged
merged 1 commit into from
Sep 7, 2023

Conversation

DecimalTurn
Copy link
Contributor

@DecimalTurn DecimalTurn commented Aug 30, 2023

Description

This PR should make all remaining regex patterns follow our new approach of using platform-agnostic line endings as discussed here: #6417 (comment)

Here are the replacements made:

  1. Standalone1 \r?\n with (?:\r?\n|\r)
  2. Standalone1 \n with (?:\r?\n|\r)
  3. (\s|\n) with [\s\r\n]
  4. [^\n] with [^\r\n]

I also replaced (^|\n) with just ^ since matching with the previous line ending or not doesn't affect the outcome.

(Checklist removed as it doesn't apply).

Footnotes

  1. In the sense that they are not part of a character set. 2

@DecimalTurn DecimalTurn requested a review from a team as a code owner August 30, 2023 01:51
@DecimalTurn DecimalTurn changed the title Plateform agnostic line endings Platform agnostic line endings Aug 30, 2023
@lildude lildude requested a review from Alhadis August 31, 2023 07:28
@lildude lildude added this pull request to the merge queue Sep 7, 2023
Merged via the queue into github-linguist:master with commit ee12e6c Sep 7, 2023
@Alhadis
Copy link
Collaborator

Alhadis commented Sep 7, 2023

Shit, sorry I missed your review request, @lildude. 😞 Been having trouble getting myself in front of a workstation lately.

  1. (\s|\n) with [\s\r\n]

I'm not sure why or where (\s|\n) was used in the first place, but this should've simply been \s; that construct is equivalent to [ \t\r\n\f\v] in Ruby. Ergo, it should've been simplified to just \s.

@lildude
Copy link
Member

lildude commented Sep 7, 2023

Ooo, I've just noticed this PR introduced a regex warning in the test output:

/home/runner/work/linguist/linguist/lib/linguist/heuristics.rb:91: warning: character class has duplicated range: /^[=-]+[\s\r\n]|\{\{[A-Za-z]/

This is for the AsciiDoc regex.

If you've got a mo @DecimalTurn could you please address this.

@Alhadis
Copy link
Collaborator

Alhadis commented Sep 7, 2023

@lildude The /^[=-]+[\s\r\n] part of the offending expression is an example of the redundancy I mentioned above.

To fix:

-/^[=-]+[\s\r\n]|\{\{[A-Za-z]/
+/^[=-]+\s|\{\{[A-Za-z]/

@DecimalTurn
Copy link
Contributor Author

@Alhadis Thanks, for the catch.

@lildude Should I create a new PR for this fix?

@lildude
Copy link
Member

lildude commented Sep 7, 2023

@DecimalTurn yes please. 🙇

@DecimalTurn
Copy link
Contributor Author

Done.

@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants