gajus / gajus/eslint-plugin-flowtype
Request: replacement for no-restricted-globals
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
I'm using eslint-config-airbnb, which has `no-restricted-globals` set to disallow certain easily confusable globals, based on the [eslint-restricted-globals](https://github.com/sidoshi/eslint-restricted-globals) list.
But sometimes you want to use these globals in types, e.g. to reuse the type of `window.history` (defined [here]((https://github.com/facebook/flow/blob/0b2dc1627d18d9b1b8d771a54b76b28820a0b691/lib/bom.js#L300)) when creating a customised `history` for use with react-router:
```jsx
type History = typeof history;
const createCustomHistory = (): History => {
// ...create and return a custom history object
}
```
The ESLint config asks you to change it to `type History = typeof window.history`. But that doesn't work for Flow – the resulting type is `any`, as [Flow's type for `window` is is `any`](https://github.com/facebook/flow/blob/0b2dc1627d18d9b1b8d771a54b76b28820a0b691/lib/bom.js#L36). Same goes for `typeof global.history`.
I think it would be useful for eslint-plugin-flowtype to add a new rule, `flowtype/no-restricted-globals`, which would allow using restricted globals in type annotations.
Contributor guide
Research direction
Start with the requested flowtype/no-restricted-globals rule and compare its goal with ESLint's no-restricted-globals behavior. Review the linked Flow lib/bom.js definitions for history, window, and global, then determine how the rule should distinguish Flow type annotations from other uses. Done means the example type annotation is accepted without removing the restriction in other contexts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100