Skip to content

Commit

Permalink
exclude kasheedas that are in the beginning or at the end of a word
Browse files Browse the repository at this point in the history
  • Loading branch information
aborazmeh committed Jul 7, 2024
1 parent 873587f commit 38b5c2b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ textlint --rule no-kasheeda --fix README.md
> يـولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق
Kasheedas usage is acceptable when it's not surrounded by letters on each sides:

> العام السابق 1445 هـ، والعام الحالي 1446 هـ
> خَرَجتَ من المُنى مثلَ الـ * * * ـحُمَيِّرِ غَرَّهُ وَتِدُه
> وعندما جاء إلى الـ«بيت» دخل الـ"غرفة" ولم يجد أحداً

## Install

Install with [npm](https://www.npmjs.com/):
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.4",
"version": "1.0.5",
"keywords": [
"textlintrule"
],
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ const report: TextlintRuleModule = (context) => {
[Syntax.Str](node) { // "Str" node
const text = getSource(node); // Get text
const matches = text.matchAll(/ـ+/g);
const notLetter = (index: number) => /[^\p{Letter}]/u.test(text[index])

for (const match of matches) {
const index = match.index ?? 0;
const matchRange = [index, index + match[0].length] as const;
if (
index === 0 ||
index + match[0].length === text.length ||
notLetter(index - 1) ||
notLetter(index + match[0].length)
) {
return
}
const remove = fixer.removeRange(matchRange);

const ruleError = new RuleError("Found kasheeda.", {
Expand Down
8 changes: 7 additions & 1 deletion test/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ const tester = new TextLintTester();
// ruleName, rule, { valid, invalid }
tester.run("rule", rule, {
valid: [
"يولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق"
"يولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق",
"العام الحالي 1446 هـ وبعد ذلك عام جديد",
"العام السابق 1445 هـ، والعام الحالي 1446 هـ",
"خَرَجتَ من المُنى مثلَ الـ ـحُمَيِّرِ غَرَّهُ وَتِدُه",
`وعندما جاء إلى الـ«بيت» دخل الـ"غرفة" ولم يجد أحداً`,
],
invalid: [
{
text: "يـولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق",
output: "يولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق",
errors: [
{
message: "Found kasheeda.",
Expand All @@ -19,6 +24,7 @@ tester.run("rule", rule, {
},
{
text: `يـولد جميع الناس أحراراً ومتـــســـاوين في الكرامة والحقوق`,
output: "يولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق",
errors: [
{
message: "Found kasheeda.",
Expand Down

0 comments on commit 38b5c2b

Please sign in to comment.