Skip to content

Commit 4dcce65

Browse files
authored
Check for duplicate files enhancement (#24)
1 parent 880cf41 commit 4dcce65

File tree

9 files changed

+167
-68
lines changed

9 files changed

+167
-68
lines changed

.coderabbit.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
language: en-US
2+
tone_instructions: ''
3+
early_access: false
4+
enable_free_tier: true
5+
reviews:
6+
profile: chill
7+
request_changes_workflow: false
8+
high_level_summary: true
9+
high_level_summary_placeholder: '@coderabbitai summary'
10+
auto_title_placeholder: '@coderabbitai'
11+
review_status: true
12+
poem: false
13+
collapse_walkthrough: false
14+
sequence_diagrams: true
15+
path_filters: []
16+
path_instructions: []
17+
abort_on_close: true
18+
auto_review:
19+
enabled: true
20+
auto_incremental_review: true
21+
ignore_title_keywords: []
22+
labels: []
23+
drafts: false
24+
base_branches: []
25+
tools:
26+
shellcheck:
27+
enabled: true
28+
ruff:
29+
enabled: true
30+
markdownlint:
31+
enabled: true
32+
github-checks:
33+
enabled: true
34+
timeout_ms: 90000
35+
languagetool:
36+
enabled: true
37+
enabled_only: false
38+
level: default
39+
biome:
40+
enabled: true
41+
hadolint:
42+
enabled: true
43+
swiftlint:
44+
enabled: true
45+
phpstan:
46+
enabled: true
47+
level: default
48+
golangci-lint:
49+
enabled: true
50+
yamllint:
51+
enabled: true
52+
gitleaks:
53+
enabled: true
54+
checkov:
55+
enabled: true
56+
detekt:
57+
enabled: true
58+
eslint:
59+
enabled: true
60+
rubocop:
61+
enabled: true
62+
buf:
63+
enabled: true
64+
chat:
65+
auto_reply: true
66+
knowledge_base:
67+
opt_out: false
68+
learnings:
69+
scope: auto
70+
issues:
71+
scope: auto
72+
jira:
73+
project_keys: []
74+
linear:
75+
team_keys: []

demo/esp32/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <ESPAsyncWebServer.h>
77
#include "svelteesp32async.h"
88

9-
#if SVELTEESP32_COUNT != 10
9+
#if SVELTEESP32_COUNT != 11
1010
#error Invalid file count
1111
#endif
1212

@@ -40,7 +40,7 @@ void loop() {}
4040
#include <PsychicHttp.h>
4141
#include "svelteesp32psychic.h"
4242

43-
#if SVELTEESP32_COUNT != 10
43+
#if SVELTEESP32_COUNT != 11
4444
#error Invalid file count
4545
#endif
4646

demo/svelte/dist/favicon.png.gz

32.5 KB
Binary file not shown.

demo/svelte/dist/gallery/image-1a.jpg

20.7 KB
Loading

demo/svelte/package-lock.json

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/svelte/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"dev": "vite dev --host",
12-
"build": "vite build",
12+
"build": "vite build && gzip -c ./dist/favicon.png > ./dist/favicon.png.gz && cp ./dist/gallery/image-1.jpg ./dist/gallery/image-1a.jpg",
1313
"preview": "vite preview",
1414
"test": "npm run test:integration && npm run test:unit",
1515
"ts:check": "svelte-check --tsconfig ./tsconfig.json",
@@ -23,8 +23,8 @@
2323
"@rollup/plugin-swc": "^0.3.1",
2424
"@sveltejs/vite-plugin-svelte": "^3.1.1",
2525
"@tsconfig/svelte": "^5.0.4",
26-
"@typescript-eslint/eslint-plugin": "^8.1.0",
27-
"@typescript-eslint/parser": "^8.1.0",
26+
"@typescript-eslint/eslint-plugin": "^8.2.0",
27+
"@typescript-eslint/parser": "^8.2.0",
2828
"autoprefixer": "^10.4.20",
2929
"eslint": "^9.9.0",
3030
"eslint-config-prettier": "^9.1.0",

src/consoleColor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export const greenLog = (s: string): string => `\u001B[32m ${s} \u001B[0m`;
1+
export const greenLog = (s: string): string => `\u001B[32m${s}\u001B[0m`;
22

3-
export const yellowLog = (s: string): string => `\u001B[33m ${s} \u001B[0m`;
3+
export const yellowLog = (s: string): string => `\u001B[33m${s}\u001B[0m`;
44

5-
export const redLog = (s: string): string => `\u001B[31m ${s} \u001B[0m`;
5+
export const redLog = (s: string): string => `\u001B[31m${s}\u001B[0m`;

src/file.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1+
import { createHash } from 'node:crypto';
2+
import { readFileSync } from 'node:fs';
13
import path from 'node:path';
24

35
import { globSync } from 'glob';
46

57
import { cmdLine } from './commandLine';
6-
import { redLog } from './consoleColor';
8+
import { redLog, yellowLog } from './consoleColor';
79

8-
export const getFiles = (): string[] => {
9-
let files = globSync('**/*', { cwd: cmdLine.sourcepath, nodir: true });
10-
files = files.filter((filename) => {
10+
const findSimilarFiles = (files: Map<string, Buffer>): string[][] => {
11+
const contentComparer: Map<string, string[]> = new Map();
12+
for (const [filename, content] of files.entries()) {
13+
const hash = createHash('sha256').update(content).digest('hex');
14+
if (contentComparer.has(hash)) contentComparer.get(hash)!.push(filename);
15+
else contentComparer.set(hash, [filename]);
16+
}
17+
18+
const result: string[][] = [];
19+
for (const filenames of contentComparer.values()) if (filenames.length > 1) result.push(filenames);
20+
return result;
21+
};
22+
23+
export const getFiles = (): Map<string, Buffer> => {
24+
let filenames = globSync('**/*', { cwd: cmdLine.sourcepath, nodir: true });
25+
filenames = filenames.filter((filename) => {
1126
const extension = path.extname(filename);
1227
if (['.gz', '.brottli', '.br'].includes(extension)) {
1328
const original = filename.slice(0, -1 * extension.length);
14-
if (files.includes(original)) {
15-
console.log(redLog(`${filename} skipped because is perhaps a compressed version of ${original}`));
29+
if (filenames.includes(original)) {
30+
console.log(redLog(` ${filename} skipped because is perhaps a compressed version of ${original}`));
1631
return false;
1732
}
1833
}
1934
return true;
2035
});
21-
return files.sort();
36+
37+
const result: Map<string, Buffer> = new Map();
38+
for (const filename of filenames)
39+
result.set(filename, readFileSync(path.join(cmdLine.sourcepath, filename), { flag: 'r' }));
40+
for (const sameFile of findSimilarFiles(result))
41+
console.log(yellowLog(` ${sameFile.join(', ')} files look like identical`));
42+
return result;
2243
};

0 commit comments

Comments
 (0)