Skip to content

Commit

Permalink
Enforce import order with ESLint (#25096)
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap committed May 23, 2023
1 parent b896b16 commit d27216d
Show file tree
Hide file tree
Showing 355 changed files with 2,207 additions and 1,269 deletions.
98 changes: 49 additions & 49 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,55 @@ module.exports = {
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',

'import/order': [
'error',
{
alphabetize: { order: 'asc' },
'newlines-between': 'always',
groups: [
'builtin',
'external',
'internal',
'parent',
['index', 'sibling'],
'object',
],
pathGroups: [
// React core packages
{
pattern: '{react,react-dom,react-dom/client,prop-types}',
group: 'builtin',
position: 'after',
},
// I18n
{
pattern: '{react-intl,intl-messageformat}',
group: 'builtin',
position: 'after',
},
// Common React utilities
{
pattern: '{classnames,react-helmet,react-router-dom}',
group: 'external',
position: 'before',
},
// Immutable / Redux / data store
{
pattern: '{immutable,react-redux,react-immutable-proptypes,react-immutable-pure-component,reselect}',
group: 'external',
position: 'before',
},
// Internal packages
{
pattern: '{mastodon/**}',
group: 'internal',
position: 'after',
},
],
pathGroupsExcludedImportTypes: [],
},
],

'promise/always-return': 'off',
'promise/catch-or-return': [
'error',
Expand Down Expand Up @@ -286,55 +335,6 @@ module.exports = {
rules: {
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],

'import/order': [
'error',
{
alphabetize: { order: 'asc' },
'newlines-between': 'always',
groups: [
'builtin',
'external',
'internal',
'parent',
['index', 'sibling'],
'object',
],
pathGroups: [
// React core packages
{
pattern: '{react,react-dom,prop-types}',
group: 'builtin',
position: 'after',
},
// I18n
{
pattern: 'react-intl',
group: 'builtin',
position: 'after',
},
// Common React utilities
{
pattern: '{classnames,react-helmet}',
group: 'external',
position: 'before',
},
// Immutable / Redux / data store
{
pattern: '{immutable,react-redux,react-immutable-proptypes,react-immutable-pure-component,reselect}',
group: 'external',
position: 'before',
},
// Internal packages
{
pattern: '{mastodon/**}',
group: 'internal',
position: 'after',
},
],
pathGroupsExcludedImportTypes: [],
},
],

'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import { importFetchedAccount, importFetchedAccounts } from './importer';

export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/announcements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { normalizeAnnouncement } from './importer/normalizer';

export const ANNOUNCEMENTS_FETCH_REQUEST = 'ANNOUNCEMENTS_FETCH_REQUEST';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/blocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import { fetchRelationships } from './accounts';
import { importFetchedAccounts } from './importer';
import { openModal } from './modal';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/bookmarks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import { importFetchedStatuses } from './importer';

export const BOOKMARKED_STATUSES_FETCH_REQUEST = 'BOOKMARKED_STATUSES_FETCH_REQUEST';
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/mastodon/actions/compose.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { defineMessages } from 'react-intl';

import axios from 'axios';
import { throttle } from 'lodash';
import { defineMessages } from 'react-intl';

import api from 'mastodon/api';
import { search as emojiSearch } from 'mastodon/features/emoji/emoji_mart_search_light';
import { tagHistory } from 'mastodon/settings';

import { showAlert, showAlertForError } from './alerts';
import { useEmoji } from './emojis';
import { importFetchedAccounts, importFetchedStatus } from './importer';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/conversations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import {
importFetchedAccounts,
importFetchedStatuses,
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/directory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import api from '../api';
import { importFetchedAccounts } from './importer';

import { fetchRelationships } from './accounts';
import { importFetchedAccounts } from './importer';

export const DIRECTORY_FETCH_REQUEST = 'DIRECTORY_FETCH_REQUEST';
export const DIRECTORY_FETCH_SUCCESS = 'DIRECTORY_FETCH_SUCCESS';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/favourites.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import { importFetchedStatuses } from './importer';

export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { openModal } from './modal';

export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/history.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { importFetchedAccounts } from './importer';

export const HISTORY_FETCH_REQUEST = 'HISTORY_FETCH_REQUEST';
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/importer/normalizer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import escapeTextContentForBrowser from 'escape-html';

import emojify from '../../features/emoji/emoji';
import { unescapeHTML } from '../../utils/html';
import { expandSpoilers } from '../../initial_state';
import { unescapeHTML } from '../../utils/html';

const domParser = new DOMParser();

Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/interactions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { importFetchedAccounts, importFetchedStatus } from './importer';

export const REBLOG_REQUEST = 'REBLOG_REQUEST';
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/lists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import api from '../api';
import { importFetchedAccounts } from './importer';

import { showAlertForError } from './alerts';
import { importFetchedAccounts } from './importer';

export const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST';
export const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS';
Expand Down
6 changes: 4 additions & 2 deletions app/javascript/mastodon/actions/markers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import api from '../api';
import { List as ImmutableList } from 'immutable';

import { debounce } from 'lodash';

import api from '../api';
import { compareId } from '../compare_id';
import { List as ImmutableList } from 'immutable';

export const MARKERS_FETCH_REQUEST = 'MARKERS_FETCH_REQUEST';
export const MARKERS_FETCH_SUCCESS = 'MARKERS_FETCH_SUCCESS';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/mutes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api, { getLinks } from '../api';

import { fetchRelationships } from './accounts';
import { importFetchedAccounts } from './importer';
import { openModal } from './modal';
Expand Down
18 changes: 11 additions & 7 deletions app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import api, { getLinks } from '../api';
import IntlMessageFormat from 'intl-messageformat';
import { defineMessages } from 'react-intl';

import { List as ImmutableList } from 'immutable';

import { compareId } from 'mastodon/compare_id';
import { usePendingItems as preferPendingItems } from 'mastodon/initial_state';

import api, { getLinks } from '../api';
import { unescapeHTML } from '../utils/html';
import { requestNotificationPermission } from '../utils/notifications';

import { fetchFollowRequests, fetchRelationships } from './accounts';
import {
importFetchedAccount,
Expand All @@ -9,12 +19,6 @@ import {
} from './importer';
import { submitMarkers } from './markers';
import { saveSettings } from './settings';
import { defineMessages } from 'react-intl';
import { List as ImmutableList } from 'immutable';
import { unescapeHTML } from '../utils/html';
import { usePendingItems as preferPendingItems } from 'mastodon/initial_state';
import { compareId } from 'mastodon/compare_id';
import { requestNotificationPermission } from '../utils/notifications';

export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP';
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/actions/pin_statuses.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import api from '../api';
import { importFetchedStatuses } from './importer';

import { me } from '../initial_state';

import { importFetchedStatuses } from './importer';

export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST';
export const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS';
export const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/polls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { importFetchedPoll } from './importer';

export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setAlerts } from './setter';
import { saveSettings } from './registerer';
import { setAlerts } from './setter';

export function changeAlerts(path, value) {
return dispatch => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import api from '../../api';
import { decode as decodeBase64 } from '../../utils/base64';
import { me } from '../../initial_state';
import { pushNotificationsSetting } from '../../settings';
import { decode as decodeBase64 } from '../../utils/base64';

import { setBrowserSupport, setSubscription, clearSubscription } from './setter';
import { me } from '../../initial_state';

// Taken from https://www.npmjs.com/package/web-push
const urlBase64ToUint8Array = (base64String) => {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/reports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { openModal } from './modal';

export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { fetchRelationships } from './accounts';
import { importFetchedAccounts, importFetchedStatuses } from './importer';

Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import api from '../api';

import { importFetchedAccount } from './importer';

export const SERVER_FETCH_REQUEST = 'Server_FETCH_REQUEST';
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/mastodon/actions/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import api from '../api';
import { debounce } from 'lodash';

import api from '../api';

import { showAlertForError } from './alerts';

export const SETTING_CHANGE = 'SETTING_CHANGE';
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/actions/statuses.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import api from '../api';

import { deleteFromTimelines } from './timelines';
import { importFetchedStatus, importFetchedStatuses, importFetchedAccount } from './importer';
import { ensureComposeIsVisible, setComposeToStatus } from './compose';
import { importFetchedStatus, importFetchedStatuses, importFetchedAccount } from './importer';
import { deleteFromTimelines } from './timelines';

export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS';
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/actions/store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Iterable, fromJS } from 'immutable';

import { hydrateCompose } from './compose';
import { importFetchedAccounts } from './importer';

Expand Down
21 changes: 11 additions & 10 deletions app/javascript/mastodon/actions/streaming.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// @ts-check

import { getLocale } from '../locales';
import { connectStream } from '../stream';

import {
fetchAnnouncements,
updateAnnouncements,
updateReaction as updateAnnouncementsReaction,
deleteAnnouncement,
} from './announcements';
import { updateConversations } from './conversations';
import { updateNotifications, expandNotifications } from './notifications';
import { updateStatus } from './statuses';
import {
updateTimeline,
deleteFromTimelines,
Expand All @@ -12,16 +23,6 @@ import {
fillCommunityTimelineGaps,
fillListTimelineGaps,
} from './timelines';
import { updateNotifications, expandNotifications } from './notifications';
import { updateConversations } from './conversations';
import { updateStatus } from './statuses';
import {
fetchAnnouncements,
updateAnnouncements,
updateReaction as updateAnnouncementsReaction,
deleteAnnouncement,
} from './announcements';
import { getLocale } from '../locales';

const { messages } = getLocale();

Expand Down
3 changes: 2 additions & 1 deletion app/javascript/mastodon/actions/suggestions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import api from '../api';
import { importFetchedAccounts } from './importer';

import { fetchRelationships } from './accounts';
import { importFetchedAccounts } from './importer';

export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
Expand Down
8 changes: 5 additions & 3 deletions app/javascript/mastodon/actions/timelines.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { importFetchedStatus, importFetchedStatuses } from './importer';
import { submitMarkers } from './markers';
import api, { getLinks } from 'mastodon/api';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';

import api, { getLinks } from 'mastodon/api';
import { compareId } from 'mastodon/compare_id';
import { usePendingItems as preferPendingItems } from 'mastodon/initial_state';

import { importFetchedStatus, importFetchedStatuses } from './importer';
import { submitMarkers } from './markers';

export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
export const TIMELINE_DELETE = 'TIMELINE_DELETE';
export const TIMELINE_CLEAR = 'TIMELINE_CLEAR';
Expand Down
Loading

0 comments on commit d27216d

Please sign in to comment.