{"id":15198381,"url":"https://github.com/arkovski/eslint-plugin-readonly-services","last_synced_at":"2026-02-21T14:32:03.637Z","repository":{"id":239206008,"uuid":"798856492","full_name":"Arkovski/eslint-plugin-readonly-services","owner":"Arkovski","description":"This ESLint plugin ensures that Angular services injected into TypeScript classes are declared as readonly. It helps maintain immutability by preventing reassignment of injected services, fostering better coding practices and enhancing stability in applications using dependency injection.","archived":false,"fork":false,"pushed_at":"2024-05-10T16:57:53.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T06:14:02.164Z","etag":null,"topics":["angular","eslint","eslint-plugin","plugin","readonly","rule"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arkovski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-05-10T16:06:13.000Z","updated_at":"2024-05-10T16:57:56.000Z","dependencies_parsed_at":"2024-05-10T18:01:49.758Z","dependency_job_id":null,"html_url":"https://github.com/Arkovski/eslint-plugin-readonly-services","commit_stats":null,"previous_names":["arkovski/eslint-plugin-readonly-services"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arkovski%2Feslint-plugin-readonly-services","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arkovski%2Feslint-plugin-readonly-services/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arkovski%2Feslint-plugin-readonly-services/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arkovski%2Feslint-plugin-readonly-services/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arkovski","download_url":"https://codeload.github.com/Arkovski/eslint-plugin-readonly-services/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241465113,"owners_count":19967243,"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":["angular","eslint","eslint-plugin","plugin","readonly","rule"],"created_at":"2024-09-28T01:04:29.859Z","updated_at":"2025-10-15T21:52:27.104Z","avatar_url":"https://github.com/Arkovski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eslint-plugin-readonly-services\n\nThis ESLint plugin ensures that services injected into TypeScript classes are declared as readonly. It helps maintain immutability by preventing reassignment of injected services, fostering better coding practices and enhancing stability in applications using dependency injection.\n\n**Purpose of the Plugin**: Ensures services are declared as readonly.  \n**Target**: TypeScript classes where services are injected.  \n**Benefit**: Maintains immutability and prevents reassignments, which leads to better coding practices and enhanced stability.  \n**Context**: Useful in applications that use dependency injection, which is a common pattern in frameworks like Angular.  \n\n## This plugin is published in the npmjs.org\n```sh\nnpm link eslint-plugin-readonly-services\nnpx eslint \"src/scripts/*.{js,ts}\"\n$env:ESLINT_PLUGIN_LOGGING=\"off\"; npx eslint \"src/scripts/*.{js,ts}\"    # if you want to disable logging. Enable by running this command with \"on\"\n```\n\n# Or if you want to customize this plugin, test, etc., follow the code below:\n## Installation\n\nYou'll first need to install [ESLint](https://eslint.org/):\n\n```sh\nnpm i eslint --save-dev\n```\n\nEnsure you have installed the necessary dependencies to support TypeScript in ESLint configurations:\n```sh\nnpm install @typescript-eslint/parser @typescript-eslint/eslint-plugin\n```\n\n\nNext, install `eslint-plugin-readonly-services`:\n\n```sh\nnpm install eslint-plugin-readonly-services --save-dev\n```\n\n## Usage\n\nAdd `readonly-services` **(without `eslint-plugin-`)** to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:\n\n```json\n{\n    \"plugins\": [\n        \"readonly-services\"\n    ]\n}\n```\n\n\nThen configure the rules you want to use under the rules section.\n\n```json\n{\n    \"rules\": {\n        \"readonly-services/rule-name\": 2\n    }\n}\n```\n\nExample ```.eslintrc.json``` code:\n\n```json\n{\n  \"parser\": \"@typescript-eslint/parser\",\n  \"parserOptions\": {\n    \"project\": \"./tsconfig.json\",\n    \"sourceType\": \"module\",\n    \"ecmaVersion\": 2022,\n    \"createDefaultProgram\": true\n  },\n  \"plugins\": [\n    \"eslint-plugin-readonly-services\"\n  ],\n  \"rules\": {\n    \"eslint-plugin-readonly-services/readonly-injected-services\": \"error\"\n  }\n}\n\n```\n\nExample ```.eslintrc.ts``` code:\n\n```ts\nmodule.exports = {\n    root: true,\n    extends: [\n        \"eslint:recommended\",\n    ],\n    parser: \"@typescript-eslint/parser\",\n    parserOptions: {\n        project: \"./tsconfig.eslint.json\",\n        tsconfigRootDir: __dirname,\n        sourceType: \"module\",\n        ecmaVersion: 2022,\n        createDefaultProgram: true\n    },\n    plugins: [\n        \"eslint-plugin-readonly-services\"\n    ],\n    rules: {\n        \"eslint-plugin-readonly-services/readonly-injected-services\": \"error\"\n    },\n};\n```\n\n## Run\nIn your angular root directory:\n```sh\nnpx eslint \"src/scripts/*.{js,ts}\"          # displays issues detected by ESLint. scr/scripts any other sub-directory with your JS/TS files\nnpx eslint \"src/scripts/*.{js,ts}\" --fix    # automatically changes the code\n\n# for PowerShell\n$env:ESLINT_PLUGIN_LOGGING=\"off\"; npx eslint \"src/scripts/*.{js,ts}\"  # to turn off logging\n$env:ESLINT_PLUGIN_LOGGING=\"on\"; npx eslint \"src/scripts/*.{js,ts}\"   # to bring back logging\n\n# for CMD\nset ESLINT_PLUGIN_LOGGING=off \u0026\u0026 npx eslint \"src/scripts/*.{js,ts}\"\nset ESLINT_PLUGIN_LOGGING=on \u0026\u0026 npx eslint \"src/scripts/*.{js,ts}\"\n````\n\n## Test code\n\nAngular project was created by:\n```sh\nnpm install -g @angular/cli\n```\n\nIn your terminal (CMD or powershell):\n\n\n```sh\ncd \u003cpath-to\u003e\\readonly_services_plugin\nnpm link eslint-plugin-readonly-service\n\nnpm list -g --depth=0\n```\n\n```sh\ncd \u003cpath-to\u003e\\readonly_services_plugin\\tests\\angular\\readonly-inject-test\nnpx eslint \"src/scripts/*.{js,ts}\"\n```\n\nEverything is fine if your output looks like:\n```sh\nC:\\Sources\\ESLintPlugins\\readonly_services_plugin\\tests\\angular\\readonly-inject-test\\src\\scripts\\test.component.ts\n1:1   error  Import and export declarations are not supported yet  node/no-unsupported-features/es-syntax\n1:27  error  \"@angular/core\" is not found                          node/no-missing-import\n2:1   error  Import and export declarations are not supported yet  node/no-unsupported-features/es-syntax\n2:29  error  \"./test.service\" is not found                         node/no-missing-import\n9:1   error  Import and export declarations are not supported yet  node/no-unsupported-features/es-syntax\n11:5   error  Parameter property can be made readonly               readonly-services/readonly-injected-services\n11:13  error  'testService' is defined but never used               no-unused-vars\n12:5   error  Parameter property can be made readonly               readonly-services/readonly-injected-services\n\nC:\\Sources\\ESLintPlugins\\readonly_services_plugin\\tests\\angular\\readonly-inject-test\\src\\scripts\\test.service.ts\n1:1   error  Import and export declarations are not supported yet  node/no-unsupported-features/es-syntax\n1:28  error  \"@angular/core\" is not found                          node/no-missing-import\n4:1   error  Import and export declarations are not supported yet  node/no-unsupported-features/es-syntax\n6:22  error  'readonlyService' is defined but never used           no-unused-vars\n7:5   error  Parameter property can be made readonly               readonly-services/readonly-injected-services\n7:13  error  'writableService' is defined but never used           no-unused-vars\n8:13  error  'reassignableService' is defined but never used       no-unused-vars\n```\n\nTo address the ```error  Parameter property can be made readonly               readonly-services/readonly-injected-services``` use `--fix` flag\n\n# Build your custom plugins:\nI used Yeoman file structure generator.\n\n```sh\nnpm install -g yo\nnpm install -g generator-eslint\n\nmkdir eslint-plugin-example\ncd eslint-plugin-example\n\nyo eslint:plugin  // or yo eslint:rule\n\nnpm link eslint-plugin-example // Locally installing your own stuff, so that you can work on it and test iteratively without having to continually rebuild.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkovski%2Feslint-plugin-readonly-services","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farkovski%2Feslint-plugin-readonly-services","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkovski%2Feslint-plugin-readonly-services/lists"}