{"id":24773050,"url":"https://github.com/re-quant/eslint-plugin-z-brain","last_synced_at":"2025-03-23T21:14:46.177Z","repository":{"id":57170171,"uuid":"429003755","full_name":"Re-Quant/eslint-plugin-z-brain","owner":"Re-Quant","description":"Custom ESLint rules that are being used in Z-Brain projects. Some of them are project-specific, some are helpful anywhere.","archived":false,"fork":false,"pushed_at":"2021-11-17T17:38:52.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T07:04:56.524Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Re-Quant.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}},"created_at":"2021-11-17T10:37:14.000Z","updated_at":"2021-11-17T17:38:55.000Z","dependencies_parsed_at":"2022-08-27T13:11:34.833Z","dependency_job_id":null,"html_url":"https://github.com/Re-Quant/eslint-plugin-z-brain","commit_stats":null,"previous_names":["re-quant/eslint-plugin-z-brain","z-brain/eslint-plugin-z-brain"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Feslint-plugin-z-brain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Feslint-plugin-z-brain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Feslint-plugin-z-brain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Feslint-plugin-z-brain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Re-Quant","download_url":"https://codeload.github.com/Re-Quant/eslint-plugin-z-brain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245168904,"owners_count":20571804,"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":"2025-01-29T04:35:39.853Z","updated_at":"2025-03-23T21:14:46.154Z","avatar_url":"https://github.com/Re-Quant.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Z-Brain ESLint Rules\n\n\u003cp\u003e\n  \u003ca target=\"_blank\" href=\"https://github.com/z-brain/eslint-plugin-z-brain/actions?query=workflow%3A%22Build%22\"\u003e\n    \u003cimg alt=\"Build status\" src=\"https://github.com/z-brain/eslint-plugin-z-brain/workflows/Build/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://www.npmjs.com/package/@z-brain/eslint-plugin-z-brain\"\u003e\n    \u003cimg alt=\"NPM version\" src=\"https://img.shields.io/npm/v/@z-brain/eslint-plugin-z-brain.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://codecov.io/gh/z-brain/eslint-plugin-z-brain\"\u003e\n    \u003cimg alt=\"Code Coverage\" src=\"https://codecov.io/gh/z-brain/eslint-plugin-z-brain/branch/main/graph/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://www.gnu.org/licenses/gpl-3.0\"\u003e\n    \u003cimg alt=\"License: GPL v3\" src=\"https://img.shields.io/badge/License-GPLv3-blue.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nCustom ESLint (TypeScript) rules that are being used in Z-Brain projects. Some of them are project-specific, some are helpful anywhere.\n\n*Notice: If you have any propositions feel free to make an issue or create a pull request.*\n\n## How to use\n\n### Installing\n\n`yarn add @z-brain/eslint-plugin-z-brain`  \nor  \n`npm i -s @z-brain/eslint-plugin-z-brain`\n\n### Adding to `.eslintrc`\n\nThe plugin import and adding the recommended rule set.\n\n```ts\nmodule.exports = {\n    env: {\n        es6: true,\n    },\n    extends: [\"plugin:@z-brain/z-brain/recommended\"],\n    parser: \"@typescript-eslint/parser\",\n    parserOptions: {\n        project: [\"./tsconfig.json\"],\n        sourceType: \"module\",\n        ecmaVersion: \"es2019\",\n    },\n    plugins: [\"@z-brain/z-brain\"],\n};\n```\n\n**Configuring specific rules:**\n\n```js\nmodule.exports = {\n  rules: {\n    '@z-brain/z-brain/empty-array-check-with-absent-length': 'warn',\n  },\n};\n```\n\n## Rules\n\n### `empty-array-check-with-absent-length`\n\n#### Short description:\n\nProtects against forgotten '.length' when checking an array for emptiness\n\n#### Detailed description:\n\nThe condition result being never changed according to current typings.\nAdd `.length` or if you're writing a check for a falsy-value please add an appropriate type to the array definition.\n\n#### Examples\n\nSee all cases \u0026 examples in the [unit tests](./src/rules/empty-array-check-with-absent-length.rule.spec.ts).\n\n```ts\nfunction foo(ids: number[]) {\n  if (ids.length) return; // GOOD\n  if (ids) return;        // BAD\n}\n```\n\n```ts\n// GOOD\nfunction foo(ids: number[] | null | undefined) {\n  if (ids) return;\n}\nfunction foo(ids: number[] | boolean) {\n  if (ids) return;\n}\nfunction foo(ids?: number[]) {\n  if (ids) return;\n}\n\n// BAD\nfunction foo(ids: number[]) {\n  if (ids) return; // in accordance with typings 'ids' is always trusty-value \n}\n```\n\n## Helpful links\n\n- [AST explorer](https://astexplorer.net/)\n\n#### Articles\n- [Simplest rule: Create a custom eslint rule with typescript](https://dev.to/bwca/create-a-custom-eslint-rule-with-typescript-4j3d)\n- [More details: How I learned to love the AST](https://dev.to/alexgomesdev/writing-custom-typescript-eslint-rules-how-i-learned-to-love-the-ast-15pn)\n- [The most complex article: How to write an ESLint plugin in TypeScript](https://dev.to/darraghor/how-to-write-an-eslint-plugin-in-typescript-3k5a)\n\n#### Documentation \u0026 repos\n- [Awesome official guide @typescript-eslint/experimental-utils · GitHub](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/development/CUSTOM_RULES.md#writing-rules-in-typescript)\n- [Lots of good \u0026 simple examples: eslint-plugin-nestjs-typed package - GitHub](https://github.com/darraghoriordan/eslint-plugin-nestjs-typed)\n- [Official ESLint custom rules guide](https://eslint.org/docs/developer-guide/working-with-rules)\n- [Description of all packages in @typescript-eslint · GitHub](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/development/architecture/PACKAGES.md)\n- [Using the Compiler API · microsoft/TypeScript Wiki · GitHub](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#using-the-type-checker)\n- [More about type checking via TS Compiler API](https://learning-notes.mistermicheels.com/javascript/typescript/compiler-api/#getting-type-information)\n\n## Development notes\n\n### Quick Start\n\n```bash\ncd /Users/volumes/code/z-brain\ngit clone git@github.com:z-brain/eslint-plugin-z-brain.git\ncd eslint-plugin-z-brain\nyarn install\n```\n\n### How to use NodeJS version from the `.nvmrc`\n\n1. Install NVM\n2. Use `.nvmrc` file one of the next ways:\n\n    * Execute `nvm use` in the project root directory\n    * Install [NVM Loader](https://github.com/korniychuk/ankor-shell) and your .nvmrc will be loaded automatically when you open the terminal.\n      ![NVM Loader demo](./resources/readme.nvm-loader.png)\n\n### How to make a build\n\n`yarn run build`\n\n### How to run lint\n\nNotice: _linter isn't configured yet_\n\n* Just show problems `yarn run lint`\n* Fix problems if it is possible `yarn run lint:fix`\n\n### How to run tests\n\n* All tests\n\n  `yarn run test`  \n  `yarn run test:watch`\n* Specific tests\n\n  `yarn run test src/my.spec.ts`  \n  `yarn run test:watch src/my.spec.ts`\n\n### How to build and publish NPM package\n\n*NPM Token:* `npm_UVqN......qTww`\n\nCI configuration details here: [.github/workflows/npmpublish.yml](.github/workflows/npmpublish.yml)\n\n```bash\nyarn run ci \\\n\u0026\u0026 npm version patch -m 'Update package version version to %s' \\\n\u0026\u0026 npm publish --access public \\\n\u0026\u0026 git push --no-verify \u0026\u0026 git push --tags --no-verify\n```\n\n### How to build package to local installation\n\n1. `yarn run build`\n2. Then you can install a local package build from the root repo dir (not `dist`) path `file:.../eslint-plugin-z-brain`.\n\n## Author\n\n| [\u003cimg src=\"https://www.korniychuk.pro/avatar.jpg\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003eAnton Korniychuk\u003c/sub\u003e](https://korniychuk.pro) |\n| :---: |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-quant%2Feslint-plugin-z-brain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fre-quant%2Feslint-plugin-z-brain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-quant%2Feslint-plugin-z-brain/lists"}