{"id":40543705,"url":"https://github.com/lerebear/sizeup-core","last_synced_at":"2026-01-20T23:17:29.539Z","repository":{"id":195720241,"uuid":"692382613","full_name":"lerebear/sizeup-core","owner":"lerebear","description":"A library for estimating how difficult a diff will be to review","archived":false,"fork":false,"pushed_at":"2025-11-17T16:26:58.000Z","size":200,"stargazers_count":7,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-17T18:12:01.086Z","etag":null,"topics":["code-review","library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lerebear.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-16T10:09:04.000Z","updated_at":"2025-11-17T16:27:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"84502dae-a5fb-4609-a50e-3070d864f3fb","html_url":"https://github.com/lerebear/sizeup-core","commit_stats":{"total_commits":82,"total_committers":2,"mean_commits":41.0,"dds":0.03658536585365857,"last_synced_commit":"7e682a6ddba0f754390e5b612ca3197ce4b8f054"},"previous_names":["lerebear/sizeup","lerebear/sizeup-core"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/lerebear/sizeup-core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerebear%2Fsizeup-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerebear%2Fsizeup-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerebear%2Fsizeup-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerebear%2Fsizeup-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lerebear","download_url":"https://codeload.github.com/lerebear/sizeup-core/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerebear%2Fsizeup-core/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28618798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T22:24:05.405Z","status":"ssl_error","status_checked_at":"2026-01-20T22:20:31.342Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["code-review","library"],"created_at":"2026-01-20T23:17:28.919Z","updated_at":"2026-01-20T23:17:29.532Z","avatar_url":"https://github.com/lerebear.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SizeUp\n\nSizeUp is a library for estimating how difficult a diff will be to review.\n\n## Installation\n\n```\nnpm install sizeup-core\n```\n\n## Usage\n\nThe most common usage of this library is via one of these wrappers:\n\n- [sizeup-action](https://github.com/lerebear/sizeup-action), which provides a GitHub Action to use this library to evaluate pull requests\n- [sizeup-cli](https://github.com/lerebear/sizeup-cli), which provides a CLI to use this library to evaluate a diff locally, prior to opening a pull request\n\nTo use the library directly, you need to first retrieve a diff, and the pass it\nto `SizeUp.evaluate` (optionally also providing a custom configuration file):\n\n```ts\nimport { SizeUp } from \"sizeup-core\"\n\nconst diff = (\n  await octokit\n    .rest\n    .pulls\n    .get({\n    \"lerebear\",\n    \"sizeup\",\n    pull_number: 1,\n\n    // This is the easiest way to request a diff directly, but since Octokit\n    // doesn't provide the correct result type when we use the `mediaType`\n    // option, we must cast the result to a string later on\n    mediaType: {format: 'diff'},\n  })\n).data as unknown as string\n\nconst score = SizeUp.evaluate(diff)\nconsole.log(score.toString())\n```\n\nThe final log statement in that snippet will output a serialized `Score`:\n\n```jsonc\n{\n  // The expression (written in prefix notation) used to score the diff\n  \"formula\": \"- - + additions deletions comments whitespace\",\n\n  // The values that were substituted for each variable in the formula\n  \"variableSubstitutions\": [\n    [\n      \"additions\",\n      11\n    ],\n    [\n      \"deletions\",\n      3\n    ],\n    [\n      \"comments\",\n      6\n    ],\n    [\n      \"whitespace\",\n      1\n    ]\n  ],\n\n  // The score the diff received when evaluated according to the formula\n  \"value\": 7,\n\n  // The category the diff was assigned based on its score\n  \"category\": \"xs\"\n}\n```\n\n## API\n\nThe public API for this library consists of the single, static `SizeUp.evaluate` method:\n\n```ts\nexport class SizeUp {\n  /**\n   * Evaluates a diff for reviewability.\n   *\n   * @param diff A .diff formatted string containing the code to evaluate\n   * @param configPath Path to a YAML configuration file containing options for how to evaluate the\n   *   pull request. The YAML file should conform to the JSON schema in src/config/schema.json.\n   */\n  static evaluate(diff: string, configPath?: string): Score\n}\n```\n\n## Configuration\n\nThis section describes how to configure this library.\n\n### Overview\n\nAs shown [above](#api), `SizeUp.evaluate` accepts a YAML configuration file that can be used to customize the evaluation process. Here's an example:\n\n```yaml\ncategories:\n  - name: xs\n    lte: 10\n  - name: s\n    lte: 30\n  - name: m\n    lte: 100\n  - name: l\n    lte: 500\n  - name: xl\nignoredFilePatterns:\n  - CODEOWNERS\n  - SERVICEOWNERS\ntestFilePatterns:\n  - \"*_test.rb\"\nscoring:\n  formula: \"- - + additions deletions comments whitespace\"\n```\n\nThe default configuration that is used when no configuration file is provided can be found in [`src/config/default.yaml`](./src/config/default.yaml).\n\nThe full specification for the configuration file is provided by the JSON schema at [`src/config/schema.json`](./src/config/schema.json).\n\n### Configuring a scoring formula\n\n`sizeup` is designed to allow users to experiment with different ways to evaluate a diff. You can do this my writing a custom scoring formula that you provide to the libary via the `score.formula` key in the configuration file.\n\nThe elements of a formula are described in more detail in each of the following sections:\n\n- [Prefix notation](#prefix-notation)\n- [Operators](#operators)\n- [Features](#features)\n- [Aliases](#aliases)\n\n#### Prefix notation\n\nEach formula is written in [prefix notation](https://en.wikipedia.org/wiki/Polish_notation), which means that instead of writing a mathematical operator in between its operands (infix notation), you write it before its operands. For example:\n\n| Traditional (infix notation) expression | Equivalent prefix notation expression |\n| :--- | :--- |\n| `1 + 2`| `+ 1 2` |\n| `(2 + 3) / 10` | `/ + 2 3 10` |\n\n#### Operators\n\nOperators are used to evaluate numerical or logical sub-expressions in a formula. This tool supports the following operators:\n\n| Symbol | Meaning | Example |\n| :--- | :--- | :--- |\n| `+` | addition | `+ 1 2` evaluates to `3` |\n| `-` | subtraction | `- 2 1` evaluates to `1` |\n| `*` | multiplication | `* 1 2` evaluates to `2` |\n| `\\` | division | `/ 4 2` evaluates to `2` |\n| `^` | exponentiation | `^ 2 3` evaluates to `8` |\n| `?` | conditional evaluation | `? 0 2 4` evaluates to 4 because `0` is considered `false`[^1] |\n| `\u003e` | greater than | `\u003e 1 2` evaluates to `false` |\n| `\u003c` | less than | `\u003c 1 2` evaluates to `true` |\n| `\u003e=` | greater than or equal to | `\u003e= 1 2` evaluates to `false` |\n| `\u003c=` | less than or equal to | `\u003c= 1 1` evaluates to `true` |\n| `==` | equals | `== 1 1` evaluates to `true` |\n| `!=` | not equal | `!= 1 1` evaluates to `false` |\n| `\u0026` | logical and | `\u0026 0 1` evaluates to `false`[^1] |\n| `\\|` | logical or | `\\| 0 1` evaluates to `true`[^1] |\n| `!` | logical not | `! 1` evaluates to `false`[^1] |\n\n\n[^1]: All positive numbers are considered truthy; `0` and all negative numbers are considered falsey.\n\nEach operand can be one of three things:\n\n1. A numerical constant like `0.5` or `99`\n2. The name of a [feature](#features)\n3. The name of an [alias](#aliases)\n\n#### Features\n\nFeatures describe aspects of a diff that can be computed from it automatically. This tool support the following features:\n\n| Feature | Description |\n| :--- | :--- |\n| `additions` | The number of lines that were added in a diff |\n| `comments`  | The number of additions in a diff that match the syntax of a comment in a [supported programming language](https://github.com/lerebear/sizeup-core/blob/6d1ba961131e32731312937cbf3e9945e4d41afe/src/linguist.ts#L154-L170). |\n| `deletions` | The number of lines that were deleted in a diff |\n| `single-words` | The number of additions in a diff that are made up of a single word on its own line |\n| `tests` | The number of additions in a diff that were made in files that match a pattern from the `testFilePatterns` configuration value. |\n| `whitespace` | The number of additions in a diff that were pure whitespace |\n\nIf you have an idea for a new feature, please [suggest an enhancement](https://github.com/lerebear/sizeup-core/issues?q=is%3Aissue%20state%3Aopen%20label%3Aenhancement).\n\n#### Aliases\n\nAliases, which are configured under the `scoring.aliases` key, allow you to define a shorthand for a longer expression:\n\n```yaml\nscoring:\n  formula: \"- changes non-functional-changes\"\n  aliases:\n    changes: \"+ additions deletions\"\n    non-functional-changes: \"+ comments whitespace\"\n```\n\n## Development\n\nThis section contains notes for how to develop this library.\n\n### Regenerating the Typescript interface for the configuration schema\n\nWe use a [JSON schema](./src/config/schema.json) to define the configuration options that this library supports. We then use the [`json-schema-to-typescript`](https://www.npmjs.com/package/json-schema-to-typescript) package to generate the [TypeScript `Configuration` interface](./src/configuration.ts) that we use in code.\n\n[`json-schema-to-typescript`](https://www.npmjs.com/package/json-schema-to-typescript) uses outdated type definitions which are incompatible with the latest version of [`minimatch`](https://www.npmjs.com/package/minimatch) that we use in this package. This creates build errors if `json-schema-to-typescript` is  added as a dependency of this package.\n\nTo work around those issues, we use the following workflow to regenerate the `Configuration` interface after we've made a change to the schema:\n\n1. Temporarily install `json-schema-to-typescript`:\n\n```sh\nnpm install --save-dev json-schema-to-typescript\n```\n\n2. Regenerate the `Configuration` interface using this command:\n\n```sh\nnpm run generate:config\n```\n\n3. Remove `json-schema-to-typescript` so that we can again build this package without errors.\n\n```sh\nnpm uninstall json-schema-to-typescript\n```\n\n### Releasing a new version\n\n- This library is released as a package on NPM.\n  - Publishing a new version to NPM follows standard practice e.g:\n\n  ```sh\n  npm version patch\n  git push --follow-tags\n\n  # Wait for build to complete successfully\n\n  npm publish\n  ```\n- A new GitHub release is also created for each tag that is packaged for NPM.\n  - Those releases are created from https://github.com/lerebear/sizeup-core/releases/new. After selecting the appropriate tag, we typically generally release notes automatically using the button in the UI.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flerebear%2Fsizeup-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flerebear%2Fsizeup-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flerebear%2Fsizeup-core/lists"}