Skip to content

Commit

Permalink
Merge pull request #105 from Expensify/cm-update-period-rule
Browse files Browse the repository at this point in the history
Enforce period only if more than one sentence
  • Loading branch information
MonilBhavsar authored Jul 31, 2024
2 parents 92a1f5f + 634cb5b commit f1345a5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
31 changes: 26 additions & 5 deletions eslint-plugin-expensify/tests/use-periods-error-messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,48 @@ const ruleTester = new RuleTester({
},
});

const goodExample = `
const goodExampleSingleSentence = `
error: {
testMessage: 'This is a test message'
}
`;

const goodExampleMultipleSentences = `
error: {
testMessage: 'This is a test message. Last period is mandatory.'
}
`;

const badExampleSingleSentence = `
error: {
testMessage: 'This is a test message.'
}
`;

const badExample = `
const badExampleMultipleSentences = `
error: {
testMessage: 'This is a test message'
testMessage: 'This is a test message. Last period is mandatory'
}
`;

ruleTester.run('use-periods-for-error-messages', rule, {
valid: [
{
code: goodExample,
code: goodExampleSingleSentence,
},
{
code: goodExampleMultipleSentences,
},
],
invalid: [
{
code: badExample,
code: badExampleSingleSentence,
errors: [{
message,
}],
},
{
code: badExampleMultipleSentences,
errors: [{
message,
}],
Expand Down
6 changes: 5 additions & 1 deletion eslint-plugin-expensify/use-periods-for-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = {
return;
}
const errorMessage = property.value.value;
if (!errorMessage.endsWith('.')) {

// Only enforce period rule if more than one sentence
const sentenceCount = errorMessage.split('.').filter(sentence => sentence.trim().length > 0).length;

if (sentenceCount > 1 && !errorMessage.endsWith('.')) {
context.report({
node: property,
message,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-expensify",
"version": "2.0.52",
"version": "2.0.53",
"description": "Expensify's ESLint configuration following our style guide",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit f1345a5

Please sign in to comment.