Skip to content

Commit

Permalink
support case-insensitive-param-case (#2738)
Browse files Browse the repository at this point in the history
  • Loading branch information
niclim authored Feb 15, 2024
1 parent c7e89bf commit 178b76e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2068,4 +2068,4 @@ exports[`naming changes configuration naming change configuration validation 2`]

exports[`naming changes configuration naming change configuration validation 3`] = `"Expected config.applies in NamingChangesRuleset to be specified and be one of added, addedOrChanged, always"`;

exports[`naming changes configuration naming change configuration validation 4`] = `"Expected casing option to be one of snake_case, camelCase, Capital-Param-Case, param-case, PascalCase, received not a valid format for queryParameters"`;
exports[`naming changes configuration naming change configuration validation 4`] = `"Expected casing option to be one of snake_case, camelCase, Capital-Param-Case, param-case, PascalCase, case-insensitive-param-case, received not a valid format for queryParameters"`;
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,29 @@ describe('isCase', () => {
expect(isCase(failingCase, 'PascalCase')).toBe(false);
}
});

test('case-insensitive-param-case', () => {
const passingCases = [
'kebab-case-For-fun',
'snake',
'kebabwithoutfriends',
'param1-Wwit2h-num3bers',
'1param-2with-Leading-number',
];
const failingCases = [
'',
'some-kebab-someCamel',
'some-AeAab-someCamel',
'camelCase',
'snake_case_for_fun',
];
for (const passingCase of passingCases) {
console.log(passingCase);
expect(isCase(passingCase, 'case-insensitive-param-case')).toBe(true);
}

for (const failingCase of failingCases) {
expect(isCase(failingCase, 'case-insensitive-param-case')).toBe(false);
}
});
});
1 change: 1 addition & 0 deletions projects/standard-rulesets/src/naming-changes/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const casing = [
'Capital-Param-Case',
'param-case',
'PascalCase',
'case-insensitive-param-case',
] as const;

export const appliesWhen = ['added', 'addedOrChanged', 'always'] as const;
Expand Down
2 changes: 2 additions & 0 deletions projects/standard-rulesets/src/naming-changes/isCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function regexForRule(format: (typeof casing)[number]) {
return /^[A-Z][a-z0-9]+(?:[A-Z0-9][a-z0-9]+)*$/;
case 'snake_case':
return /^[a-z0-9]+(?:_[a-z0-9]+)*$/;
case 'case-insensitive-param-case':
return /^[a-zA-Z0-9][a-z0-9]*(-[a-zA-Z0-9][a-z0-9]*)*$/;
default:
return /(.*?)/;
}
Expand Down

0 comments on commit 178b76e

Please sign in to comment.