{"id":13702277,"url":"https://github.com/ocharles/weeder","last_synced_at":"2025-05-15T15:04:40.635Z","repository":{"id":39904977,"uuid":"207516878","full_name":"ocharles/weeder","owner":"ocharles","description":"A re-implementation of weeder using HIE files","archived":false,"fork":false,"pushed_at":"2025-03-04T17:22:51.000Z","size":270,"stargazers_count":176,"open_issues_count":38,"forks_count":30,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-08T00:39:44.677Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocharles.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-10T09:23:38.000Z","updated_at":"2025-05-04T19:01:39.000Z","dependencies_parsed_at":"2023-02-12T02:45:19.853Z","dependency_job_id":"d5d6f587-1158-436d-8aee-592c5b04e124","html_url":"https://github.com/ocharles/weeder","commit_stats":{"total_commits":139,"total_committers":21,"mean_commits":6.619047619047619,"dds":"0.36690647482014394","last_synced_commit":"6c78e137033025c6b33e35fb8f9e681d55c43427"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocharles%2Fweeder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocharles%2Fweeder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocharles%2Fweeder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocharles%2Fweeder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocharles","download_url":"https://codeload.github.com/ocharles/weeder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364270,"owners_count":22058878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T21:00:33.146Z","updated_at":"2025-05-15T15:04:40.617Z","avatar_url":"https://github.com/ocharles.png","language":"Haskell","readme":"# Weeder\n\nWeeder is an application to perform whole-program dead-code analysis. Dead code\nis code that is written, but never reachable from any other code. Over the\nlifetime of a project, this happens as code is added and removed, and leftover\ncode is never cleaned up. While GHC has warnings to detect dead code is a single\nmodule, these warnings don't extend across module boundaries - this is where\nWeeder comes in.\n\nWeeder uses HIE files produced by GHC - these files can be thought of as source\ncode that has been enhanced by GHC, adding full symbol resolution and type\ninformation. Weeder builds a dependency graph from these files to understand how\ncode interacts. Once all analysis is done, Weeder performs a traversal of this\ngraph from a set of roots (e.g., your `main` function), and determines which\ncode is reachable and which code is dead.\n\n# Using Weeder\n\n## Preparing Your Code for Weeder\n\nTo use Weeder, you will need to generate `.hie` files from your source code.\n\n### Cabal\n\nIf you use Cabal, this is easily done by adding one line to your\n`cabal.project.local` file:\n\n``` cabal\nprogram-options\n  ghc-options: -fwrite-ide-info\n```\n\nOnce this has been added, perform a full rebuild of your project:\n\n``` shell\ncabal clean\ncabal build all\n```\n\n### Stack\n\nIf you use `stack`, add the following to your `stack.yaml`:\n\n``` yaml\nghc-options:\n  \"$locals\": -fwrite-ide-info\n```\n\nand rebuild:\n\n``` shell\nstack clean\nstack build\n```\n\n### Nix\n\nSee [`weeder-nix`](https://github.com/NorfairKing/weeder-nix) for `weeder \u003c-\u003e nixpkgs` integration.\n\n## Calling Weeder\n\nTo call Weeder, you first need to provide a configuration file, `weeder.toml`. Weeder uses\n[TOML](https://toml.io/en/) as its configuration format.\n\n`roots` is a list of regular expressions of symbols that are considered as\nalive. If you're building an executable, the pattern `^Main.main$` is a\ngood starting point - specifying that `main` is a root. Weeder currently doesn't\nadd all exported functions as roots automatically but in many cases `main` from a\ntest suite could be a good workaround for that\n\n`type-class-roots` configures whether or not Weeder should consider all instances\nof type classes as roots. Defaults to `false`.\n\n``` toml\nroots = [ \"^Main.main$\" ]\ntype-class-roots = true\n```\n\nNow invoke the `weeder` executable, and - if your project has weeds - you will\nsee something like the following:\n\n``` shell\n$ weeder\nsrc/Dhall/TH.hs:187: toDeclaration\nsrc/Dhall/TH.hs:196: toNestedHaskellType\n```\n\n… which indicates the location of two unused symbols.\n(Please note these warnings are just for demonstration and not necessarily weeds\nin the Dhall project).\n\n## Configuration options\n\n| Name             | Default value                        | Description |\n| ---------------- | ------------------------------------ | --- |\n| roots            | `[ \"Main.main\", \"^Paths_weeder.*\" ]` | Any declarations matching these regular expressions will be considered as alive. |\n| type-class-roots | `false`                              | Consider all instances of type classes as roots. Overrides `root-instances`. |\n| root-instances   | `[ {class = '\\.IsString$'}, {class = '\\.IsList$'} ]` | Type class instances that match on all specified fields will be considered as roots. Accepts the fields `instance` matching on the pretty-printed type of the instance (visible in the output), `class` matching on its parent class declaration, and `module` matching on the module the instance is defined in. |\n| root-modules     | `[]`                                 | The exports of all matching modules will be considered as alive. This does not include type class instances implicitly exported by the module.\n| unused-types     | `false`                              | Enable analysis of unused types. |\n\n`root-instances` can also accept string literals as a shorthand for writing a table\ncontaining only the `instance` field. See the following example from the test suite:\n\n``` toml\nroot-instances = [ { module = \"Spec.ConfigInstanceModules.Module1\", instance = \"Bounded T\" }\n                 , \"Read T\" \n                 , { module = \"Spec.ConfigInstanceModules.Module3\" }\n                 , { class = '\\.Enum$' }\n                 , { module = \"Spec.ConfigInstanceModules.Module2\", class = '\\.Show$' }\n                 ]\n```\n\n## Exit codes\n\nWeeder emits the following exit codes:\n\n| Exit code | Cause |\n| --- | --- |\n|  0  | No weeds were found |\n| 228 | One or more weeds found |\n|  1  | Generic failing exit code |\n|  2  | Failure to read HIE file due to GHC version mismatch |\n|  3  | Failure to parse config file |\n|  4  | No HIE files found |\n\n# Tips\n\n- You may want to add `^Paths_.*` to the roots in `weeder.toml` to ignore the\n  `Paths_packageName` module automatically generated by Cabal.\n\n- You can automatically write and use a default configuration file by calling \n  Weeder with the `--write-default-config` flag, if no configuration file is\n  found.\n\n- You can mandate explicitly specifying every option in the configuration by \n  calling Weeder with the `--no-default-fields` flag. This can prevent being\n  caught off guard by new configuration options or changes to default values.\n\n- To mark all instances in a module `M` as roots, add `{ module = \"^M$\" }`\n  to `root-instances`.\n\n# Limitations\n\nWeeder currently has a few limitations:\n\n## Overloaded syntax\n\nOn some versions of GHC, Weeder might report various type classes that are used\nfor syntax extensions as weeds. For example, `Num` and `IsString` classes might be\nflagged as weeds if they are only used for overloaded literal syntax (that is,\nthe `fromInteger` and `fromString` methods).\n\nYou can add instances of specific type classes as roots with the `root-instances` \nfield, or toggle whether Weeder considers all type class instances as roots with \nthe `type-class-roots` configuration option.\n\n## Type families\n\nWeeder cannot yet analyse uses of type family instances. For this reason type\nfamily instances will be marked as implicit roots if analysis of types is\nenabled via `unused-types`.\n\n## Template Haskell\n\nWeeder is currently unable to parse the result of a Template Haskell splice. If\nsome Template Haskell code refers to other source code, this dependency won't be\ntracked by Weeder, and thus Weeder might end up with false positives.\n","funding_links":[],"categories":["Cabal Assistants","Programming Languages"],"sub_categories":["Dependencies analysers"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focharles%2Fweeder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focharles%2Fweeder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focharles%2Fweeder/lists"}