Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.

Commit 9b7117e

Browse files
arnostpleskotrobertrossmann
authored andcommitted
Flow ruleset
1 parent 57b0ed0 commit 9b7117e

File tree

8 files changed

+138
-2
lines changed

8 files changed

+138
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ node_modules
1919
*#
2020
.DS_STORE
2121
.netbeans
22+
.vscode
2223
nbproject
2324
.idea
2425
.node_history

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ See the [tutorial](tutorial) directory for lots of example config files.
4646
- @strv/javascript/environments/react/optional
4747
- @strv/javascript/environments/react/accessibility
4848

49+
> These are rules for [Flow][flow-home] type checker.
50+
- @strv/javascript/environments/flow/recommended
51+
4952
> This one includes rules which deal with how the code looks like and not how it works. It helps keep the code clean and consistent.
5053
5154
- @strv/javascript/coding-styles/recommended
@@ -54,6 +57,10 @@ See the [tutorial](tutorial) directory for lots of example config files.
5457
5558
- @strv/javascript/coding-styles/fixable
5659

60+
> This one contains coding style rules for Flow
61+
62+
- @strv/javascript/coding-styles/flow
63+
5764
## License
5865

5966
This software is licensed under the **BSD-3-Clause License**. See the [LICENSE](LICENSE) file for more information.
@@ -64,3 +71,4 @@ This software is licensed under the **BSD-3-Clause License**. See the [LICENSE](
6471
[travis-url]: https://travis-ci.org/strvcom/eslint-config-javascript
6572
[eslint-version]: https://img.shields.io/badge/ESLint->=4.5.0-brightgreen.svg
6673
[eslint-fixing]: http://eslint.org/docs/user-guide/command-line-interface#fix
74+
[flow-home]: https://flow.org

coding-styles/flow.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Js-coding-standards
3+
*
4+
* @author Arnost Pleskot <[email protected]>
5+
* @copyright 2017 STRV
6+
* @license http://choosealicense.com/licenses/bsd-3-clause BSD-3-Clause License
7+
*/
8+
9+
'use strict'
10+
11+
module.exports = {
12+
plugins: [
13+
'flowtype',
14+
],
15+
16+
rules: {
17+
// Enforces a particular style for boolean type annotations.
18+
'flowtype/boolean-style': ['warn', 'boolean'],
19+
20+
// Enforces consistent spacing within generic type annotation parameters.
21+
'flowtype/generic-spacing': ['warn', 'never'],
22+
23+
// Enforces consistent separators between properties in Flow object types.
24+
'flowtype/object-type-delimiter': ['warn', 'comma'],
25+
26+
// Enforces consistent use of trailing commas in Object and Tuple annotations.
27+
// This rule takes one argument which mirrors ESLint's default comma-dangle rule.
28+
'flowtype/delimiter-dangle': ['warn', 'always-multiline'],
29+
30+
// Enforces consistent use of semicolons after type aliases.
31+
'flowtype/semi': ['warn', 'never'],
32+
33+
// Enforces consistent spacing after the type annotation colon.
34+
'flowtype/space-after-type-colon': ['warn', 'always'],
35+
36+
// Enforces consistent spacing before the opening < of generic type annotation parameters.
37+
'flowtype/space-before-generic-bracket': ['warn', 'never'],
38+
39+
// Enforces consistent spacing before the type annotation colon.
40+
'flowtype/space-before-type-colon': ['warn', 'never'],
41+
42+
// Enforces consistent spacing around union and intersection type separators (` | ` and ` & `).
43+
'flowtype/union-intersection-spacing': ['warn', 'always'],
44+
},
45+
}

environments/flow/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Flow
2+
3+
These configuration files are suitable to lint Flow type annotations.
4+
5+
## Configurations
6+
7+
### @strv/javascript/environments/flow/recommended
8+
9+
Basic ruleset for Flow. Main focus is on consistent way to write type annotations.
10+
11+
### In combination with React
12+
13+
If you are using Flow with React to [validate props](https://flow.org/en/docs/react/components/#toc-class-components) consider adding this rule to your `.eslintrc.js` config:
14+
15+
```js
16+
// Enforces sorting of Object annotations.
17+
// This rule mirrors ESlint's sort-keys rule.
18+
'flowtype/sort-keys': ['warn', 'asc', { caseSensitive: false }]
19+
```

environments/flow/recommended.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Js-coding-standards
3+
*
4+
* @author Arnost Pleskot <[email protected]>
5+
* @copyright 2017 STRV
6+
* @license http://choosealicense.com/licenses/bsd-3-clause BSD-3-Clause License
7+
*/
8+
9+
'use strict'
10+
11+
module.exports = {
12+
plugins: [
13+
'flowtype',
14+
],
15+
16+
rules: {
17+
// Marks Flow type identifiers as defined.
18+
// Used to suppress no-undef reporting of type identifiers.
19+
'flowtype/define-flow-type': 'warn',
20+
21+
// Checks for duplicate properties in Object annotations.
22+
'flowtype/no-dupe-keys': 'error',
23+
24+
// Disallows use of primitive constructors as types, such as Boolean, Number and String.
25+
'flowtype/no-primitive-constructor-types': 'error',
26+
27+
// Disallows Flow type imports, exports, aliases, and annotations in files missing a valid
28+
// Flow file declaration (or a @noflow annotation).
29+
'flowtype/no-types-missing-file-annotation': 'error',
30+
31+
// Warns against weak type annotations any, Object and Function. These types can cause flow
32+
// to silently skip over portions of your code, which would have otherwise caused type errors.
33+
'flowtype/no-weak-types': ['warn', { any: true }],
34+
35+
// Requires that all function parameters have type annotations.
36+
'flowtype/require-parameter-type': 'error',
37+
38+
// Requires that functions have return type annotation.
39+
'flowtype/require-return-type': ['error', 'always'],
40+
41+
// Requires that all variable declarators have type annotations.
42+
'flowtype/require-variable-type': 'error',
43+
44+
// Marks Flow type alias declarations as used.
45+
// Used to suppress no-unused-vars errors that are triggered by type aliases.
46+
'flowtype/use-flow-type': 'warn',
47+
},
48+
}

package-lock.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"contributors": [],
1010
"dependencies": {
11+
"eslint-plugin-flowtype": "^2.35.0",
1112
"eslint-plugin-import": "^2.7.0",
1213
"eslint-plugin-jsx-a11y": "^6.0.2",
1314
"eslint-plugin-react": "^7.3.0"

unused.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,12 @@ module.exports = {
168168

169169
// Enforce React components to have a shouldComponentUpdate method
170170
'react/require-optimization': 0,
171+
172+
// Enforces sorting of Object annotations.
173+
// This rule mirrors ESlint's sort-keys rule.
174+
'flowtype/sort-keys': 0,
175+
176+
// Enforces a consistent naming pattern for type aliases.
177+
'flowtype/type-id-match': 0,
171178
},
172179
}

0 commit comments

Comments
 (0)