{"id":35043304,"url":"https://github.com/ysknsid25/eslint-plugin-commander-option-flags","last_synced_at":"2026-04-28T04:37:58.153Z","repository":{"id":328314630,"uuid":"1115061531","full_name":"ysknsid25/eslint-plugin-commander-option-flags","owner":"ysknsid25","description":"ESLint plugin to enforce commander option flags style","archived":false,"fork":false,"pushed_at":"2025-12-12T10:56:08.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-28T04:37:52.570Z","etag":null,"topics":["2025","commander","eslint","eslint-plugin","eslintplugin","flags","style","works"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/eslint-plugin-commander-option-flags","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/ysknsid25.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"ysknsid25","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2025-12-12T09:33:07.000Z","updated_at":"2025-12-25T02:38:31.000Z","dependencies_parsed_at":"2025-12-13T22:04:32.081Z","dependency_job_id":null,"html_url":"https://github.com/ysknsid25/eslint-plugin-commander-option-flags","commit_stats":null,"previous_names":["ysknsid25/eslint-plugin-commander-option-flags"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ysknsid25/eslint-plugin-commander-option-flags","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysknsid25%2Feslint-plugin-commander-option-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysknsid25%2Feslint-plugin-commander-option-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysknsid25%2Feslint-plugin-commander-option-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysknsid25%2Feslint-plugin-commander-option-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysknsid25","download_url":"https://codeload.github.com/ysknsid25/eslint-plugin-commander-option-flags/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysknsid25%2Feslint-plugin-commander-option-flags/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32367021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["2025","commander","eslint","eslint-plugin","eslintplugin","flags","style","works"],"created_at":"2025-12-27T08:36:00.075Z","updated_at":"2026-04-28T04:37:58.145Z","avatar_url":"https://github.com/ysknsid25.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ysknsid25"],"categories":[],"sub_categories":[],"readme":"# eslint-plugin-commander-option-flags\n\nAn ESLint plugin to enforce standard style for [Commander.js](https://github.com/tj/commander.js) option flags.\n\n## Features\n\n- **Format Check**: Ensures flags are in the format `-[char], --[word]` (or just one of them).\n- **Internal Order**: Enforces short flags to come before long flags (e.g., `-p, --port` instead of `--port, -p`).\n- **Alphabetical Sorting**: Enforces chained `.option()` calls to be sorted alphabetically by flag name.\n\n## Installation\n\nYou'll first need to install [ESLint](https://eslint.org/):\n\n```bash\nnpm i eslint --save-dev\n```\n\nNext, install `eslint-plugin-commander-option-flags`:\n\n```bash\nnpm install eslint-plugin-commander-option-flags --save-dev\n```\n\n### Prerequisites\n\nThis project pins the Node.js and npm versions using [Volta](https://volta.sh/). It is highly recommended to install Volta to ensure you are using the correct versions automatically.\n\nOnce you have Volta installed, just `cd` into the project directory, and Volta will switch to the pinned Node.js version.\n\n## Usage\n\nAdd `commander-option-flags` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:\n\n```json\n{\n    \"plugins\": [\n        \"commander-option-flags\"\n    ],\n    \"rules\": {\n        \"commander-option-flags/commander-option-flags\": \"warn\"\n    }\n}\n```\n\n## Rule Details\n\n### Options\n\nThe rule accepts an optional object to configure the sorting order:\n\n*   `order`: `\"long\"` (default) or `\"short\"`. Determines whether to sort based on the long flag name or the short flag name.\n\n```json\n\"commander-option-flags/commander-option-flags\": [\"warn\", { \"order\": \"long\" }]\n```\n\n### Examples\n\n**👎 Incorrect**\n\n```javascript\nprogram\n  .option('--banana, -b') // Invalid order within string\n  .option('-a, --apple') // Not sorted relative to previous\n  .option('--port, -p \u003cnumber\u003e') // Long flag before short flag\n  .option('port \u003cnumber\u003e') // Missing hyphens\n  .option('-a, -b, --c') // Too many parts\n  .option('-x, -x') // Duplicate short flags\n  .option('--verbose, --verbose') // Duplicate long flags\n```\n\n**👍 Correct**\n\n```javascript\nprogram\n  .option('-a, --apple')\n  .option('-b, --banana')\n  .option('-p, --port \u003cnumber\u003e')\n  .option('-s', 'short only')\n  .option('--long', 'long only')\n```\n\n## Implementation Details\n\nThe core logic is located in `lib/rules/commander-option-flags.js`. Here is a high-level overview of how it works:\n\n1.  **AST Traversal**: The rule listens for `CallExpression` nodes to identify calls to `.option()`. It specifically checks if the callee is a `MemberExpression` with the property name `option`.\n2.  **Flag Parsing**: It extracts the first argument (the flags string, e.g., `\"-p, --port \u003cnumber\u003e\"`) and cleans it by removing argument placeholders (like `\u003cpath\u003e` or `[value]`). The remaining string is split to identify potential short (`-s`) and long (`--long`) flags.\n3.  **Validation Phases**:\n    *   **Format Check**: Verifies that the flags strictly match the `-[char]` or `--[word]` patterns and ensures no duplicates exist.\n    *   **Internal Order Check**: Checks if both short and long flags are present. If so, it verifies that the short flag appears *before* the long flag in the string.\n    *   **Sorting Check**: It inspects the *parent* object to find the preceding chained call. If the previous call was also an `.option()`, it compares their flag names alphabetically (based on the `order` configuration).\n4.  **Autofix Mechanism**:\n    *   **Internal Reordering**: Reconstructs the flag string with the short flag first, preserving any trailing arguments.\n    *   **Sorting**: Uses `fixer.replaceTextRange` to swap the entire code range of the current `.option(...)` call with the preceding one.\n\n## TypeScript Support\n\nThis plugin works with TypeScript files parsed by `@typescript-eslint/parser`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysknsid25%2Feslint-plugin-commander-option-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysknsid25%2Feslint-plugin-commander-option-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysknsid25%2Feslint-plugin-commander-option-flags/lists"}