Skip to content

Commit

Permalink
Eslint config: enable Flow Enums
Browse files Browse the repository at this point in the history
There is currently one issue with `no-undef` rule (see: gajus/eslint-plugin-flowtype#502)
but I think we can proceed with this and continue with the ecosystem
fixing.

See: https://flow.org/en/docs/enums/

adeira-source-id: 1898e8ac4f97e8c49ef2710a1639ddd0fda86bfc
  • Loading branch information
mrtnzlml authored and adeira-github-bot committed Sep 15, 2021
1 parent 3b2e77c commit c4d02cf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Unreleased

- set `jsx-a11y/accessible-emoji` rule to off, since it is deprecated and creates a degraded experience: [see](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/627)
- New rule [`fb-flow/use-flow-enums`](https://github.com/facebook/flow/blob/eb02b62805a196a05efff35ea6b73bd2f91f40fa/packages/eslint-plugin-fb-flow/README.md#use-flow-enums) enabled. Additionally, rules [`no-fallthrough`](https://eslint.org/docs/rules/no-fallthrough) and [`no-case-declarations`](https://eslint.org/docs/rules/no-case-declarations) were upgraded to errors in strict mode to improve Flow Enums support. For more information please visit: https://flow.org/en/docs/enums/
- New rules `@next/next/inline-script-id`, `@next/next/no-script-in-document` and `@next/next/no-script-in-head` enabled (as warnings). For more information visit: https://nextjs.org/docs/basic-features/eslint#eslint-plugin
- Disable `jsx-a11y/accessible-emoji` rule, since it is deprecated and creates [a degraded experience](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/627).
- We clarified what to do when you are using `@adeira/eslint-config/next` preset inside monorepo (check our readme). Basically, you might encounter the following warning:

```text
Expand Down
69 changes: 69 additions & 0 deletions __tests__/__fixtures__/valid-eslint-examples/flow/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// @flow strict

/* eslint-disable no-undef -- https://github.com/gajus/eslint-plugin-flowtype/issues/502 */

enum StatusDefault1 {
Active,
Paused,
Off,
}

enum StatusDefault2 of string {
Active,
Paused,
Off,
}

enum StatusString1 {
Active = 'active',
Paused = 'paused',
Off = 'off',
}

enum StatusString2 of string {
Active = 'active',
Paused = 'paused',
Off = 'off',
}

enum StatusNumber1 {
Active = 1,
Paused = 2,
Off = 3,
}

enum StatusNumber2 of number {
Active = 1,
Paused = 2,
Off = 3,
}

enum StatusBoolean1 {
Active = true,
Off = false,
}

enum StatusBoolean2 of boolean {
Active = true,
Off = false,
}

enum StatusSymbol of symbol {
Active,
Paused,
Off,
}

enum StatusUnknownMembers {
Active,
Paused,
Off,
...
}

export const a: StatusDefault1 = StatusDefault1.Active;
export const b: StatusString1 = StatusString1.Active;
export const c: StatusNumber1 = StatusNumber1.Active;
export const d: StatusBoolean2 = StatusBoolean2.Active;
export const e: StatusSymbol = StatusSymbol.Active;
export const f: StatusUnknownMembers = StatusUnknownMembers.Active;
16 changes: 14 additions & 2 deletions __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Object {
"fb-flow/flow-enums-default-if-possible": 1,
"fb-flow/no-flow-enums-object-mapping": 1,
"fb-flow/use-exact-by-default-object-type": 1,
"fb-flow/use-flow-enums": 0,
"fb-flow/use-flow-enums": 1,
"fb-flow/use-indexed-access-type": 0,
"flowtype/array-style-complex-type": 0,
"flowtype/array-style-simple-type": 0,
Expand Down Expand Up @@ -1077,10 +1077,12 @@ Snapshot Diff:
- "fb-flow/flow-enums-default-if-possible": 1,
- "fb-flow/no-flow-enums-object-mapping": 1,
- "fb-flow/use-exact-by-default-object-type": 1,
- "fb-flow/use-flow-enums": 1,
+ "fb-flow/flow-enums-default-if-possible": 2,
+ "fb-flow/no-flow-enums-object-mapping": 2,
+ "fb-flow/use-exact-by-default-object-type": 2,
"fb-flow/use-flow-enums": 0,
+ "fb-flow/use-flow-enums": 2,
"fb-flow/use-indexed-access-type": 0,
@@ --- --- @@
"import/no-nodejs-modules": 0,
- "import/no-relative-packages": 1,
Expand All @@ -1091,6 +1093,16 @@ Snapshot Diff:
- 1,
+ 2,
Object {
@@ --- --- @@
"no-caller": 2,
- "no-case-declarations": 1,
+ "no-case-declarations": 2,
"no-class-assign": 1,
@@ --- --- @@
"no-extra-semi": "off",
- "no-fallthrough": 1,
+ "no-fallthrough": 2,
"no-floating-decimal": "off",
@@ --- --- @@
"no-redeclare": Array [
- 1,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/presets.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ Object {
"fb-flow/flow-enums-default-if-possible": 1,
"fb-flow/no-flow-enums-object-mapping": 1,
"fb-flow/use-exact-by-default-object-type": 1,
"fb-flow/use-flow-enums": 0,
"fb-flow/use-flow-enums": 1,
"fb-flow/use-indexed-access-type": 0,
"flowtype/array-style-complex-type": 0,
"flowtype/array-style-simple-type": 0,
Expand Down
4 changes: 2 additions & 2 deletions src/presets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = ({
'no-alert': WARN,
'no-await-in-loop': WARN,
'no-caller': ERROR,
'no-case-declarations': WARN,
'no-case-declarations': NEXT_VERSION_ERROR,
'no-constructor-return': ERROR,
'no-div-regex': WARN,
'no-else-return': ERROR,
Expand All @@ -89,7 +89,7 @@ module.exports = ({
'no-extend-native': WARN,
'no-extra-bind': WARN,
'no-extra-label': ERROR,
'no-fallthrough': WARN,
'no-fallthrough': NEXT_VERSION_ERROR,
'no-global-assign': [ERROR, { exceptions: ['Map', 'Set'] }],
'no-implicit-coercion': [
ERROR,
Expand Down
2 changes: 1 addition & 1 deletion src/presets/flowtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = ({
'fb-flow/flow-enums-default-if-possible': NEXT_VERSION_ERROR,
'fb-flow/no-flow-enums-object-mapping': NEXT_VERSION_ERROR,
'fb-flow/use-exact-by-default-object-type': NEXT_VERSION_ERROR, // we are using `exact_by_default=true`
'fb-flow/use-flow-enums': OFF, // TODO: enable when Flow enums are fully supported
'fb-flow/use-flow-enums': NEXT_VERSION_ERROR,
'fb-flow/use-indexed-access-type': OFF, // TODO (revert https://github.com/adeira/universe/pull/2662)
},
} /*: EslintConfig */);

0 comments on commit c4d02cf

Please sign in to comment.