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

Conversation

arnostpleskot
Copy link
Contributor

Added eslint-plugin-flowtype and related rules.

@robertrossmann
Copy link
Member

Thanks for this! I have some suggestions/requests to amend the current structure of the new ruleset.

There are quite several coding-style specific rules which deal with how the code looks like, instead of how it works. I would like to move all such rules to a new coding-styles/flow ruleset (just like we have for react).

I will go through the existing rules and see if I am okay with their current configuration. In the meantime, feel free to start moving the rules out.

Thank you!

Copy link
Member

@robertrossmann robertrossmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left lots of comments with requests to change some rules' configurations and placement.

'flowtype/boolean-style': ['warn', 'boolean'],

// Disallows use of primitive constructors as types, such as Boolean, Number and String.
'flowtype/no-primitive-constructor-types': 'warn',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to error. The primitive constructors are almost never used, only when type-casting, ie.

const bool = Boolean('I am Groot') // true
const num = Number('42') // 42 instead of "42"
// etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, move from optional to recommended.


// Enforces sorting of Object annotations.
// This rule mirrors ESlint's sort-keys rule.
'flowtype/sort-keys': 'warn',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably too restrictive even for a coding-style ruleset. Please move to unused.js and set to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because after all changes environments/flow/optional.js contains only this rule and flowtype/type-id-match I would left them as optional part of ruleset.

'flowtype/sort-keys': 'warn',

// Enforces a consistent naming pattern for type aliases.
'flowtype/type-id-match': ['warn', '^([A-Z][a-z0-9]*)+Type$'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks too restrictive, having Type suffix in all type defs feels ugly. For now, let's move this to unused.js, we can re-visit later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because after all changes environments/flow/optional.js contains only this rule and flowtype/sort-keys I would left them as optional part of ruleset.

/**
* Js-coding-standards
*
* @author Robert Rossmann <rr.rossmann@me.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, change to Arnost Pleskot? 😄

* Js-coding-standards
*
* @author Robert Rossmann <rr.rossmann@me.com>
* @copyright 2016 STRV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2017

'flowtype/space-after-type-colon': ['error', 'always'],

// Enforces consistent spacing before the opening < of generic type annotation parameters.
'flowtype/space-before-generic-bracket': ['error', 'always'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coding-style -> warn

Also I think the space before generic annotation is rarely used in other languages, so please switch to never.

'flowtype/space-before-generic-bracket': ['error', 'always'],

// Enforces consistent spacing before the type annotation colon.
'flowtype/space-before-type-colon': ['error', 'never'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding-style -> warn

'flowtype/space-before-type-colon': ['error', 'never'],

// Enforces consistent spacing around union and intersection type separators (` | ` and ` & `).
'flowtype/union-intersection-spacing': ['error', 'always'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding-style -> warn


rules: {
// Enforces a particular style for boolean type annotations.
'flowtype/boolean-style': ['warn', 'boolean'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a recommended rule with these settings. Consistency is of great importance.


// Warns against weak type annotations any, Object and Function. These types can cause flow
// to silently skip over portions of your code, which would have otherwise caused type errors.
'flowtype/no-weak-types': ['warn', { any: true }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to recommended with these settings.

@robertrossmann
Copy link
Member

Merged, awesome - thanks! 🎉 🍻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants