dslop 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.3.0
4
+
5
+
6
+ ### 🚀 Enhancements
7
+
8
+ - Include committed branch changes in default scan ([468c514](https://github.com/turf-sports/dslop/commit/468c514))
9
+
10
+ ### ❤️ Contributors
11
+
12
+ - Siddharth Sharma <sharmasiddharthcs@gmail.com>
13
+
3
14
  ## v1.2.0
4
15
 
5
16
  [compare changes](https://github.com/turf-sports/dslop/compare/v1.1.0...v1.2.0)
package/README.md CHANGED
@@ -6,7 +6,7 @@ Find duplicate code in your codebase.
6
6
  npx dslop
7
7
  ```
8
8
 
9
- By default, checks your uncommitted changes against the codebase.
9
+ By default, checks your branch changes (committed + uncommitted) against the codebase.
10
10
 
11
11
  ## Install
12
12
 
@@ -17,7 +17,7 @@ npm i -g dslop
17
17
  ## Usage
18
18
 
19
19
  ```bash
20
- dslop # check uncommitted changes for dupes
20
+ dslop # check your PR/branch for dupes
21
21
  dslop --all # scan entire codebase
22
22
  dslop ./src -m 6 -s 80 # 6 line min, 80% similarity
23
23
  dslop --all --cross-package # cross-package dupes (monorepos)
package/dist/index.js CHANGED
@@ -6561,22 +6561,32 @@ async function scanDirectory(targetPath, options) {
6561
6561
  }
6562
6562
 
6563
6563
  // index.ts
6564
- var VERSION = process.env.npm_package_version || "1.2.0";
6564
+ var VERSION = process.env.npm_package_version || "1.3.0";
6565
6565
  function getChangedFiles(targetPath) {
6566
6566
  const absolutePath = path4.resolve(targetPath);
6567
- try {
6568
- const staged = execSync("git diff --cached --name-only", { cwd: absolutePath, encoding: "utf-8" });
6569
- const unstaged = execSync("git diff --name-only", { cwd: absolutePath, encoding: "utf-8" });
6570
- const untracked = execSync("git ls-files --others --exclude-standard", { cwd: absolutePath, encoding: "utf-8" });
6571
- const files = new Set;
6572
- for (const file of [...staged.split(`
6573
- `), ...unstaged.split(`
6574
- `), ...untracked.split(`
6575
- `)]) {
6567
+ const files = new Set;
6568
+ const addFiles = (output) => {
6569
+ for (const file of output.split(`
6570
+ `)) {
6576
6571
  if (file.trim()) {
6577
6572
  files.add(path4.resolve(absolutePath, file.trim()));
6578
6573
  }
6579
6574
  }
6575
+ };
6576
+ try {
6577
+ addFiles(execSync("git diff --cached --name-only", { cwd: absolutePath, encoding: "utf-8" }));
6578
+ addFiles(execSync("git diff --name-only", { cwd: absolutePath, encoding: "utf-8" }));
6579
+ addFiles(execSync("git ls-files --others --exclude-standard", { cwd: absolutePath, encoding: "utf-8" }));
6580
+ try {
6581
+ const baseBranch = execSync("git rev-parse --abbrev-ref origin/HEAD 2>/dev/null || echo origin/main", { cwd: absolutePath, encoding: "utf-8" }).trim().replace("origin/", "");
6582
+ const currentBranch = execSync("git rev-parse --abbrev-ref HEAD", { cwd: absolutePath, encoding: "utf-8" }).trim();
6583
+ if (currentBranch !== baseBranch) {
6584
+ const mergeBase = execSync(`git merge-base ${baseBranch} HEAD 2>/dev/null || echo ""`, { cwd: absolutePath, encoding: "utf-8" }).trim();
6585
+ if (mergeBase) {
6586
+ addFiles(execSync(`git diff --name-only ${mergeBase}...HEAD`, { cwd: absolutePath, encoding: "utf-8" }));
6587
+ }
6588
+ }
6589
+ } catch {}
6580
6590
  return files;
6581
6591
  } catch {
6582
6592
  return new Set;
@@ -6589,7 +6599,7 @@ dslop - Detect Similar/Duplicate Lines Of Programming
6589
6599
  Usage:
6590
6600
  dslop [path] [options]
6591
6601
 
6592
- By default, checks uncommitted changes against the codebase.
6602
+ By default, checks your branch changes (committed + uncommitted) against the codebase.
6593
6603
 
6594
6604
  Arguments:
6595
6605
  path Directory to scan (default: current directory)
@@ -6607,7 +6617,7 @@ Options:
6607
6617
  -v, --version Show version
6608
6618
 
6609
6619
  Examples:
6610
- dslop Check uncommitted changes for duplicates
6620
+ dslop Check your PR/branch changes for duplicates
6611
6621
  dslop --all Scan entire codebase
6612
6622
  dslop ./src -m 6 -s 80 Scan src with 6 line min, 80% similarity
6613
6623
  dslop --all --cross-package Cross-package duplicates in entire codebase
@@ -6668,13 +6678,13 @@ async function main() {
6668
6678
  const changedFiles = !scanAll ? getChangedFiles(targetPath) : null;
6669
6679
  if (!scanAll && changedFiles?.size === 0) {
6670
6680
  console.log(`
6671
- No uncommitted changes found. Use --all to scan entire codebase.`);
6681
+ No changes found. Use --all to scan entire codebase.`);
6672
6682
  process.exit(0);
6673
6683
  }
6674
6684
  console.log(`
6675
6685
  Scanning ${targetPath}...`);
6676
6686
  if (!scanAll) {
6677
- console.log(` Mode: checking ${changedFiles.size} uncommitted files`);
6687
+ console.log(` Mode: checking ${changedFiles.size} changed files`);
6678
6688
  } else {
6679
6689
  console.log(` Mode: full codebase scan`);
6680
6690
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dslop",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Detect Similar/Duplicate Lines Of Programming - Find code duplication in your codebase",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",