Skip to content

Commit 4cf0c66

Browse files
authored
Check for CRLF line endings in CI (#1348)
## The problem We currently don't have any checks to ensure that we don't use CRLF line endings, which could result in hard-to-detect issues in our files, as the difference between LF and CRLF isn't always visible ## The solution In this PR, we now check that all files that are not binary do not contain CRLF line endings. This PR does the following: - Adds a `pre-commit` rule to ensure that files that text files don't have CRLF - Fixes all files in our repo that had CRLF line endings; looks like we had only missed one file - Removes an old Rope database file that was floating around in our repo for some reason. Seemed better to remove it than add a rule for it to our new `.gitattributes` - Throws an exception in test case recorder when developer tries to record a test with line endings as CRLF ## References - https://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/ - https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings - https://git-scm.com/docs/gitattributes ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet - [x] Make sure we're checking line endings for files in CI
1 parent 4b1e0ce commit 4cf0c66

File tree

5 files changed

+14
-126
lines changed

5 files changed

+14
-126
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ repos:
1414
entry: Forbid symlinks
1515
language: fail
1616
types: [symlink]
17+
- repo: https://github.com/Lucas-C/pre-commit-hooks
18+
rev: v1.5.1
19+
hooks:
20+
- id: forbid-crlf
1721
- repo: https://github.com/pre-commit/pre-commit-hooks
1822
rev: v4.4.0
1923
hooks:

cursorless-talon/.vscode/.ropeproject/config.py

Lines changed: 0 additions & 123 deletions
This file was deleted.
-6 Bytes
Binary file not shown.

data/playground/xml.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<root>
2-
<name id="some id">Some text</name>
3-
</root>
1+
<root>
2+
<name id="some id">Some text</name>
3+
</root>

packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ export class TestCaseRecorder {
323323
await this.testCase.recordInitialState();
324324

325325
const editor = ide().activeTextEditor!;
326+
327+
if (editor.document.getText().includes("\r\n")) {
328+
throw Error(
329+
"Refusing to record a test when the document contains CRLF line endings. Please convert line endings to LF.",
330+
);
331+
}
332+
326333
// NB: We need to copy the editor options rather than storing a reference
327334
// because its properties are lazy
328335
this.originalTextEditorOptions = { ...editor.options };

0 commit comments

Comments
 (0)