Skip to content

Commit

Permalink
prevent-abbreviations: Improve fix for retVal (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 8, 2022
1 parent f2f376a commit 25cd810
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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

0 comments on commit 25cd810

Please sign in to comment.