diff --git a/src/index.ts b/src/index.ts index 8d012e5..a05b69a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,14 +5,23 @@ import type { import { checkEndsWithPeriod } from "check-ends-with-period"; const checkEndsWithoutPeriod = (text: string, periodMarks: string[]) => { - const { index, periodMark, valid } = checkEndsWithPeriod(text, { + const { index, periodMark } = checkEndsWithPeriod(text, { periodMarks, }); + const isPeriodMarkAtEnd = periodMarks.indexOf(periodMark) !== -1; + if (isPeriodMarkAtEnd) { + return { + index, + periodMark, + valid: false, + }; + } + return { index, periodMark, - valid: !valid, + valid: true, }; }; @@ -54,10 +63,11 @@ const reporter: TextlintRuleReporter = (context, options = {}) => { } // Prefer to use period - const { index, periodMark, valid } = checkEndsWithPeriod(text, { + const { index, periodMark, valid } = checkEndsWithoutPeriod( + text, periodMarks, - }); - if (valid) { + ); + if (!valid) { if (periodMark === preferPeriodMark) { return; } diff --git a/test/index-test.ts b/test/index-test.ts index ff5669e..8810e8d 100644 --- a/test/index-test.ts +++ b/test/index-test.ts @@ -29,6 +29,9 @@ tester.run("textlint-rule-period-in-header", rule, { periodMark: ".", }, }, + "# text!", + "# text?", + "# text (foobar)", ], invalid: [ {