Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleavely/eslint-plugin-ts-rules
Opinionated rules for maintainable Typescript projects
https://github.com/sleavely/eslint-plugin-ts-rules
code-quality eslint eslint-plugin static-analysis typescript
Last synced: about 2 months ago
JSON representation
Opinionated rules for maintainable Typescript projects
- Host: GitHub
- URL: https://github.com/sleavely/eslint-plugin-ts-rules
- Owner: Sleavely
- Created: 2023-09-29T09:44:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-01T08:36:21.000Z (over 1 year ago)
- Last Synced: 2024-11-11T17:50:14.805Z (about 2 months ago)
- Topics: code-quality, eslint, eslint-plugin, static-analysis, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@sleavely/eslint-plugin-ts-rules
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @sleavely/eslint-plugin-ts-rules
Opinionated rules for maintainable projects.
This plugin is a Typescript complement to the Javascript rules in [`@sleavely/eslint-plugin-js-rules`](https://github.com/Sleavely/eslint-plugin-js-rules).
## Installing
```sh
npm i --save-dev @sleavely/eslint-plugin-ts-rules
``````js
// .eslintrc.cjs
module.exports = {
// ..
plugins: [
'@sleavely/ts-rules',
],
rules: {
'@sleavely/ts-rules/prefer-inferred-const': ['error', 'always'],
}
}
```## Rules
### ts-rules/prefer-inferred-const
If [`no-inferrable-types`](https://typescript-eslint.io/rules/no-inferrable-types/) had a very strict parent, this rule would be it.
A `const` variable should generally never change, and even if it does it should be contained within the same type that it was originally inferred from.
```ts
// ⛔
const name: string = 'foo'
// ✅
const name = 'foo'// methods _should_ already define a return type or have an inferrable one
const getBurger = (): string => 'Big Mac'
// ⛔
const burger: string = getBurger()
// ✅
const burger = getBurger()// Sometimes you may want to assign a custom type such as an enum. Use this approach in those cases:
const name = 'foo' as MyCustomTypeThatIsntAPrimitiveconst name = 'foo' as const
```