69`$ sudo snap install scc`
70
71▶*NB* Snap installed applications cannot run outside of `/home` <https://askubuntu.com/questions/930437/permission-denied-error-when-running-apps-installed-as-snap-packages-ubuntu-17> so you may encounter issues if you use snap and attempt to run outside this directory.
72
73#### Homebrew
· · ·
501- 75% (High Density): Very terse, expressive code. Every line counts. (Example: Clojure, Haskell)
502- 60% - 70% (Standard): A healthy balance of logic and structural ceremony. (Example: Java, Python)
503▶- < 55% (High Boilerplate): High repetition. Likely due to mandatory error handling, auto-generated code, or verbose configuration. (Example: C#, CSS)
504
505See <https://boyter.org/posts/boilerplate-tax-ranking-popular-languages-by-density/> for more details.
· · ·
1294If you are running `scc` in a low memory environment < 512 MB of RAM you may need to set `--file-gc-count` to a lower value such as `0` to force the garbage collector to be on at all times.
1295
1296▶A sign that this is required will be `scc` crashing with panic errors.
1297
1298### Tests
3import (
4 "context"
5▶ "errors"
6 "fmt"
7 "math"
· · ·
63
64 if filterBad(loc) {
65▶ log.Error().Str(uniqueCode, "bfee4bd8").Str("loc", loc.String()).Msg("filter bad")
66 return
67 }
· · ·
71 res, err := process(1, loc)
72 if err != nil {
73▶ log.Error().Str(uniqueCode, "03ec75c3").Err(err).Str("loc", loc.String()).Send()
74 w.WriteHeader(http.StatusBadRequest)
75 _, _ = w.Write([]byte("something bad happened sorry"))
· · ·
108 addr := ":8080"
109 log.Info().Str(uniqueCode, "1876ce1e").Str("addr", addr).Msg("serving")
110▶ if err := http.ListenAndServe(addr, nil); err != nil && !errors.Is(err, http.ErrServerClosed) {
111 log.Error().Str(uniqueCode, "c28556e8").Err(err).Send()
112 os.Exit(1)
· · ·
111▶ log.Error().Str(uniqueCode, "c28556e8").Err(err).Send()
112 os.Exit(1)
113 }
+ 7 more matches in this file
57 t.Run(tt.name, func(t *testing.T) {
58 if got := resolveColor(tt.color); got != tt.want {
59▶ t.Errorf("resolveColor(%q) = %q, want %q", tt.color, got, tt.want)
60 }
61 })
· · ·
125 t.Run(tt.name, func(t *testing.T) {
126 if got := formatCount(tt.args.count); got != tt.want {
127▶ t.Errorf("formatCount() = %v, want %v", got, tt.want)
128 }
129 })
· · ·
170 got, err := processUrlPath(tt.args.path)
171 if (err != nil) != tt.wantErr {
172▶ t.Errorf("processUrlPath() error = %v, wantErr %v", err, tt.wantErr)
173 return
174 }
· · ·
175 if !reflect.DeepEqual(got, tt.want) {
176▶ t.Errorf("processUrlPath() got = %v, want %v", got, tt.want)
177 }
178 })
· · ·
298 t.Run(tt.name, func(t *testing.T) {
299 if got := parseBadgeSettings(tt.values); !reflect.DeepEqual(got, tt.want) {
300▶ t.Errorf("parseBadgeSettings() = %v, want %v", got, tt.want)
301 }
302 })
59github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
60github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
61▶github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
62github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
63github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4
5import (
6▶ "errors"
7 "fmt"
8 "os"
· · ·
15)
16
17▶func printShellCompletion(cmd *cobra.Command, command string) error {
18 switch command {
19 case "bash":
· · ·
26 return cmd.GenPowerShellCompletion(os.Stdout)
27 default:
28▶ return errors.New("Unknown shell: " + command)
29 }
30}
· · ·
66 b, err := os.ReadFile(filepath)
67 if err != nil {
68▶ fmt.Printf("Error reading flags from a file: %s\n", err)
69 os.Exit(1)
70 }
· · ·
545 err := printShellCompletion(rootCmd, args[3])
546 if err != nil {
547▶ _, _ = fmt.Fprintf(os.Stderr, "Error printing shell completion: %s\n", err)
548 }
549 return
+ 3 more matches in this file
29}
30
31▶func runSCC(args ...string) (string, error) {
32 args = slices.Insert(args, 0, sccTestFlag)
33 cmd := exec.Command(sccBinPath, args...)
· · ·
265 }
266 if !strings.Contains(output, "MATLAB") {
267▶ t.Errorf("can not find MATLAB, output: %s", output)
268 }
269 if !strings.Contains(output, "Objective C") {
· · ·
270▶ t.Errorf("can not find Objective C, output:\n%s", output)
271 }
272}
· · ·
276 output, err := runSCC("--not-a-real-option")
277 if err == nil {
278▶ t.Fatal("scc should exit with error code")
279 }
280 if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
· · ·
280▶ if !strings.Contains(output, "Error: unknown flag: --not-a-real-option") {
281 t.Fatalf("scc should report invalid options, output:\n%s", output)
282 }
+ 23 more matches in this file
81
82 errLogger := log.New(os.Stderr, "scc-mcp: ", log.LstdFlags)
83▶ if err := server.ServeStdio(mcpServer, server.WithErrorLogger(errLogger)); err != nil {
84 _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
85 os.Exit(1)
· · ·
84▶ _, _ = fmt.Fprintf(os.Stderr, "scc-mcp: server error: %v\n", err)
85 os.Exit(1)
86 }
· · ·
149}
150
151▶func mcpAnalyzeHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
152 args := request.GetArguments()
153
· · ·
161 absPath, err := filepath.Abs(path)
162 if err != nil {
163▶ return mcp.NewToolResultError(fmt.Sprintf("invalid path: %v", err)), nil
164 }
165
· · ·
166 // Verify path can be accessed
167 if _, err := os.Stat(absPath); err != nil {
168▶ return mcp.NewToolResultError(fmt.Sprintf("path cannot be accessed: %s: %v", absPath, err)), nil
169 }
170
+ 3 more matches in this file
6# 2. Follow the documentation below to learn how to create a package for the package type you are creating.
7# 3. In Chocolatey scripts, ALWAYS use absolute paths - $toolsDir gets you to the package's tools directory.
8▶$ErrorActionPreference = 'Stop'; # stop on all errors
9#Items that could be replaced based on what you call chocopkgup.exe with
10#{{PackageName}} - Package Name (should be same as nuspec file and folder) |/p
· · ·
75#Install-ChocolateyInstallPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-install-package
76
77▶## Main helper functions - these have error handling tucked into them already
78## see https://chocolatey.org/docs/helpers-reference
79
11## If this is an exe, change fileType, silentArgs, and validExitCodes
12
13▶$ErrorActionPreference = 'Stop'; # stop on all errors
14$packageArgs = @{
15 packageName = $env:ChocolateyPackageName
13 // Should be around 582
14 if got < 580 || got > 585 {
15▶ t.Errorf("Got %f", got)
16 }
17}
· · ·
23 // Should be around 2602096
24 if got < 2602000 || got > 2602100 {
25▶ t.Errorf("Got %f", got)
26 }
27}
· · ·
33 // Should be around 2.7
34 if got < 2.6 || got > 2.8 {
35▶ t.Errorf("Got %f", got)
36 }
37}
6 "bytes"
7 "cmp"
8▶ "errors"
9 "slices"
10 "strings"
· · ·
12
13var (
14▶ errMissingShebang = errors.New("missing shebang")
15 errUnknownShebang = errors.New("unknown shebang")
16 errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
· · ·
15▶ errUnknownShebang = errors.New("unknown shebang")
16 errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
17)
· · ·
16▶ errUnableToDetermineShebangCmd = errors.New("unable to determine shebang command")
17)
18
· · ·
19▶// DetectLanguage detects a language based on the filename returns the language extension and error
20func DetectLanguage(name string) ([]string, string) {
21 extension := ""
+ 2 more matches in this file
14
15 if ext != "css" {
16▶ t.Error("Expected css got", ext)
17 }
18 AllowListExtensions = []string{}
· · ·
25
26 if x != "" || y == nil {
27▶ t.Error("Expected no match got", x)
28 }
29}
· · ·
48
49 if x != "Perl" || y != nil {
50▶ t.Error("Expected Perl match got", x, "for", c)
51 }
52 }
· · ·
65
66 if x != "PHP" || y != nil {
67▶ t.Error("Expected PHP match got", x)
68 }
69 }
· · ·
83
84 if x != "Python" || y != nil {
85▶ t.Error("Expected Python match got", x)
86 }
87 }
+ 31 more matches in this file
66 }
67
68▶ var err error
69 symPath, err = filepath.EvalSymlinks(path)
70 if err != nil {
· · ·
71▶ printError(err.Error())
72 return nil
73 }
· · ·
74 fileInfo, err = os.Lstat(symPath)
75 if err != nil {
76▶ printError(err.Error())
77 return nil
78 }
16
17 if got != expected {
18▶ t.Errorf("Expected %s got %s", expected, got)
19 }
20}
· · ·
25
26 if got != expected {
27▶ t.Errorf("Expected %s got %s", expected, got)
28 }
29}
· · ·
34
35 if got != expected {
36▶ t.Errorf("Expected %s got %s", expected, got)
37 }
38}
· · ·
43
44 if got != expected {
45▶ t.Errorf("Expected %s got %s", expected, got)
46 }
47}
· · ·
52
53 if got != expected {
54▶ t.Errorf("Expected %s got %s", expected, got)
55 }
56}
+ 14 more matches in this file
23
24// ReadFile actually reads the file into a buffer size controlled by LargeByteCount
25▶func (reader *FileReader) ReadFile(path string, size int) ([]byte, error) {
26 fd, err := os.Open(path)
27 if err != nil {
· · ·
28▶ return nil, fmt.Errorf("error opening %s: %v", path, err)
29 }
30 defer func(file *os.File) {
· · ·
48 _, err = io.Copy(reader.Buffer, fd)
49 if err != nil {
50▶ return nil, fmt.Errorf("error reading %s: %v", path, err)
51 }
52
18
19 if !strings.Contains(str.String(), "Estimated Schedule Effort (organic) 0.22 months") {
20▶ t.Error("expected to match got", str.String())
21 }
22}
· · ·
27
28 if !strings.Contains(str.String(), "Processed 1 bytes, 0.000 megabytes (SI)") {
29▶ t.Error("expected to match got", str.String())
30 }
31}
· · ·
36
37 if !strings.Contains(str.String(), "Processed 1000000 bytes, 1.000 megabytes (SI)") {
38▶ t.Error("expected to match got", str.String())
39 }
40}
· · ·
95
96 if summary.Files[0].Filename != "aaaa.go" {
97▶ t.Error("Sorting on lines failed", val)
98 }
99 }
· · ·
105
106 if summary.Files[0].Filename != "aaaa.go" {
107▶ t.Error("Sorting on blank failed", val)
108 }
109 }
+ 93 more matches in this file
11 got := LocomoComplexityDensity(10, 0)
12 if got != 0 {
13▶ t.Errorf("Expected 0 for zero code lines, got %f", got)
14 }
15}
· · ·
18 got := LocomoComplexityDensity(30, 100)
19 if math.Abs(got-0.3) > 0.001 {
20▶ t.Errorf("Expected 0.3, got %f", got)
21 }
22}
· · ·
26 got := LocomoComplexityFactor(0.3, 5)
27 if got < 3.7 || got > 3.8 {
28▶ t.Errorf("Expected ~3.74, got %f", got)
29 }
30}
· · ·
34 got := LocomoComplexityFactor(0.05, 5)
35 if got < 2.0 || got > 2.2 {
36▶ t.Errorf("Expected ~2.12, got %f", got)
37 }
38}
· · ·
42 got := LocomoIterationFactor(0.3, 1.5, 2)
43 if got < 2.5 || got > 2.7 {
44▶ t.Errorf("Expected ~2.60, got %f", got)
45 }
46}
+ 23 more matches in this file
678
679 fileWalker := gocodewalker.NewParallelFileWalker(dirPaths, potentialFilesQueue)
680▶ fileWalker.SetErrorHandler(func(e error) bool {
681 printError(e.Error())
682 return true
· · ·
681▶ printError(e.Error())
682 return true
683 })
· · ·
701 excludePathRegexes = append(excludePathRegexes, regexpResult)
702 } else {
703▶ printError(err.Error())
704 }
705 }
· · ·
708 err := fileWalker.Start()
709 if err != nil {
710▶ printError(err.Error())
711 }
712 }()
13
14 if len(ExtensionToLanguage) == 0 {
15▶ t.Error("Should not be 0")
16 }
17
· · ·
18 if len(LanguageFeatures) == 0 {
19▶ t.Error("Should not be 0")
20 }
21}
· · ·
26
27 if PathDenyList[0] != "testing" {
28▶ t.Error("expected / to be trimmed")
29 }
30
· · ·
39 ConfigureLazy(true)
40 if !isLazy {
41▶ t.Error("isLazy should be true")
42 }
43
· · ·
44 ConfigureLazy(false)
45 if isLazy {
46▶ t.Error("isLazy should be false")
47 }
48}
+ 8 more matches in this file
16// ProcessResult runs the same pipeline as Process but returns structured results
17// instead of formatting to stdout. Useful for programmatic consumers like MCP servers.
18▶func ProcessResult() ([]LanguageSummary, error) {
19 ProcessConstants()
20 processFlags()
· · ·
33 s, err := os.Stat(fpath)
34 if err != nil {
35▶ return nil, fmt.Errorf("file or directory could not be read: %s", fpath)
36 }
37
· · ·
55
56 fileWalker := gocodewalker.NewParallelFileWalker(dirPaths, potentialFilesQueue)
57▶ fileWalker.SetErrorHandler(func(e error) bool {
58 printError(e.Error())
59 return true
· · ·
58▶ printError(e.Error())
59 return true
60 })
· · ·
78 excludePathRegexes = append(excludePathRegexes, regexpResult)
79 } else {
80▶ printError(err.Error())
81 }
82 }
+ 1 more matches in this file
107 result := StringSimilarRatio(tc.s1, tc.s2) >= SimilarStringThreshold
108 if result != tc.isSimilar {
109▶ t.Errorf("StringSimilarRatio(%q, %q) failed, got %v, want %v", tc.s1, tc.s2, result, tc.isSimilar)
110 }
111 }
· · ·
113
114func TestGetMostSimilarFlags(t *testing.T) {
115▶ flags := pflag.NewFlagSet("testing", pflag.ExitOnError)
116 _ = flags.Bool("no-ignore", false, "test")
117 _ = flags.Bool("no-gitignore", false, "test")
· · ·
171 result := GetMostSimilarFlags(flags, tc.name)
172 if !slices.Equal(result, tc.expects) {
173▶ t.Errorf("got: %v, want: %v", result, tc.expects)
174 }
175 }
19
20 if !c.Check(1, []byte("hash")) {
21▶ t.Error("Expected match")
22 }
23
· · ·
24 if !c.Check(1, []byte("hash2")) {
25▶ t.Error("Expected match")
26 }
27
· · ·
28 if c.Check(2, []byte("hash")) {
29▶ t.Error("Expected no match")
30 }
31
· · ·
32 if c.Check(1, []byte("hash3")) {
33▶ t.Error("Expected no match")
34 }
35}
· · ·
87 typ, depth, closed := trie.Match(tc.token)
88 if typ != tc.expectType {
89▶ t.Errorf("\"%v\" matched wrong type, want: %v, got: %v", string(tc.token), tc.expectType, typ)
90 }
91 if depth != tc.expectDepth {
+ 6 more matches in this file