dslop 1.1.0 → 1.2.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,17 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.2.0
4
+
5
+ [compare changes](https://github.com/turf-sports/dslop/compare/v1.1.0...v1.2.0)
6
+
7
+ ### 🚀 Enhancements
8
+
9
+ - Default to checking uncommitted changes, add --all flag ([0492bba](https://github.com/turf-sports/dslop/commit/0492bba))
10
+
11
+ ### ❤️ Contributors
12
+
13
+ - Siddharth Sharma <sharmasiddharthcs@gmail.com>
14
+
3
15
  ## v1.1.0
4
16
 
5
17
  [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 uncommitted changes 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 uncommitted changes 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,7 +6561,7 @@ 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.2.0";
6565
6565
  function getChangedFiles(targetPath) {
6566
6566
  const absolutePath = path4.resolve(targetPath);
6567
6567
  try {
@@ -6589,15 +6589,17 @@ dslop - Detect Similar/Duplicate Lines Of Programming
6589
6589
  Usage:
6590
6590
  dslop [path] [options]
6591
6591
 
6592
+ By default, checks uncommitted changes against the codebase.
6593
+
6592
6594
  Arguments:
6593
6595
  path Directory to scan (default: current directory)
6594
6596
 
6595
6597
  Options:
6598
+ -a, --all Scan entire codebase (not just uncommitted changes)
6596
6599
  -m, --min-lines <n> Minimum block size in lines (default: ${DEFAULT_MIN_LINES})
6597
6600
  -s, --similarity <n> Minimum similarity threshold 0-100 (default: ${Math.round(DEFAULT_SIMILARITY * 100)})
6598
6601
  -e, --extensions <s> File extensions to scan (default: ${DEFAULT_EXTENSIONS.join(",")})
6599
6602
  -i, --ignore <s> Patterns to ignore (default: ${DEFAULT_IGNORE_PATTERNS.slice(0, 4).join(",")},...)
6600
- --staged Only show duplicates involving uncommitted changes
6601
6603
  --no-normalize Disable string/number normalization
6602
6604
  --cross-package Only show duplicates across different packages/apps (monorepo mode)
6603
6605
  --json Output as JSON
@@ -6605,10 +6607,10 @@ Options:
6605
6607
  -v, --version Show version
6606
6608
 
6607
6609
  Examples:
6608
- dslop . Scan current directory
6609
- dslop --staged Check uncommitted changes for duplicates
6610
+ dslop Check uncommitted changes for duplicates
6611
+ dslop --all Scan entire codebase
6610
6612
  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)
6613
+ dslop --all --cross-package Cross-package duplicates in entire codebase
6612
6614
  `);
6613
6615
  }
6614
6616
  function showVersion() {
@@ -6624,7 +6626,7 @@ async function main() {
6624
6626
  ignore: { type: "string", short: "i", default: DEFAULT_IGNORE_PATTERNS.join(",") },
6625
6627
  normalize: { type: "boolean", default: true },
6626
6628
  "no-normalize": { type: "boolean", default: false },
6627
- staged: { type: "boolean", default: false },
6629
+ all: { type: "boolean", short: "a", default: false },
6628
6630
  "cross-package": { type: "boolean", default: false },
6629
6631
  json: { type: "boolean", default: false },
6630
6632
  help: { type: "boolean", short: "h", default: false },
@@ -6646,7 +6648,7 @@ async function main() {
6646
6648
  const extensions = values.extensions.split(",").map((e) => e.trim());
6647
6649
  const ignorePatterns = values.ignore.split(",").map((p) => p.trim());
6648
6650
  const normalize2 = !values["no-normalize"];
6649
- const staged = values.staged;
6651
+ const scanAll = values.all;
6650
6652
  const crossPackage = values["cross-package"];
6651
6653
  const jsonOutput = values.json;
6652
6654
  if (minLines < 2) {
@@ -6663,23 +6665,24 @@ async function main() {
6663
6665
  minLines,
6664
6666
  normalize: normalize2
6665
6667
  };
6666
- const changedFiles = staged ? getChangedFiles(targetPath) : null;
6667
- if (staged && changedFiles?.size === 0) {
6668
+ const changedFiles = !scanAll ? getChangedFiles(targetPath) : null;
6669
+ if (!scanAll && changedFiles?.size === 0) {
6668
6670
  console.log(`
6669
- No uncommitted changes found.`);
6671
+ No uncommitted changes found. Use --all to scan entire codebase.`);
6670
6672
  process.exit(0);
6671
6673
  }
6672
6674
  console.log(`
6673
6675
  Scanning ${targetPath}...`);
6676
+ if (!scanAll) {
6677
+ console.log(` Mode: checking ${changedFiles.size} uncommitted files`);
6678
+ } else {
6679
+ console.log(` Mode: full codebase scan`);
6680
+ }
6674
6681
  console.log(` Extensions: ${extensions.join(", ")}`);
6675
6682
  console.log(` Min block size: ${minLines} lines`);
6676
6683
  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
6684
  if (crossPackage) {
6682
- console.log(` Cross-package mode: enabled`);
6685
+ console.log(` Cross-package: enabled`);
6683
6686
  }
6684
6687
  console.log();
6685
6688
  try {
@@ -6696,7 +6699,7 @@ Scanning ${targetPath}...`);
6696
6699
  const detectStart = performance.now();
6697
6700
  let duplicates = findDuplicates(blocks, similarity, targetPath);
6698
6701
  const detectTime = performance.now() - detectStart;
6699
- if (staged && changedFiles) {
6702
+ if (!scanAll && changedFiles) {
6700
6703
  duplicates = duplicates.filter((group) => group.matches.some((m) => changedFiles.has(m.filePath)));
6701
6704
  }
6702
6705
  if (crossPackage) {
@@ -6711,7 +6714,7 @@ Scanning ${targetPath}...`);
6711
6714
  console.log(`Found ${duplicates.length} duplicate groups in ${Math.round(detectTime)}ms
6712
6715
  `);
6713
6716
  if (duplicates.length === 0) {
6714
- if (staged) {
6717
+ if (!scanAll) {
6715
6718
  console.log("No duplicates in your changes. You're good!");
6716
6719
  } else if (crossPackage) {
6717
6720
  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.2.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",