Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Eslint 7 & add rules #15

Merged
merged 35 commits into from
Oct 8, 2020
Merged

Support Eslint 7 & add rules #15

merged 35 commits into from
Oct 8, 2020

Conversation

moroine
Copy link
Contributor

@moroine moroine commented May 19, 2020

This PR is WIP, plugins not supporting yet eslint 7:

I've also added lot of rules, idk if they're all needed or if they will lead to too much changes! I haven't tried them yet, let's review them together here.

Related PR:

@moroine moroine requested a review from limtingzhi May 19, 2020 07:25
@moroine moroine changed the base branch from master to develop May 19, 2020 07:25
rules/flow.js Outdated
'flowtype/no-mixed': 'off',
'flowtype/no-dupe-keys': 'error',
// TODO: enable?
'flowtype/no-existential-type': 'off',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think can be enabled since * is deprecated. But I guess we would have to change * to any.

'flowtype/no-flow-fix-me-comments': 'off',
'flowtype/no-mixed': 'off',
// TODO: enable?
'flowtype/no-mutable-array': 'off',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it forces us to only use $ReadOnlyArray and totally disallow [] or Array though. Because in our codebase, I remember we do mutate some stuff for performance purposes.

https://github.com/gajus/eslint-plugin-flowtype/blob/master/.README/rules/no-mutable-array.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have this

Note that initialization of a variable with an empty array is considered valid (e.g., const values: Array = [];). This behavior resembles the behavior of Flow's unsealed objects, as it is assumed that empty array is intended to be mutated.

And also we will still be able to do perf optimisations using // eslint-disable-next-line it will emphasis the alert on the mutation

'flowtype/no-primitive-constructor-types': 'error',
'flowtype/no-types-missing-file-annotation': 'error',
'flowtype/no-unused-expressions': 'error',
// TODO: disable any?
Copy link
Collaborator

Choose a reason for hiding this comment

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

flowtype/no-weak-types: I think we can keep any for now, else they might be too many changes.

rules/flow.js Outdated
'flowtype/require-return-type': 'off',
'flowtype/require-types-at-top': 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might lead to quite a number of changes, need to test it out. Some of our files have this kind of pattern, which we could either move to different files else the types would be difficult to see.

Type A
Function A
Type B
Function B

https://github.com/gajus/eslint-plugin-flowtype/blob/master/.README/rules/require-types-at-top.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, would lead to lot of changes but this has autofix I think

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think so too. But some files might need to reorganise, should be a few I guess.

'flowtype/space-after-type-colon': ['error', 'always'],
'flowtype/space-before-generic-bracket': ['error', 'never'],
'flowtype/space-before-type-colon': ['error', 'never'],
// TODO: enable?
'flowtype/spread-exact-type': 'off',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's because spreading non-exact type is not safe and not properly supported by flow

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be possible to enable 🤔

rules/flow.js Outdated
'flowtype/type-id-match': 'off',
// Use identifier as declaration imports are not well supported by vscode
'flowtype/type-import-style': ['error', 'identifier'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer this to be off. As at times, there is not a need to have identifier style when importing types from a type file. Less verbose too.

https://github.com/gajus/eslint-plugin-flowtype/blob/master/.README/rules/type-import-style.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about forcing declaration style? It might help separating type from non type 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, we can force declaration style. Would prefer that to identifier style if you want to enforce one of them.

rules/imports.js Outdated
Comment on lines 156 to 159
'alphabetize': {
'order': 'asc',
'caseInsensitive': true,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️ 😂 🙏 . Though I'm not sure how it will work out with aliasing 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's see 😄

@@ -195,33 +204,32 @@ module.exports = {
// Prevent unassigned imports
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
// importing for side effects is perfectly acceptable, if you need side effects.
'import/no-unassigned-import': 'off',
'import/no-unassigned-import': 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure will it affect index files that just imports and do nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will have to use eslint-disable but these files are bad because using side-effects. Best is to remove them as much as we can

Comment on lines +226 to +232
'import/exports-last': 'error',

// Reports when named exports are not grouped together in a single export declaration
// or when multiple assignments to CommonJS module.exports or exports object are present
// in a single file.
// https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
'import/group-exports': 'off',
'import/group-exports': 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it when these two rules import/exports-last and import/group-exports are enabled together, we wouldn't have that much changes in terms of lines movement in our files?

Cause I'm not sure about import/exports-last as we do have this kind of patterns which will be flagged. And I guess is okay to have exports in the middle as sometimes we only export what we need to.

const bool = true
export default bool
const str = 'foo'

https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md#this-will-be-reported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but it's easier when navigating. If you need to add export a function then it will be grouped in last statement like

const a = ...
 function b() {}

export { a, b };

rules/react.js Outdated
Comment on lines 56 to 61
// Enforce a specific function type for function components.
// https://github.com/yannickcr/eslint-plugin-react/blob/v7.20.0/docs/rules/function-component-definition.md
'react/function-component-definition': ['error', {
namedComponents: 'function-declaration',
unnamedComponents: 'function-declaration',
}],
Copy link
Collaborator

@limtingzhi limtingzhi Jun 2, 2020

Choose a reason for hiding this comment

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

I'm not sure about this. I prefer to write this way inside a function component, and this would probably prevent it 🤔

var Component = (props) => {
  return <div />;
};

Also, unnamedComponents should be function-expression instead. There is no function-declaration for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmms, true 🤔 But means inside class, we would also have to not use arrows then. We can try it out and see how many changes etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's just on functions, class arrow functions will be good

@@ -494,7 +499,7 @@ module.exports = {

// Enforce that props are read-only
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-read-only-props.md
'react/prefer-read-only-props': 'off',
'react/prefer-read-only-props': 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might lead to a lot of changes but I think is most likely simple fixes. Not sure if it would be too verbose though. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll enable them one-by-one to have separated commits

@limtingzhi
Copy link
Collaborator

limtingzhi commented Jun 2, 2020

@moroine I guess we probably need to test them out to further understand what will be the changes needed. I commented on the ones that I think might have issues with.

If eslint-plugin-ramda is not really actively supported, we can drop it for now. But it seems like it is working with ESLint 7: ramda/eslint-plugin-ramda#28

@moroine
Copy link
Contributor Author

moroine commented Jun 12, 2020

@moroine I guess we probably need to test them out to further understand what will be the changes needed. I commented on the ones that I think might have issues with.

@limtingzhi I agree, I'll tests theses changes one-by-one in order to test them out

If eslint-plugin-ramda is not really actively supported, we can drop it for now. But it seems like it is working with ESLint 7: ramda/eslint-plugin-ramda#28

Yeah I think we can remove them

@moroine moroine changed the title [WIP] Support Eslint 7 & add rules Support Eslint 7 & add rules Oct 1, 2020
@@ -3,32 +3,34 @@
## Changes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing breaking changes eslint to ^7.10.0.

CHANGELOG.md Outdated
- **[Breaking]**: minimum supported NodeJs version 12.18
- upgrade `babel-eslint` to `^10.1.0`
- upgrade `eslint-plugin-eslint-comments` to `^3.2.0`
- upgrade `eslint-plugin-import` to `^2.22.0`
Copy link
Collaborator

Choose a reason for hiding this comment

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

eslint-plugin-import is suppose to be ^2.22.1 and not ^2.22.0.

CHANGELOG.md Outdated
- upgrade `eslint-plugin-import` to `^2.22.0`
- upgrade `eslint-plugin-jsx-a11y` to `^6.3.1`
- upgrade `eslint-plugin-react` to `^7.21.2`
- upgrade `eslint-plugin-react-hooks` to `^4.1.2`
Copy link
Collaborator

Choose a reason for hiding this comment

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

eslint-plugin-react-hooks is written above as breaking changes. Could you remove this one and update the breaking changes to ^4.1.2?

rules/imports.js Outdated
@@ -146,8 +145,18 @@ module.exports = {
// TODO: enforce a stricter convention in module import order?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to remove this TODO?

@moroine moroine merged commit 351a8ef into develop Oct 8, 2020
@moroine moroine deleted the improvment/eslint-7 branch October 8, 2020 05:41
@limtingzhi limtingzhi mentioned this pull request Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants