Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce new rule to ensure generic type annotation position #21

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/rules/consistent-ref-type-annotation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: '@rotki/consistent-ref-type-annotation'
description: Ensures consistent type annotation position for ref, computed assignments
since: v0.4.0
---

# @rotki/consistent-ref-type-annotation

> Ensures consistent type annotation position for ref, computed assignments

- :star: The `"extends": "plugin:@rotki/recommended"` property in a configuration file enables this rule.
- :black_nib:️ The `--fix` option on the [command line](http://eslint.org/docs/user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule.

## :book: Rule Details

This rule reports inconsistent type annotation positioning for `ref` and `computed` properties.

<eslint-code-block fix>

<!-- eslint-skip -->

```vue
<script setup lang="ts">
import { ref, computed, Ref, ComputedRef } from 'vue'
/* eslint @rotki/consistent-ref-type-annotation: "error" */

type Balances = Record<string, number>;

<!-- ✓ GOOD -->
const text = ref<string>('');
const comp = computed<string>(() => '');

<!-- ✗ BAD -->
const secondText: Ref<string> = ref('');
const secondComp: ComputedRef<string> = computed(() => '');
const balances: Ref<Balances> = ref<Balances>({});
</script>
```

</eslint-code-block>

## :gear: Options

By default, a missing type annotation in a `ref` or `computed` is considered a problem.
If you want to allow type inference on `ref` or `computed` assignments you can set `allowInference` to `true`.

```json
{
"@rotki/consistent-ref-type-annotation": [
"error",
{
"allowInference": false
}
]
}
```

-

## :rocket: Version

This rule was introduced in `@rotki/eslint-plugin` v0.4.0

## :mag: Implementation

- [Rule source](https://github.com/rotki/eslint-plugin/blob/master/src/rules/consistent-ref-type-annotation.ts)
- [Test source](https://github.com/rotki/eslint-plugin/tree/master/tests/rules/consistent-ref-type-annotation.ts)
4 changes: 2 additions & 2 deletions docs/started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ e.g.
module.export = {
extends: [
'eslint:recommended',
'plugin:@rotki/recommended'
'plugin:@rotki/recommended',
],
}
};
```
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rotki/eslint-plugin",
"version": "0.3.2",
"packageManager": "pnpm@8.15.0",
"packageManager": "pnpm@9.4.0",
"type": "module",
"license": "AGPL-3.0",
"bugs": {
Expand Down Expand Up @@ -48,40 +48,40 @@
"eslint": "^8.0.0 || ^9.0.0"
},
"dependencies": {
"@typescript-eslint/utils": "6.19.1",
"debug": "4.3.4",
"eslint-compat-utils": "0.4.1",
"@typescript-eslint/utils": "7.15.0",
"debug": "4.3.5",
"eslint-compat-utils": "0.5.1",
"jsonc-eslint-parser": "2.4.0",
"scule": "1.2.0",
"vue-eslint-parser": "9.4.2",
"yaml-eslint-parser": "1.2.2"
"scule": "1.3.0",
"vue-eslint-parser": "9.4.3",
"yaml-eslint-parser": "1.2.3"
},
"devDependencies": {
"@commitlint/cli": "18.6.0",
"@commitlint/config-conventional": "18.6.0",
"@rotki/eslint-config": "2.4.4",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@rotki/eslint-config": "2.9.0",
"@types/debug": "4.1.12",
"@types/eslint": "8.56.2",
"@types/eslint": "8.56.10",
"@types/node": "20",
"@typescript-eslint/eslint-plugin": "6.19.1",
"@typescript-eslint/parser": "6.19.1",
"@typescript-eslint/rule-tester": "6.19.1",
"@vitest/coverage-v8": "^1.2.2",
"bumpp": "9.3.0",
"debug": "4.3.4",
"eslint": "8.56.0",
"husky": "9.0.7",
"lint-staged": "15.2.0",
"rimraf": "5.0.5",
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"@typescript-eslint/rule-tester": "7.15.0",
"@vitest/coverage-v8": "1.6.0",
"bumpp": "9.4.1",
"debug": "4.3.5",
"eslint": "8.57.0",
"husky": "9.0.11",
"lint-staged": "15.2.7",
"rimraf": "5.0.8",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"typescript": "5.5.3",
"unbuild": "2.0.0",
"vitepress": "1.0.0-rc.40",
"vitest": "1.2.2"
"vitepress": "1.2.3",
"vitest": "1.6.0"
},
"engines": {
"node": ">=20",
"pnpm": ">=8 <9"
"pnpm": ">=9 <10"
},
"lint-staged": {
"*.{js,cjs,ts,vue,yml,json,md}": "eslint"
Expand Down
Loading
Loading