dslop 1.2.0 → 1.3.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 +23 -0
- package/README.md +2 -2
- package/dist/index.js +24 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.3.1
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/turf-sports/dslop/compare/v1.3.0...v1.3.1)
|
|
6
|
+
|
|
7
|
+
### 🏡 Chore
|
|
8
|
+
|
|
9
|
+
- Remove verbose comments ([1fa02d6](https://github.com/turf-sports/dslop/commit/1fa02d6))
|
|
10
|
+
|
|
11
|
+
### ❤️ Contributors
|
|
12
|
+
|
|
13
|
+
- Siddharth Sharma <sharmasiddharthcs@gmail.com>
|
|
14
|
+
|
|
15
|
+
## v1.3.0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### 🚀 Enhancements
|
|
19
|
+
|
|
20
|
+
- Include committed branch changes in default scan ([468c514](https://github.com/turf-sports/dslop/commit/468c514))
|
|
21
|
+
|
|
22
|
+
### ❤️ Contributors
|
|
23
|
+
|
|
24
|
+
- Siddharth Sharma <sharmasiddharthcs@gmail.com>
|
|
25
|
+
|
|
3
26
|
## v1.2.0
|
|
4
27
|
|
|
5
28
|
[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
|
|
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
|
|
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.
|
|
6564
|
+
var VERSION = process.env.npm_package_version || "1.3.1";
|
|
6565
6565
|
function getChangedFiles(targetPath) {
|
|
6566
6566
|
const absolutePath = path4.resolve(targetPath);
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
const
|
|
6570
|
-
|
|
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
|
|
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
|
|
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
|
|
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}
|
|
6687
|
+
console.log(` Mode: checking ${changedFiles.size} changed files`);
|
|
6678
6688
|
} else {
|
|
6679
6689
|
console.log(` Mode: full codebase scan`);
|
|
6680
6690
|
}
|