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

prevent-abbreviations: Improve fix for retVal #1953

Merged
merged 4 commits into from Nov 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions rules/prevent-abbreviations.js
Expand Up @@ -141,6 +141,16 @@ const getNameReplacements = (name, options, limit = 3) => {
samples,
} = cartesianProductSamples(combinations, limit);

// `retVal` -> `['returnValue', 'Value']` -> `['returnValue']`
for (const parts of samples) {
for (let index = parts.length - 1; index > 0; index--) {
const word = parts[index];
if (/^[A-Za-z]+$/.test(word) && parts[index - 1].endsWith(parts[index])) {
parts.splice(index, 1);
}
}
}

return {
total,
samples: samples.map(words => words.join('')),
Expand Down
33 changes: 33 additions & 0 deletions test/prevent-abbreviations.mjs
Expand Up @@ -1261,6 +1261,39 @@ const tests = {
options: noExtendDefaultAllowListOptions,
errors: createErrors(),
},

// #1937
{
code: 'const expectedRetVal = "that should be ok";',
output: 'const expectedReturnValue = "that should be ok";',
errors: createErrors(),
},
{
code: 'const retVal = "that should be ok";',
output: 'const returnValue = "that should be ok";',
errors: createErrors(),
},
{
code: 'const retValue = "that should be ok";',
output: 'const returnValue = "that should be ok";',
errors: createErrors(),
},
{
code: 'const returnVal = "that should be ok";',
output: 'const returnValue = "that should be ok";',
errors: createErrors(),
},
{
code: 'const sendDmMessage = () => {};',
output: 'const sendDirectMessage = () => {};',
options: [{replacements: {dm: {directMessage: true}}}],
errors: createErrors(),
},
{
code: 'const ret_val = "that should be ok";',
output: 'const returnValue_value = "that should be ok";',
errors: createErrors(),
},
],
};

Expand Down