dslop 1.1.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,28 @@
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
+
14
+ ## v1.2.0
15
+
16
+ [compare changes](https://github.com/turf-sports/dslop/compare/v1.1.0...v1.2.0)
17
+
18
+ ### 🚀 Enhancements
19
+
20
+ - Default to checking uncommitted changes, add --all flag ([0492bba](https://github.com/turf-sports/dslop/commit/0492bba))
21
+
22
+ ### ❤️ Contributors
23
+
24
+ - Siddharth Sharma <sharmasiddharthcs@gmail.com>
25
+
3
26
  ## v1.1.0
4
27
 
5
28
  [compare changes](https://github.com/turf-sports/dslop/compare/v1.0.7...v1.1.0)
package/README.md CHANGED
@@ -3,9 +3,11 @@
3
3
  Find duplicate code in your codebase.
4
4
 
5
5
  ```bash
6
- npx dslop .
6
+ npx dslop
7
7
  ```
8
8
 
9
+ By default, checks your branch changes (committed + uncommitted) against the codebase.
10
+
9
11
  ## Install
10
12
 
11
13
  ```bash
@@ -15,23 +17,22 @@ npm i -g dslop
15
17
  ## Usage
16
18
 
17
19
  ```bash
18
- dslop . # scan current directory
19
- dslop --staged # check uncommitted changes for dupes
20
+ dslop # check your PR/branch for dupes
21
+ dslop --all # scan entire codebase
20
22
  dslop ./src -m 6 -s 80 # 6 line min, 80% similarity
21
- dslop . --cross-package # only cross-package dupes (monorepos)
22
- dslop . --json # json output
23
+ dslop --all --cross-package # cross-package dupes (monorepos)
23
24
  ```
24
25
 
25
26
  ## Options
26
27
 
27
- | Flag | Default | Description |
28
- |------|---------|-------------|
29
- | `-m, --min-lines` | 4 | min lines per block |
30
- | `-s, --similarity` | 70 | similarity threshold (0-100) |
31
- | `-e, --extensions` | ts,tsx,js,jsx | file extensions |
32
- | `--staged` | | only show dupes involving uncommitted changes |
33
- | `--cross-package` | | only show dupes across packages |
34
- | `--json` | | json output |
28
+ | Flag | Description |
29
+ |------|-------------|
30
+ | `-a, --all` | scan entire codebase (default: uncommitted only) |
31
+ | `-m, --min-lines` | min lines per block (default: 4) |
32
+ | `-s, --similarity` | similarity threshold 0-100 (default: 70) |
33
+ | `-e, --extensions` | file extensions (default: ts,tsx,js,jsx) |
34
+ | `--cross-package` | only show dupes across packages |
35
+ | `--json` | json output |
35
36
 
36
37
  ## License
37
38
 
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.1.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,15 +6599,17 @@ dslop - Detect Similar/Duplicate Lines Of Programming
6589
6599
  Usage:
6590
6600
  dslop [path] [options]
6591
6601
 
6602
+ By default, checks your branch changes (committed + uncommitted) against the codebase.
6603
+
6592
6604
  Arguments:
6593
6605
  path Directory to scan (default: current directory)
6594
6606
 
6595
6607
  Options:
6608
+ -a, --all Scan entire codebase (not just uncommitted changes)
6596
6609
  -m, --min-lines <n> Minimum block size in lines (default: ${DEFAULT_MIN_LINES})
6597
6610
  -s, --similarity <n> Minimum similarity threshold 0-100 (default: ${Math.round(DEFAULT_SIMILARITY * 100)})
6598
6611
  -e, --extensions <s> File extensions to scan (default: ${DEFAULT_EXTENSIONS.join(",")})
6599
6612
  -i, --ignore <s> Patterns to ignore (default: ${DEFAULT_IGNORE_PATTERNS.slice(0, 4).join(",")},...)
6600
- --staged Only show duplicates involving uncommitted changes
6601
6613
  --no-normalize Disable string/number normalization
6602
6614
  --cross-package Only show duplicates across different packages/apps (monorepo mode)
6603
6615
  --json Output as JSON
@@ -6605,10 +6617,10 @@ Options:
6605
6617
  -v, --version Show version
6606
6618
 
6607
6619
  Examples:
6608
- dslop . Scan current directory
6609
- dslop --staged Check uncommitted changes for duplicates
6620
+ dslop Check your PR/branch changes for duplicates
6621
+ dslop --all Scan entire codebase
6610
6622
  dslop ./src -m 6 -s 80 Scan src with 6 line min, 80% similarity
6611
- dslop . --cross-package Only duplicates across packages (great for monorepos)
6623
+ dslop --all --cross-package Cross-package duplicates in entire codebase
6612
6624
  `);
6613
6625
  }
6614
6626
  function showVersion() {
@@ -6624,7 +6636,7 @@ async function main() {
6624
6636
  ignore: { type: "string", short: "i", default: DEFAULT_IGNORE_PATTERNS.join(",") },
6625
6637
  normalize: { type: "boolean", default: true },
6626
6638
  "no-normalize": { type: "boolean", default: false },
6627
- staged: { type: "boolean", default: false },
6639
+ all: { type: "boolean", short: "a", default: false },
6628
6640
  "cross-package": { type: "boolean", default: false },
6629
6641
  json: { type: "boolean", default: false },
6630
6642
  help: { type: "boolean", short: "h", default: false },
@@ -6646,7 +6658,7 @@ async function main() {
6646
6658
  const extensions = values.extensions.split(",").map((e) => e.trim());
6647
6659
  const ignorePatterns = values.ignore.split(",").map((p) => p.trim());
6648
6660
  const normalize2 = !values["no-normalize"];
6649
- const staged = values.staged;
6661
+ const scanAll = values.all;
6650
6662
  const crossPackage = values["cross-package"];
6651
6663
  const jsonOutput = values.json;
6652
6664
  if (minLines < 2) {
@@ -6663,23 +6675,24 @@ async function main() {
6663
6675
  minLines,
6664
6676
  normalize: normalize2
6665
6677
  };
6666
- const changedFiles = staged ? getChangedFiles(targetPath) : null;
6667
- if (staged && changedFiles?.size === 0) {
6678
+ const changedFiles = !scanAll ? getChangedFiles(targetPath) : null;
6679
+ if (!scanAll && changedFiles?.size === 0) {
6668
6680
  console.log(`
6669
- No uncommitted changes found.`);
6681
+ No changes found. Use --all to scan entire codebase.`);
6670
6682
  process.exit(0);
6671
6683
  }
6672
6684
  console.log(`
6673
6685
  Scanning ${targetPath}...`);
6686
+ if (!scanAll) {
6687
+ console.log(` Mode: checking ${changedFiles.size} changed files`);
6688
+ } else {
6689
+ console.log(` Mode: full codebase scan`);
6690
+ }
6674
6691
  console.log(` Extensions: ${extensions.join(", ")}`);
6675
6692
  console.log(` Min block size: ${minLines} lines`);
6676
6693
  console.log(` Similarity threshold: ${Math.round(similarity * 100)}%`);
6677
- console.log(` Normalization: ${normalize2 ? "enabled" : "disabled"}`);
6678
- if (staged) {
6679
- console.log(` Staged mode: checking ${changedFiles.size} changed files against codebase`);
6680
- }
6681
6694
  if (crossPackage) {
6682
- console.log(` Cross-package mode: enabled`);
6695
+ console.log(` Cross-package: enabled`);
6683
6696
  }
6684
6697
  console.log();
6685
6698
  try {
@@ -6696,7 +6709,7 @@ Scanning ${targetPath}...`);
6696
6709
  const detectStart = performance.now();
6697
6710
  let duplicates = findDuplicates(blocks, similarity, targetPath);
6698
6711
  const detectTime = performance.now() - detectStart;
6699
- if (staged && changedFiles) {
6712
+ if (!scanAll && changedFiles) {
6700
6713
  duplicates = duplicates.filter((group) => group.matches.some((m) => changedFiles.has(m.filePath)));
6701
6714
  }
6702
6715
  if (crossPackage) {
@@ -6711,7 +6724,7 @@ Scanning ${targetPath}...`);
6711
6724
  console.log(`Found ${duplicates.length} duplicate groups in ${Math.round(detectTime)}ms
6712
6725
  `);
6713
6726
  if (duplicates.length === 0) {
6714
- if (staged) {
6727
+ if (!scanAll) {
6715
6728
  console.log("No duplicates in your changes. You're good!");
6716
6729
  } else if (crossPackage) {
6717
6730
  console.log("No cross-package duplicates found!");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dslop",
3
- "version": "1.1.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",