Skip to content

Commit

Permalink
add prettier and apply it
Browse files Browse the repository at this point in the history
  • Loading branch information
aborazmeh committed Jul 11, 2024
1 parent 38b5c2b commit 03a8506
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

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

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
"test": "textlint-scripts test",
"build": "textlint-scripts build",
"prepublish": "npm run --if-present build",
"watch": "textlint-scripts build --watch"
"watch": "textlint-scripts build --watch",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
},
"prettier": {
"singleQuote": false,
"printWidth": 120,
"tabWidth": 4,
"trailingComma": "es5"
},
"devDependencies": {
"@textlint/types": "^14.0.4",
"@types/node": "^20.14.9",
"prettier": "^3.3.2",
"textlint-scripts": "^14.0.4",
"textlint-tester": "^14.0.4",
"ts-node": "^10.9.2",
Expand Down
21 changes: 11 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import type { TextlintRuleModule } from "@textlint/types";
const report: TextlintRuleModule = (context) => {
const { Syntax, RuleError, fixer, report, getSource, locator } = context;
return {
[Syntax.Str](node) { // "Str" node
[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])
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)
index === 0 ||
index + match[0].length === text.length ||
notLetter(index - 1) ||
notLetter(index + match[0].length)
) {
return
return;
}
const remove = fixer.removeRange(matchRange);

Expand All @@ -27,11 +28,11 @@ const report: TextlintRuleModule = (context) => {
});
report(node, ruleError);
}
}
}
},
};
};

export default {
linter: report,
fixer: report
fixer: report,
};
19 changes: 9 additions & 10 deletions test/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ tester.run("rule", rule, {
errors: [
{
message: "Found kasheeda.",
range: [1, 2]
}
]
range: [1, 2],
},
],
},
{
text: `يـولد جميع الناس أحراراً ومتـــســـاوين في الكرامة والحقوق`,
output: "يولد جميع الناس أحراراً ومتساوين في الكرامة والحقوق",
errors: [
{
message: "Found kasheeda.",
range: [1, 2]
range: [1, 2],
},
{
message: "Found kasheeda.",
range: [28, 31]
range: [28, 31],
},
{
message: "Found kasheeda.",
range: [32, 35]
}
]
range: [32, 35],
},
],
},

]
],
});

0 comments on commit 03a8506

Please sign in to comment.