Skip to content

Commit

Permalink
add rule: no middle Tanween
Browse files Browse the repository at this point in the history
  • Loading branch information
aborazmeh committed Jul 9, 2024
1 parent 9a1a294 commit afe4180
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Shadda can't be combined with Sukun

ضيّْق

### No Middle Tanween

لا يمكن للتنوين أن يأتي في وسًٍط وسٍط وسٌط الكلمة

## Usage

Via `.textlintrc.json`(Recommended)
Expand Down Expand Up @@ -90,7 +94,6 @@ Test textlint rule by [textlint-tester](https://github.com/textlint/textlint-tes

- Normalize diacritics forms before some regexes like for duplicated diacritics
- No diacritics or Tanween on Alef without Hamza except Tanween Al-Nasb
- No middle Tanween
- No consecutive five Harakat
- No consecutive three Sokoon
- Twneen on Alef or the letter before
Expand Down
22 changes: 22 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export interface Options {
no_shadda_with_madda?: boolean;
no_shadda_with_sukun?: boolean;
no_duplicated_diacritics?: boolean;
no_middle_tanween?: boolean
}

const regex = {
diacritics: "[\u064B-\u0653]",
tanween: "[\u064B-\u064D]",
shadda: "[\u0651\u0AFB\uFC5E-\uFC63\uFCF2-\uFCF4\uFE7C\uFE7D\u11237]",
madda: "\u0653",
alefMadda: "[\u0622\uFE81\uFE82\uFEF5\uFEF6]",
Expand Down Expand Up @@ -100,6 +102,21 @@ function noDuplicatedDiacritics(node: TxtStrNode, text: string, context: Readonl
}
}

function noMiddleTanween(node: TxtStrNode, text: string, context: Readonly<TextlintRuleContext>) {
const { report, locator, RuleError } = context;

// FIXME dont't report if the next character is Alef and it's the last letter of the word
const matches = text.matchAll(new RegExp(`(${regex.tanween})(?=[^\\s]*\\p{Letter})`, "ug"));
for (const match of matches) {
const index = match.index ?? 0;
const matchRange = [index, index + match[0].length] as const;
const ruleError = new RuleError("Found middle Tanween.", {
padding: locator.range(matchRange)
});
report(node, ruleError);
}
}

const report: TextlintRuleModule<Options> = (context, options = {}) => {
const { getSource, Syntax } = context;
return {
Expand All @@ -108,6 +125,7 @@ const report: TextlintRuleModule<Options> = (context, options = {}) => {
const shaddaWithMaddaOpt = options.no_shadda_with_madda ?? true;
const shaddaWithSukunOpt = options.no_shadda_with_sukun ?? true;
const duplicatedDiacriticsOpt = options.no_duplicated_diacritics ?? true;
const noMiddleTanweenOpt = options.no_middle_tanween ?? true;

const text = getSource(node); // Get text
noLooseDiacritics(node, text, context, removeLooseDiacritics);
Expand All @@ -123,6 +141,10 @@ const report: TextlintRuleModule<Options> = (context, options = {}) => {
if (duplicatedDiacriticsOpt) {
noDuplicatedDiacritics(node, text, context);
}

if (noMiddleTanweenOpt) {
noMiddleTanween(node, text, context);
}
}
};
};
Expand Down
22 changes: 22 additions & 0 deletions test/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tester.run("rule", rule, {
"الآن",
"ضيّق",
"يونَُِس: قال أبو عبيدة، «يقال:يونس بضم النون وكسرها». والمشهور في القراءة يونُس برفع النون من غير همز.",
"من علامات الاسم: التنوين آخر الاسم المنصرف؛ السماء صافيةٌ، رأيت عامراً، مررت بدكانٍ",
{
text: "ضيّْق",
options: {
Expand Down Expand Up @@ -113,6 +114,27 @@ tester.run("rule", rule, {
range: [9, 12]
}
]
},
{
text: "لا يمكن للتنوين أن يأتي في وسًٍط وسٍط وسٌط الكلمة",
errors: [
{
message: "Found middle Tanween.",
range: [29, 30]
},
{
message: "Found middle Tanween.",
range: [30, 31]
},
{
message: "Found middle Tanween.",
range: [35, 36]
},
{
message: "Found middle Tanween.",
range: [40, 41]
}
]
}
]
});

0 comments on commit afe4180

Please sign in to comment.