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

Allow Infinity as line limit #137

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading