{"id":15668844,"url":"https://github.com/jaydenseric/eslint-plugin-optimal-modules","last_synced_at":"2025-05-06T20:03:10.273Z","repository":{"id":177095695,"uuid":"659931852","full_name":"jaydenseric/eslint-plugin-optimal-modules","owner":"jaydenseric","description":"An ESLint plugin to enforce optimal JavaScript module design.","archived":false,"fork":false,"pushed_at":"2024-09-26T02:51:14.000Z","size":24,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-03T22:47:12.762Z","etag":null,"topics":["eslint","esm","maintained","mjs","node","npm","typescript"],"latest_commit_sha":null,"homepage":"https://npm.im/eslint-plugin-optimal-modules","language":"JavaScript","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/jaydenseric.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":".github/funding.yml","license":"license.md","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},"funding":{"github":"jaydenseric"}},"created_at":"2023-06-28T22:10:45.000Z","updated_at":"2024-09-26T02:49:54.000Z","dependencies_parsed_at":"2024-10-23T09:55:59.429Z","dependency_job_id":"98832063-6172-456d-a157-781ddbe7caae","html_url":"https://github.com/jaydenseric/eslint-plugin-optimal-modules","commit_stats":null,"previous_names":["jaydenseric/eslint-plugin-optimal-modules"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenseric%2Feslint-plugin-optimal-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenseric%2Feslint-plugin-optimal-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenseric%2Feslint-plugin-optimal-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenseric%2Feslint-plugin-optimal-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaydenseric","download_url":"https://codeload.github.com/jaydenseric/eslint-plugin-optimal-modules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761121,"owners_count":21800123,"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":["eslint","esm","maintained","mjs","node","npm","typescript"],"created_at":"2024-10-03T14:20:17.484Z","updated_at":"2025-05-06T20:03:10.208Z","avatar_url":"https://github.com/jaydenseric.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jaydenseric"],"categories":[],"sub_categories":[],"readme":"# eslint-plugin-optimal-modules\n\nAn [ESLint plugin](https://eslint.org/docs/latest/use/configure/plugins) to enforce [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design).\n\n## Installation\n\nTo install [`eslint-plugin-optimal-modules`](https://npm.im/eslint-plugin-optimal-modules) with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), run:\n\n```sh\nnpm install eslint-plugin-optimal-modules --save-dev\n```\n\nTo use the [recommended config](#config-recommended), add the following ESLint “flat” config in [`eslint.config.mjs`](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file):\n\n```js\n// @ts-check\n\nimport eslintPluginOptimalModules from \"eslint-plugin-optimal-modules\";\n\n/**\n * ESLint config.\n * @satisfies {Array\u003cimport(\"eslint\").Linter.Config\u003e}\n */\nconst eslintConfig = [eslintPluginOptimalModules.configs.recommended];\n\nexport default eslintConfig;\n```\n\nAlternatively, manually configure the plugin and the desired rules:\n\n```js\n// @ts-check\n\nimport eslintPluginOptimalModules from \"eslint-plugin-optimal-modules\";\n\n/**\n * ESLint config.\n * @satisfies {Array\u003cimport(\"eslint\").Linter.Config\u003e}\n */\nconst eslintConfig = [\n  {\n    plugins: {\n      \"optimal-modules\": eslintPluginOptimalModules,\n    },\n    rules: {\n      \"optimal-modules/no-named-exports\": \"error\",\n    },\n  },\n];\n\nexport default eslintConfig;\n```\n\nTo allow named exports in [Storybook](https://storybook.js.org) story modules that have a [Component Story Format (CSF)](https://github.com/ComponentDriven/csf):\n\n```js\n// @ts-check\n\nimport eslintPluginOptimalModules from \"eslint-plugin-optimal-modules\";\n\n/**\n * ESLint config.\n * @satisfies {Array\u003cimport(\"eslint\").Linter.Config\u003e}\n */\nconst eslintConfig = [\n  eslintPluginOptimalModules.configs.recommended,\n  {\n    files: [\"**/*.stories.{mjs,cjs,js,mts,cts,ts,tsx}\"],\n    rules: {\n      \"optimal-modules/no-named-exports\": \"off\",\n    },\n  },\n];\n\nexport default eslintConfig;\n```\n\n## Rules\n\n### Rule `no-named-exports`\n\nProhibits using named exports for [optimal module design](https://jaydenseric.com/blog/optimal-javascript-module-design).\n\n**Valid** examples:\n\n```js\n// No exports.\nconst a = true;\n```\n\n```js\n// Default export.\nexport default true;\n```\n\n```js\n// Default export.\nconst a = true;\nexport { a as default };\n```\n\n```ts\n// TypeScript type default export.\ntype A = boolean;\nexport type { A as default };\n```\n\n**Invalid** examples:\n\n```js\n// Named export.\nexport const a = true;\n```\n\n```js\n// Named export.\nconst a = true;\nexport { a };\n```\n\n```ts\n// TypeScript type named export.\nexport type A = boolean;\n```\n\nTo fix the above errors, move the thing being exported to its own module as a default export.\n\n## Configs\n\n### Config `recommended`\n\nEnabled rules:\n\n- [`no-named-exports`](#rule-no-named-exports) (error).\n\n## Requirements\n\nSupported runtime environments:\n\n- [Node.js](https://nodejs.org) versions `^18.18.0 || ^20.9.0 || \u003e=21.1.0`.\n\nProjects must configure [TypeScript](https://typescriptlang.org) to use types from the CommonJS modules that have a `// @ts-check` comment:\n\n- [`compilerOptions.allowJs`](https://typescriptlang.org/tsconfig#allowJs) should be `true`.\n- [`compilerOptions.maxNodeModuleJsDepth`](https://typescriptlang.org/tsconfig#maxNodeModuleJsDepth) should be reasonably large, e.g. `10`.\n- [`compilerOptions.module`](https://typescriptlang.org/tsconfig#module) should be `\"node16\"` or `\"nodenext\"`.\n\n## Exports\n\nThese CommonJS modules are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):\n\n- [`eslintPluginOptimalModules.js`](./eslintPluginOptimalModules.js)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydenseric%2Feslint-plugin-optimal-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaydenseric%2Feslint-plugin-optimal-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydenseric%2Feslint-plugin-optimal-modules/lists"}