Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b63a21

Browse files
committed
feat: add sort cloc support
1 parentdecb12a commit4b63a21

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

‎cmd/cloc.go‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"log"
1414
"os"
1515
"path/filepath"
16+
"sort"
1617
"strings"
1718
)
1819

@@ -64,7 +65,22 @@ func processTopFile(dir string) {
6465

6566
runProcessor()
6667

67-
//content := cmd_util.ReadCocaFile("top_cloc.json")
68+
var languageSummaries []processor.LanguageSummary
69+
content := cmd_util.ReadCocaFile("top_cloc.json")
70+
err := json.Unmarshal(content, &languageSummaries)
71+
checkError("no a valid language languageSummaries", err)
72+
73+
for _, langSummary := range languageSummaries {
74+
files := langSummary.Files
75+
sort.Slice(files,func(i, jint)bool {
76+
return files[i].Code > files[j].Code
77+
})
78+
79+
langSummary.Files = files
80+
}
81+
82+
sortContent, _ := json.Marshal(languageSummaries)
83+
cmd_util.WriteToCocaFile("sort_cloc.json",string(sortContent))
6884
}
6985

7086
funcprocessByDirectory(firstDir string) {

‎cmd/cloc_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,22 @@ func TestShouldReturnNullWhenIgnoreDir(t *testing.T) {
5555
Golden:"testdata/cloc_ignore.txt",
5656
}}
5757
RunTestCmd(t,tests)
58+
}
59+
60+
funcTestShouldByFileSize(t*testing.T) {
61+
abs:="../_fixtures"
62+
63+
analysis:= []testcase.CmdTestCase{{
64+
Name:"analysis",
65+
Cmd:"analysis -p "+abs,
66+
Golden:"",
67+
}}
68+
RunTestCmd(t,analysis)
69+
70+
tests:= []testcase.CmdTestCase{{
71+
Name:"cloc",
72+
Cmd:"cloc "+abs+" --top-file",
73+
Golden:"",
74+
}}
75+
RunTestCmd(t,tests)
5876
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp