dslop 1.6.0 → 1.6.1

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,18 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.6.1
4
+
5
+ [compare changes](https://github.com/turf-sports/dslop/compare/v1.6.0...v1.6.1)
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - Suppress all logs when using --json output ([59e30f1](https://github.com/turf-sports/dslop/commit/59e30f1))
10
+ - Compact JSON output (90K→4K lines) ([3e93895](https://github.com/turf-sports/dslop/commit/3e93895))
11
+
12
+ ### ❤️ Contributors
13
+
14
+ - Siddharth Sharma <sharmasiddharthcs@gmail.com>
15
+
3
16
  ## v1.6.0
4
17
 
5
18
  [compare changes](https://github.com/turf-sports/dslop/compare/v1.5.2...v1.6.0)
package/dist/index.cjs CHANGED
@@ -51724,7 +51724,7 @@ async function scanDirectory(targetPath, options, enableAST = true) {
51724
51724
  }
51725
51725
 
51726
51726
  // index.ts
51727
- var VERSION = process.env.npm_package_version || "1.6.0";
51727
+ var VERSION = process.env.npm_package_version || "1.6.1";
51728
51728
  function parseDiffOutput(diff, cwd) {
51729
51729
  const changes = /* @__PURE__ */ new Map();
51730
51730
  let currentFile = null;
@@ -51994,15 +51994,19 @@ Scanning ${targetPath}...`);
51994
51994
  declDuplicates = filterCrossPackage(declDuplicates);
51995
51995
  }
51996
51996
  const totalGroups = duplicates.length + astDuplicates.length + declDuplicates.length;
51997
- console.log(`Found ${totalGroups} duplicate groups in ${Math.round(detectTime)}ms`);
51998
- if (astDuplicates.length > 0 || declDuplicates.length > 0) {
51999
- console.log(` (${duplicates.length} blocks, ${astDuplicates.length} AST, ${declDuplicates.length} declarations)
51997
+ if (!jsonOutput) {
51998
+ console.log(`Found ${totalGroups} duplicate groups in ${Math.round(detectTime)}ms`);
51999
+ if (astDuplicates.length > 0 || declDuplicates.length > 0) {
52000
+ console.log(` (${duplicates.length} blocks, ${astDuplicates.length} AST, ${declDuplicates.length} declarations)
52000
52001
  `);
52001
- } else {
52002
- console.log();
52002
+ } else {
52003
+ console.log();
52004
+ }
52003
52005
  }
52004
52006
  if (totalGroups === 0) {
52005
- if (!scanAll) {
52007
+ if (jsonOutput) {
52008
+ console.log(JSON.stringify({ duplicates: [], ast: [], declarations: [] }, null, 2));
52009
+ } else if (!scanAll) {
52006
52010
  console.log("No duplicates in your changes. You're good!");
52007
52011
  } else if (crossPackage) {
52008
52012
  console.log("No cross-package duplicates found!");
@@ -52012,7 +52016,33 @@ Scanning ${targetPath}...`);
52012
52016
  process.exit(0);
52013
52017
  }
52014
52018
  if (jsonOutput) {
52015
- console.log(JSON.stringify({ duplicates, ast: astDuplicates, declarations: declDuplicates }, null, 2));
52019
+ const compactDuplicates = duplicates.slice(0, 100).map((d) => ({
52020
+ lines: d.lineCount,
52021
+ occurrences: d.occurrences,
52022
+ similarity: Math.round(d.similarity * 100),
52023
+ preview: d.matches[0]?.content.split("\n").slice(0, 3).join("\n") || "",
52024
+ locations: d.matches.slice(0, 10).map((m) => `${m.filePath.replace(process.cwd() + "/", "")}:${m.startLine}`)
52025
+ }));
52026
+ const compactAST = astDuplicates.slice(0, 50).map((a) => ({
52027
+ type: a.type,
52028
+ name: a.matches[0]?.name || "unknown",
52029
+ occurrences: a.matches.length,
52030
+ locations: a.matches.map((m) => ({
52031
+ name: m.name,
52032
+ file: m.filePath.replace(process.cwd() + "/", ""),
52033
+ line: m.startLine,
52034
+ exported: m.exported
52035
+ }))
52036
+ }));
52037
+ console.log(JSON.stringify({
52038
+ summary: {
52039
+ duplicateGroups: duplicates.length,
52040
+ astGroups: astDuplicates.length,
52041
+ declarationGroups: declDuplicates.length
52042
+ },
52043
+ duplicates: compactDuplicates,
52044
+ ast: compactAST
52045
+ }, null, 2));
52016
52046
  } else {
52017
52047
  if (astDuplicates.length > 0) {
52018
52048
  console.log(formatASTDuplicates(astDuplicates, targetPath));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dslop",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Detect Similar/Duplicate Lines Of Programming - Find code duplication in your codebase",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",