{"id":21105616,"url":"https://github.com/stazz/eslint-plugin-type-only-import","last_synced_at":"2025-03-14T09:11:40.965Z","repository":{"id":167300609,"uuid":"642309648","full_name":"stazz/eslint-plugin-type-only-import","owner":"stazz","description":"ESLint plugin to enforce `type` modifier to imports/exports targeting files with certain naming pattern.","archived":false,"fork":false,"pushed_at":"2023-05-19T20:00:22.000Z","size":86,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T12:08:10.609Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/stazz.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-18T09:29:23.000Z","updated_at":"2023-09-10T12:17:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"c8249a4d-4079-44ce-a3f5-14f172b207a1","html_url":"https://github.com/stazz/eslint-plugin-type-only-import","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"bb956266abafc4637881aca4e06299a9e5797f3d"},"previous_names":["stazz/eslint-plugin-type-only-import"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stazz%2Feslint-plugin-type-only-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stazz%2Feslint-plugin-type-only-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stazz%2Feslint-plugin-type-only-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stazz%2Feslint-plugin-type-only-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stazz","download_url":"https://codeload.github.com/stazz/eslint-plugin-type-only-import/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243352032,"owners_count":20276914,"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-11-20T00:08:24.598Z","updated_at":"2025-03-14T09:11:40.939Z","avatar_url":"https://github.com/stazz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Import/Export Type-only Fixer - ESLint Plugin\n- [Import/Export Type-only Fixer - ESLint Plugin](#importexport-type-only-fixer---eslint-plugin)\n- [Overview](#overview)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Options](#options)\n- [Rules](#rules)\n\n# Overview\n\nThe ESLint plugin `eslint-plugin-type-only-import` allows automation of managing `type` modifier for imports/exports matching a given pattern.\nIf such import/export is detected, and it doesn't have `type` modifier (either fully or any of its components), this plugin will attempt to fix the situation by adding `type` modifier to the import/export.\n\nThe most typical usecase for this plugin is when one is creating a library with TypeScript, and it has some files which should contain only types.\nOne option is to use `.d.ts` extension, but that has special meaning in TypeScript, causing e.g. compiler to leave that file out from the final emitting result.\nAnd if just using `.ts` extension, then e.g. code coverage tools will report those files as not covered.\n\nThe approach support by this plugin and which also fits nice with code coverage tools, is that these types-only `.ts` files will have some certain naming pattern, e.g. `xyz.types.ts`.\nThe code coverage tools can be configured to exclude such files from their analysis, and this ESLint plugin can be configured to enforce `type` modifier for any `import` or `export` statements that target such files.\n\nAssuming the plugin would be configured to add `type` modifier to all imports/exports which have target string literal matching pattern `*.types` , here are few examples about valid and invalid code\n|                     code                      |        is valid         |                                      auto-fixed to                                       |\n| :-------------------------------------------: | :---------------------: | :--------------------------------------------------------------------------------------: |\n|    `import * as code from \"./code.types\"`     |           :x:           |                       `import type * as code from \"./code.types\"`                        |\n|       `import * as code from \"./code\"`        | :ballot_box_with_check: | Target string literal does not match given pattern and thus the statement is unaffected. |\n|  `import type * as code from \"./code.types\"`  |   :white_check_mark:    |                                                                                          |\n| `import code, { type X } from \"./code.types\"` |           :x:           |                 `import type { default as code, X } from \"./code.types\"`                 |\n|   `import code, { X } from \"./code.types\"`    |           :x:           |                 `import type { default as code, X } from \"./code.types\"`                 |\n|    `import type { X } from \"./code.types\"`    |   :white_check_mark:    |                                                                                          |\n|    `import { type X } from \"./code.types\"`    |   :white_check_mark:    |                                                                                          |\n|       `import code from \"./code.types\"`       |           :x:           |                  `import type { default as code } from \"./code.types\"`                   |\n|        `export * from \"./code.types\"`         |           :x:           |                           `export type * from \"./code.types\"`                            |\n|      `export { X } from \"./code.types\"`       |           :x:           |                         `export type { X } from \"./code.types\"`                          |\n\n# Installation\nAssuming that ESLint has already been installed\n```sh\nyarn add --dev eslint@latest\n```\n, install this plugin:\n```sh\nyarn add --dev eslint-plugin-type-only-import@latest\n```\n\n# Configuration\nIn the `plugins` section of the [ESLint configuration](https://eslint.org/docs/latest/use/configure), specify the newly installed plugin:\n```json\n{\n  \"plugins\": [\n    \"type-only-import\"\n  ]\n}\n```\n\nThen, extend the recommended set (which configures both rules of this plugin to be treated as `error`):\n```json\n{\n  \"extends\": [\n    \"plugin:type-only-import/recommended\"\n  ]\n}\n```\n\nAlternatively, it is possible to configure each rule individually:\n```javascript\n{\n  \"rules\": {\n    \"type-only-import/require-type-only-import\": \"error\", // Recommended\n    \"type-only-import/require-type-only-import\": \"error\" // Recommented\n  }\n}\n```\n\n# Options\nBoth rules exposed by this plugin take optional individual options.\nThese options adher to single schema, which is a **JSON object** with the following properties:\n- `pattern` of type `string` : the pattern, as `RegExp` source, to match the import/export target string literals against.\n  Is treated verbatim, so to match relative-only imports/exports, use `\\.` as first character.\n  If using extensions in imports/exports, these must be included here too.\n  Default: `\\..+\\.types$`.\n- `disableFixer` of type `boolean` : If `true`, then none of the detected errors by this rule will be auto-fixed.\n  Default: `false`.\n\nFor more information, see [JSON schema specification and TS type in source code](./src/rule-helpers/options.ts).\n\n# Rules\nAll of the rules currently are fixable, and can be fixed automatically by running ESLint CLI with `--fix` flag.\n\n|    recommended     | fixable  |                               rule                               |                             description                             |\n| :----------------: | :------: | :--------------------------------------------------------------: | :-----------------------------------------------------------------: |\n| :white_check_mark: | :wrench: | [require-type-only-export](./src/rules/require-type-only-export) | Checks and fixes the target string literals in `export` statements. |\n| :white_check_mark: | :wrench: | [require-type-only-import](./src/rules/require-type-only-import) | Checks and fixes the target string literals in `import` statements. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstazz%2Feslint-plugin-type-only-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstazz%2Feslint-plugin-type-only-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstazz%2Feslint-plugin-type-only-import/lists"}