Skip to content

Commit

Permalink
Allow Infinity as line limit (#137)
Browse files Browse the repository at this point in the history
GitHub started reflowing the descriptions of the pull requests, so we
want often to disable the check in the pull requests.
  • Loading branch information
mristin authored May 24, 2024
1 parent f3b9cec commit 8d22319
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
additional-verbs: 'chrusimusi, unit-test'
path-to-additional-verbs: src/additional-verbs.txt
max-body-line-length: 'Infinity'

# test-pr-commits:
# runs-on: ubuntu-latest
Expand All @@ -44,3 +45,4 @@ jobs:
- uses: ./
with:
allow-one-liners: 'true'
max-body-line-length: 'Infinity'
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ You can change the imposed maximum subject length by setting the flag `max-subje
max-subject-line-length: '100'
```

If you want to disable the limit, set it to `Infinity`.

## Custom line length on the body

Similar to the subject line, for terminals and monospaced GUIs it is a good practice to limit the line length of the body to 72 characters.
Expand All @@ -190,6 +192,8 @@ You can change the imposed maximum line length by setting the flag `max-body-lin
max-body-line-length: '100'
```

If you want to disable the limit, set it to `Infinity`.

## Skip Body Check

For some repositories only the subject matters while the body is allowed to be free-form.
Expand Down
23 changes: 21 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29058,6 +29058,25 @@ class MaybeInputs {
}
}
exports.MaybeInputs = MaybeInputs;
const infLiteralSet = new Set([
'inf',
'infty',
'infinity',
'-inf',
'-infty',
'-infinity',
]);
/**
* Parse the `text` as either an integer or `Infinity`.
*
* If the `text` could not be parsed, return a `NaN`.
*/
function parseIntOrInfinity(text) {
if (infLiteralSet.has(text.toLowerCase())) {
return Infinity;
}
return parseInt(text, 10);
}
function parseInputs(rawInputs) {
const { additionalVerbsInput = '', pathToAdditionalVerbsInput = '', allowOneLinersInput = '', maxSubjectLengthInput = '', maxBodyLineLengthInput = '', enforceSignOffInput = '', validatePullRequestCommitsInput = '', skipBodyCheckInput = '', ignoreMergeCommitsInput = '', ignorePatternsInput = '', } = rawInputs;
const additionalVerbs = new Set();
Expand Down Expand Up @@ -29086,14 +29105,14 @@ function parseInputs(rawInputs) {
}
const maxSubjectLength = !maxSubjectLengthInput
? 50
: parseInt(maxSubjectLengthInput, 10);
: parseIntOrInfinity(maxSubjectLengthInput);
if (Number.isNaN(maxSubjectLength)) {
return new MaybeInputs(null, 'Unexpected value for max-subject-line-length. ' +
`Expected a number or nothing, got ${maxSubjectLengthInput}`);
}
const maxBodyLineLength = !maxBodyLineLengthInput
? 72
: parseInt(maxBodyLineLengthInput, 10);
: parseIntOrInfinity(maxBodyLineLengthInput);
if (Number.isNaN(maxBodyLineLength)) {
return new MaybeInputs(null, 'Unexpected value for max-body-line-length. ' +
`Expected a number or nothing, got ${maxBodyLineLengthInput}`);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions src/__tests__/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ it('parses the inputs.', () => {
ignorePatternsInput: `
^Some pattern$
Another pattern
`
`,
});

expect(maybeInputs.error).toBeNull();
Expand All @@ -52,7 +52,7 @@ it('parses the inputs.', () => {
expect(inputs.hasAdditionalVerbsInput).toBeTruthy();
expect(inputs.pathToAdditionalVerbs).toEqual(pathToVerbs);
expect(inputs.additionalVerbs).toEqual(
new Set<string>(['rewrap', 'table', 'integrate', 'analyze'])
new Set<string>(['rewrap', 'table', 'integrate', 'analyze']),
);
expect(inputs.allowOneLiners).toBeTruthy();
expect(inputs.maxSubjectLength).toEqual(90);
Expand All @@ -61,8 +61,18 @@ it('parses the inputs.', () => {
expect(inputs.validatePullRequestCommits).toBeTruthy();
expect(inputs.skipBodyCheck).toBeTruthy();
expect(inputs.ignoreMergeCommits).toBeFalsy();
expect(inputs.ignorePatterns).toEqual([
/^Some pattern$/,
/Another pattern/
]);
expect(inputs.ignorePatterns).toEqual([/^Some pattern$/, /Another pattern/]);
});

it('parses the Infinity limits.', () => {
const maybeInputs = input.parseInputs({
maxSubjectLengthInput: 'Infinity',
maxBodyLineLengthInput: 'Infinity',
});

expect(maybeInputs.error).toBeNull();

const inputs = maybeInputs.mustInputs();
expect(inputs.maxSubjectLength).toEqual(Infinity);
expect(inputs.maxBodyLineLength).toEqual(Infinity);
});
Loading

0 comments on commit 8d22319

Please sign in to comment.