Skip to content

Commit

Permalink
fix: compare strings without any whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul-alhasany committed Aug 26, 2023
1 parent 81b4e32 commit 64cfc06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "taqwim",
"displayName": "PHPTaqwim",
"description": "PHP linter and formatter",
"version": "0.0.59",
"version": "0.0.60",
"homepage": "https://taqwim.kalimah-apps.com/",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion taqwim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@kalimahapps/taqwim",
"description": "PHP linter and formatter",
"author": "khr2003",
"version": "0.0.59",
"version": "0.0.60",
"homepage": "https://taqwim.kalimah-apps.com/docs/",
"repository": {
"type": "git",
Expand Down
15 changes: 8 additions & 7 deletions taqwim/src/rules/usegroup/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class UsegroupScope {
* @return {string} The string without whitespace
*/
removeWhitespace(string: string): string {
return string.replaceAll(/\n\s*/gmu, '');
return string.replaceAll(/\s/gmu, '');
}

pre() {
Expand Down Expand Up @@ -507,14 +507,15 @@ class UsegroupScope {
// so it can be compared with the new tree string
const { start, end } = this.position;

let currentTreeString = sourceCode.slice(start.offset, end.offset);
currentTreeString = currentTreeString.replaceAll(/\n\s*/gmu, '');
const currentTreeString = sourceCode.slice(start.offset, end.offset);

// currentTreeString = currentTreeString.replaceAll(/\n\s*/gmu, '');
const finalString = finalStringArray.join('\n');

// Compare current tree string with new tree string
// with all new lines and leading spaces removed. If they are the same,
// it means that the tree is already fixed.
if (this.removeWhitespace(finalString) === currentTreeString) {
// Compare current tree string with new tree string with whitespace removed.
// If they are the same, it means that the tree is already fixed or it
// does not need to be fixed
if (this.removeWhitespace(finalString) === this.removeWhitespace(currentTreeString)) {
return;
}

Expand Down

0 comments on commit 64cfc06

Please sign in to comment.