-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add sort-import ESLint rule #317
Conversation
|
Yes but it needs to be separated by a blank line or a comment line. For example: import ConfigUtils from '../utils/ConfigUtils';
import Icon from '../components/Icon';
import LocaleUtils from '../utils/LocaleUtils';
import PropTypes from 'prop-types';
import React from 'react';
import SideBar from '../components/SideBar';
import Spinner from '../components/Spinner';
import classnames from 'classnames';
import isEmpty from 'lodash.isempty';
import {connect} from 'react-redux';
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
import './style/Bookmark.css'; or something like that (with absolute/relative and single/mulitple) import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import isEmpty from 'lodash.isempty';
import {connect} from 'react-redux';
import ConfigUtils from '../utils/ConfigUtils';
import Icon from '../components/Icon';
import LocaleUtils from '../utils/LocaleUtils';
import SideBar from '../components/SideBar';
import Spinner from '../components/Spinner';
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
import './style/Bookmark.css'; |
This should also work right? import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import isEmpty from 'lodash.isempty';
import {connect} from 'react-redux';
import ConfigUtils from '../utils/ConfigUtils';
import Icon from '../components/Icon';
import LocaleUtils from '../utils/LocaleUtils';
import SideBar from '../components/SideBar';
import Spinner from '../components/Spinner';
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
import './style/Bookmark.css'; |
No because named imports are also sorted with default imports (so We would have to create one block for each of these import types: // absolute single default imports
import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import isEmpty from 'lodash.isempty';
// absolute single named imports
import {connect} from 'react-redux';
// absolute multiple named imports
// relative single default imports
import ConfigUtils from '../utils/ConfigUtils';
import Icon from '../components/Icon';
import LocaleUtils from '../utils/LocaleUtils';
import SideBar from '../components/SideBar';
import Spinner from '../components/Spinner';
// relative single named imports
// relative multiple named imports
import {createBookmark, getUserBookmarks, removeBookmark, updateBookmark} from '../utils/PermaLinkUtils';
// styles
import './style/Bookmark.css'; |
Right. So the convention I've been using up to now was
I guess there is no rule to achieve this anyway, so boh dunno, no strong feelings except perhaps wanting to minimize the about of work to clean up all existing source files... But ultimately happy with whatever if we decide to add a rule for this. |
I think the last one in #317 (comment) could be a good one, I can do the changes in existing src files (in this same PR ?). We could also keep the comments for contributors to separate blocks. What do you think ? |
Yes ok for me! |
dc19a3d
to
561f79a
Compare
As it it really laborious to change existing source code to fix errors, I think we could introduce an ESLint plugin to be able to automatically fix errors. For instance, I have found this one: https://github.com/azat-io/eslint-plugin-perfectionist where we can just introduce sort-imports rule for now https://eslint-plugin-perfectionist.azat.io/rules/sort-imports, and we could add some other rules later. |
Makes sense - I guess this could then be configured as a pre-commit hook |
561f79a
to
af9ebf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
b4701d4
to
af9ebf0
Compare
a3eafa7
to
e7a3289
Compare
I have added the plugin with a rule and run ESLint with I think you have to run ESLint on |
Thanks - so this is good to merge now? |
Yes :-) |
Top, thanks! |
Hmm do you still get the eslint warnings in the code editor (i.e. vscodium)? |
Yes, I had to restart ESLint server |
Right, working now, thanks! |
@manisandro what do you think about this configuration ?
allowSeparatedGroups
could allow us to import style at the end of the imports.It sorts alphabetically Capital letters, then lowercase letters.
The member syntax sort order is
It does not take into account relative or absolute imports.
For example, imports of Bookmark plugin with this rule:
Thanks