Skip to content

clean sonar: bug fixes#142

Merged
begin-again merged 9 commits intomasterfrom
th/clean-sonar-path-change
Jul 21, 2024
Merged

clean sonar: bug fixes#142
begin-again merged 9 commits intomasterfrom
th/clean-sonar-path-change

Conversation

@begin-again
Copy link
Owner

@begin-again begin-again commented Jul 12, 2024

SonarLinter changed its work file path from to ~/.sonarlint/work to ~/.sonarlint. Also it instroduced new temp folders named xodus-local-only-issue-store123450...

  • added name filters for the folder search
  • changed default root path to ~/.sonarlint
  • replaced statSync with fs/promises stat
  • fixed tests

Summary by CodeRabbit

  • New Features

    • Introduced sonar and yarnArtifacts commands for better configuration management.
    • Added a function to verify and set Git user configuration automatically before tests.
  • Refactor

    • Updated the Git-Tools module to use git.simpleGit for more efficient git operations.
    • Improved folder removal logic in the Cleaner Module for better performance and reliability.
  • Tests

    • Added sequential tests for Git module functions to ensure accurate behavior.
    • Enhanced test cases for the git module with updated assertions and clearer descriptions.
  • Chores

    • Added a new lint:fix script to package.json and updated versions for eslint and mocha.

SonarLinter changed its work file path from to ~/.sonarlint/work to
~/.sonarlint. Also it instroduced new temp folders named
xodus-local-only-issue-store123450...

- added name filters for the folder search
- changed default root path to ~/.sonarlint
- replaced statSync with fs/promises stat
- fixed tests
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

The updates improve file system operations, enhance Git tool interactions, and expand test coverage. Notable enhancements include refactoring folder cleaning logic, adopting git.simpleGit for streamlined git processes, and introducing new configurations and tests. The project now offers better handling of temporary folders, async capabilities for git operations, and comprehensive testing across cleaning functions and Git features.

Changes

File Path Change Summary
src/clean/clean.js Modified imports, updated folder filtering logic, adjusted path handling, and refined temporary folder removal process.
src/clean/index.js Changed default work folder path and introduced new configurations for sonar and yarnArtifacts commands.
src/common/git-tools.js Refactored Git tool functions to use git.simpleGit, added async operations, and improved error handling.
package.json Added lint:fix script and updated eslint and mocha versions.
test/clean.spec.js Renamed keys and updated folder names in mock file system setup for cleaner module tests.
test/git-seq.spec.js Introduced sequential tests for commitsDiff(), commitDiffCounts(), and headLog() functions, ensuring correct behavior in shared repository context.
test/git.spec.js Refactored test suite for the Git module, including renaming test descriptions, updating assertions, and restructuring test cases.

Poem

In files we sweep, a clean command,
Through git’s new hands, async we stand.
With lint to fix and tests anew,
Our code’s refreshed, its strength we knew.
A journey clear, from temp to git,
In every change, our bits commit.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (3)
src/clean/clean.js (3)

77-77: Remove unnecessary blank line.

The blank line before the function definition is unnecessary and can be removed for better readability.

-

Line range hint 47-47:
Use Promise.allSettled instead of Promise.all.

Using Promise.allSettled ensures that all promises are handled, even if some of them reject.

-        return Promise.all(promises)
+        return Promise.allSettled(promises)

Line range hint 32-32:
Add error handling for readdir.

Consider adding error handling for readdir to handle cases where the directory might not be accessible.

-    const folders = await readdir(rootFolder, { withFileTypes: true });
+    const folders = await readdir(rootFolder, { withFileTypes: true }).catch(err => {
+        logger.error(`Error reading directory ${rootFolder}: ${err.message}`);
+        return [];
+    });
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f94a05 and 4bb0840.

Files selected for processing (3)
  • src/clean/clean.js (3 hunks)
  • src/clean/index.js (1 hunks)
  • test/clean.spec.js (3 hunks)
Files skipped from review due to trivial changes (2)
  • src/clean/index.js
  • test/clean.spec.js

const _root = root || join(process.env.HOME, '.sonarlint', 'work');
const _root = root || join(process.env.HOME, '.sonarlint');
const now = Date.now();
const DAY_MS = 86400000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid redeclaring DAY_MS.

DAY_MS is declared twice in the file. Consider moving it to a global constant to avoid redeclaration.

-    const DAY_MS = 86400000;

Committable suggestion was skipped due to low confidence.

Comment on lines 94 to 96
.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
.filter(async d => {
const { ctimeMs } = await stat(join(_root, d.name)).catch(() => 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize folder filtering.

The folder filtering logic can be optimized by combining the filter and map operations to avoid multiple iterations over the same list.

-    const folders = await readdir(_root, { withFileTypes: true })
-        .then(dirs =>
-            dirs
-                .filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
-                .filter(async d => {
-                    const { ctimeMs } = await stat(join(_root, d.name)).catch(() => 0);
-                    const daysOld = Math.floor((now - ctimeMs) / DAY_MS);
-                    return daysOld >= age;
-                })
-        );
+    const folders = (await readdir(_root, { withFileTypes: true }))
+        .filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
+        .map(async d => {
+            const { ctimeMs } = await stat(join(_root, d.name)).catch(() => 0);
+            const daysOld = Math.floor((now - ctimeMs) / DAY_MS);
+            return { name: d.name, daysOld };
+        })
+        .filter(d => d.daysOld >= age);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
.filter(async d => {
const { ctimeMs } = await stat(join(_root, d.name)).catch(() => 0);
.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
.map(async d => {
const { ctimeMs } = await stat(join(_root, d.name)).catch(() => 0);
const daysOld = Math.floor((now - ctimeMs) / DAY_MS);
return { name: d.name, daysOld };
})
.filter(d => d.daysOld >= age);

begin-again and others added 2 commits July 14, 2024 12:22
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
improve readability

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4bb0840 and a021996.

Files selected for processing (1)
  • src/clean/clean.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/clean/clean.js

.map(d => join(rootFolder, d.name));
const folders = await fsPromises.readdir(rootFolder, { withFileTypes: true });
return folders.reduce((acc, dirent) => {
if (dirent.isDirectory() && regex.test(dirent.name)) {

Check failure

Code scanning / ESLint

Enforce consistent spacing before and after keywords

Unexpected space(s) after "if".
Comment on lines 93 to 94
folders = await fsPromises.readdir(_root, { withFileTypes: true })
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI

Missing semicolon.
Comment on lines 94 to 95
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
const foldersToDelete = targetFolders.filter(async d => {

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI

Missing semicolon.
Comment on lines 99 to 100
})

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI

Missing semicolon.
);

return deleteFolders.filter(f => f.status === 'fulfilled').length;

Check failure

Code scanning / ESLint

Disallow trailing whitespace at the end of lines

Trailing spaces not allowed.

return deleteFolders.filter(f => f.status === 'fulfilled').length;

} catch(err){

Check failure

Code scanning / ESLint

Disallow unused variables

'err' is defined but never used.
Comment on lines 109 to 111
} catch(err){

}

Check failure

Code scanning / ESLint

Enforce consistent spacing before blocks

Missing space before opening brace.
Comment on lines 109 to 111
} catch(err){

}

Check failure

Code scanning / ESLint

Disallow empty block statements

Empty block statement.
} catch(err){

}

Check failure

Code scanning / ESLint

Disallow trailing whitespace at the end of lines

Trailing spaces not allowed.
).then(r => {
return r.filter(f => f.status === 'fulfilled').length;
});

Check failure

Code scanning / ESLint

Disallow trailing whitespace at the end of lines

Trailing spaces not allowed.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a021996 and 3620c22.

Files selected for processing (2)
  • src/clean/clean.js (3 hunks)
  • test/clean.spec.js (4 hunks)
Files skipped from review due to trivial changes (1)
  • test/clean.spec.js
Additional context used
GitHub Check: ESLint
src/clean/clean.js

[failure] 37-37: Enforce consistent spacing before and after keywords
Unexpected space(s) after "if".


[failure] 93-94: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 94-95: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 99-100: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 108-108: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 109-109: Enforce consistent brace style for blocks
Closing curly brace appears on the same line as the subsequent block.


[failure] 109-109: Enforce consistent spacing before and after keywords
Expected space(s) after "catch".


[failure] 109-109: Disallow unused variables
'err' is defined but never used.


[failure] 109-111: Enforce consistent spacing before blocks
Missing space before opening brace.


[failure] 109-111: Disallow empty block statements
Empty block statement.


[failure] 112-112: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 115-115: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.

Additional comments not posted (3)
src/clean/clean.js (3)

Line range hint 62-79:
Improve readability of Promise.all block.

Consider breaking down the Promise.all block for better readability.

-        const promises = folders.map(folder => {
-            return remover(join(root, folder), { recursive: true })
-                .catch((out) => {
-                    logger.debug(`ERROR: ${folder} => ${out}`);
-                    return 'skipped';
-                });
-        });
-        return Promise.all(promises)
-            .catch(err => {
-                logger.debug(`problem encountered during delete ${err}`);
-            })
-            .then(() => {
-                logger.info(`${name} cleanup completed`);
-            });
+        const promises = folders.map(folder => remover(join(root, folder), { recursive: true })
+            .catch((out) => {
+                logger.debug(`ERROR: ${folder} => ${out}`);
+                return 'skipped';
+            })
+        );
+        return Promise.all(promises)
+            .catch(err => {
+                logger.debug(`problem encountered during delete ${err}`);
+            })
+            .then(() => {
+                logger.info(`${name} cleanup completed`);
+            });
Tools
GitHub Check: ESLint

[failure] 93-94: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 94-95: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 99-100: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 108-108: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 109-109: Enforce consistent brace style for blocks
Closing curly brace appears on the same line as the subsequent block.


[failure] 109-109: Enforce consistent spacing before and after keywords
Expected space(s) after "catch".


[failure] 109-109: Disallow unused variables
'err' is defined but never used.


[failure] 109-111: Enforce consistent spacing before blocks
Missing space before opening brace.


[failure] 109-111: Disallow empty block statements
Empty block statement.


[failure] 112-112: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 115-115: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


90-90: Avoid redeclaring DAY_MS.

DAY_MS is declared twice in the file. Consider moving it to a global constant to avoid redeclaration.

-    const DAY_MS = 86400000;

Line range hint 118-121:
LGTM!

The module exports are correct.

Tools
GitHub Check: ESLint

[failure] 93-94: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 94-95: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 99-100: Require or disallow semicolons instead of ASI
Missing semicolon.


[failure] 108-108: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 109-109: Enforce consistent brace style for blocks
Closing curly brace appears on the same line as the subsequent block.


[failure] 109-109: Enforce consistent spacing before and after keywords
Expected space(s) after "catch".


[failure] 109-109: Disallow unused variables
'err' is defined but never used.


[failure] 109-111: Enforce consistent spacing before blocks
Missing space before opening brace.


[failure] 109-111: Disallow empty block statements
Empty block statement.


[failure] 112-112: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.


[failure] 115-115: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.

Comment on lines 99 to 100
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing semicolon.

A semicolon is missing at the end of the line.

-            return daysOld >= age;
+            return daysOld >= age;

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: ESLint

[failure] 99-100: Require or disallow semicolons instead of ASI
Missing semicolon.

).then(r => {
return r.filter(f => f.status === 'fulfilled').length;
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace.

Trailing spaces are not allowed.

-    
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Tools
GitHub Check: ESLint

[failure] 115-115: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.

} catch(err){

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace.

Trailing spaces are not allowed.

-    
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Tools
GitHub Check: ESLint

[failure] 112-112: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.

);

return deleteFolders.filter(f => f.status === 'fulfilled').length;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace.

Trailing spaces are not allowed.

-        );
+        );

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: ESLint

[failure] 108-108: Disallow trailing whitespace at the end of lines
Trailing spaces not allowed.

Comment on lines 94 to 95
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
const foldersToDelete = targetFolders.filter(async d => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing semicolon.

A semicolon is missing at the end of the line.

-        const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
+        const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
const foldersToDelete = targetFolders.filter(async d => {
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')));
Tools
GitHub Check: ESLint

[failure] 94-95: Require or disallow semicolons instead of ASI
Missing semicolon.

Comment on lines 93 to 94
folders = await fsPromises.readdir(_root, { withFileTypes: true })
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing semicolon.

A semicolon is missing at the end of the line.

-        folders = await fsPromises.readdir(_root, { withFileTypes: true })
+        folders = await fsPromises.readdir(_root, { withFileTypes: true });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
folders = await fsPromises.readdir(_root, { withFileTypes: true })
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
folders = await fsPromises.readdir(_root, { withFileTypes: true });
const targetFolders = folders.filter(d => d.isDirectory() && (d.name.startsWith('.sonarlinttmp_') || d.name.startsWith('xodus-local-only')))
Tools
GitHub Check: ESLint

[failure] 93-94: Require or disallow semicolons instead of ASI
Missing semicolon.

Comment on lines 109 to 111
} catch(err){

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused variable and fix spacing.

The variable err is defined but never used. Also, fix spacing after catch and remove the empty block.

-    } catch(err){
-    }
+    } catch {
+        logger.debug(`problem encountered during delete`);
+    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch(err){
}
} catch {
logger.debug(`problem encountered during delete`);
}
Tools
GitHub Check: ESLint

[failure] 109-109: Enforce consistent brace style for blocks
Closing curly brace appears on the same line as the subsequent block.


[failure] 109-109: Enforce consistent spacing before and after keywords
Expected space(s) after "catch".


[failure] 109-109: Disallow unused variables
'err' is defined but never used.


[failure] 109-111: Enforce consistent spacing before blocks
Missing space before opening brace.


[failure] 109-111: Disallow empty block statements
Empty block statement.

.map(d => join(rootFolder, d.name));
const folders = await fsPromises.readdir(rootFolder, { withFileTypes: true });
return folders.reduce((acc, dirent) => {
if (dirent.isDirectory() && regex.test(dirent.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spacing after if statement.

There should be no space after the if keyword.

-        if (dirent.isDirectory() && regex.test(dirent.name)) {
+        if(dirent.isDirectory() && regex.test(dirent.name)) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (dirent.isDirectory() && regex.test(dirent.name)) {
if(dirent.isDirectory() && regex.test(dirent.name)) {
Tools
GitHub Check: ESLint

[failure] 37-37: Enforce consistent spacing before and after keywords
Unexpected space(s) after "if".

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3620c22 and fc831b3.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (7)
  • package.json (2 hunks)
  • src/clean/clean.js (3 hunks)
  • src/clean/index.js (1 hunks)
  • src/common/git-tools.js (11 hunks)
  • src/common/git.js (7 hunks)
  • test/git-seq.spec.js (1 hunks)
  • test/git.spec.js (4 hunks)
Files skipped from review due to trivial changes (2)
  • package.json
  • src/common/git.js
Files skipped from review as they are similar to previous changes (2)
  • src/clean/clean.js
  • src/clean/index.js
Additional comments not posted (19)
test/git-seq.spec.js (3)

42-52: LGTM!

The test cases for commitsDiff are well-written and cover the expected scenarios.


54-66: LGTM!

The test cases for commitDiffCounts are well-written and cover the expected scenarios.


68-75: LGTM!

The test case for headLog is well-written and covers the expected scenario.

test/git.spec.js (4)

25-45: LGTM!

The test cases for currentBranch are well-written and cover the expected scenarios.


Line range hint 53-61: LGTM!

The test case for currentHash is well-written and covers the expected scenario.


64-73: LGTM!

The test cases for isDirty are well-written and cover the expected scenarios.


82-90: LGTM!

The test cases for hasCommits are well-written and cover the expected scenarios.

src/common/git-tools.js (12)

21-25: LGTM!

The createRepo function is well-written and correctly uses git.simpleGit for Git operations.


Line range hint 29-41: LGTM!

The copyFolder function is well-written and handles directory and file copying appropriately.


Line range hint 49-53: LGTM!

The duplicateRepo function is well-written and correctly uses the copyFolder function for copying.


75-75: LGTM!

The addRemote function is well-written and correctly uses git.simpleGit for adding a remote.


Line range hint 87-97: LGTM!

The addFileToRepo function is well-written and correctly uses git.simpleGit for Git operations.


107-110: LGTM!

The isDirty function is well-written and correctly uses git.simpleGit for checking the repository status.


121-124: LGTM!

The currentBranch function is well-written and correctly uses git.simpleGit for retrieving the current branch.


137-144: LGTM!

The push function is well-written and correctly uses git.simpleGit for pushing changes.


157-157: LGTM!

The pull function is well-written and correctly uses git.simpleGit for pulling changes.


166-166: LGTM!

The fetchRemotes function is well-written and correctly uses git.simpleGit for fetching remotes.


178-185: LGTM!

The addCommit function is well-written and correctly uses git.simpleGit for creating a commit.


203-212: LGTM!

The addCommitWithMessage function is well-written and correctly uses git.simpleGit for creating a commit with a message.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc831b3 and 14a4508.

Files selected for processing (1)
  • test/git.spec.js (4 hunks)
Additional comments not posted (2)
test/git.spec.js (2)

49-52: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that the checkGitConfig function is used correctly in the codebase.

Verification successful

Function usage verified.

The checkGitConfig function is correctly used within the before hook of the test suite in the test/git.spec.js file.

  • test/git.spec.js, lines 49-52
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `checkGitConfig` function in the codebase.

# Test: Search for the function usage. Expect: Usage in the `before` hook of the test suite.
rg --type js -A 5 $'checkGitConfig'

Length of output: 677


22-23: Verify the usage of git.raw for checking Git configuration.

Ensure that the git.raw method is appropriate for checking the Git user configuration. Consider using specific methods provided by the simple-git library if available.

Verification successful

Verify if simple-git provides specific methods for checking and setting Git configuration.

Ensure that the simple-git library does not have specific methods for checking and setting Git user configuration, which might be more suitable than using git.raw.


Verify if simple-git provides specific methods for checking and setting Git configuration.

Ensure that the simple-git library does not have specific methods for checking and setting Git user configuration, which might be more suitable than using git.raw.


Verified: The usage of git.raw for checking and setting Git configuration is appropriate.

  • The simple-git library does not provide specific methods for these operations, making the usage of git.raw suitable.
  • Consider improving error handling in the checkGitConfig function to provide more detailed error information.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `git.raw` method for checking Git configuration.

# Test: Search for the usage of `git.raw` method. Expect: Usage in `checkGitConfig` function.
rg --type js -A 5 $'git.raw'

Length of output: 862


Script:

#!/bin/bash
# Description: Check if `simple-git` library provides specific methods for checking and setting Git configuration.

# Test: Search for methods in `simple-git` library related to Git configuration.
rg --type js 'simple-git'

Length of output: 208


Script:

#!/bin/bash
# Description: Check if `simple-git` library provides specific methods for checking and setting Git configuration.

# Test: Search for methods in `simple-git` library related to Git configuration.
rg --type js 'config' -A 5

Length of output: 2511

Comment on lines +39 to +42
catch {
// handle error
console.error('Failed to check git config');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling.

The current error handling only logs an error message. Consider adding more detailed error handling or rethrowing the error to ensure any issues are properly addressed.

-  console.error('Failed to check git config');
+  console.error('Failed to check git config', err);
+  throw err;

Committable suggestion was skipped due to low confidence.

@begin-again begin-again merged commit f7fabe9 into master Jul 21, 2024
@begin-again begin-again deleted the th/clean-sonar-path-change branch July 21, 2024 21:45
@begin-again begin-again restored the th/clean-sonar-path-change branch July 21, 2024 21:45
@coderabbitai coderabbitai bot mentioned this pull request Oct 5, 2024
@begin-again begin-again deleted the th/clean-sonar-path-change branch October 15, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant