diff --git a/eslint-plugin-expensify/tests/use-periods-error-messages.test.js b/eslint-plugin-expensify/tests/use-periods-error-messages.test.js index c0c3c4b..b622105 100644 --- a/eslint-plugin-expensify/tests/use-periods-error-messages.test.js +++ b/eslint-plugin-expensify/tests/use-periods-error-messages.test.js @@ -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, }], diff --git a/eslint-plugin-expensify/use-periods-for-error-messages.js b/eslint-plugin-expensify/use-periods-for-error-messages.js index bec9b78..1c34878 100644 --- a/eslint-plugin-expensify/use-periods-for-error-messages.js +++ b/eslint-plugin-expensify/use-periods-for-error-messages.js @@ -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, diff --git a/package.json b/package.json index 1e1a744..4878940 100644 --- a/package.json +++ b/package.json @@ -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": {