Skip to content

A local-first personal finance app

More import-related ESLint rules (#1070)

Jed Foxe660e1e727ee
diff --git a/.eslintrc.js b/.eslintrc.js
index 413bef6a0c..4e7f3c5187 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -55,6 +55,7 @@ module.exports = {
// ],
'import/no-useless-path-segments': 'error',
+ 'import/no-duplicates': ['error', { 'prefer-inline': true }],
'import/order': [
'error',
{
@@ -132,5 +133,22 @@ module.exports = {
],
},
},
+ {
+ files: ['./packages/loot-core/src/**/*'],
+ rules: {
+ 'no-restricted-imports': [
+ 'error',
+ {
+ patterns: [
+ {
+ group: ['loot-core/**'],
+ message:
+ 'Please use relative imports in loot-core instead of importing from `loot-core/*`',
+ },
+ ],
+ },
+ ],
+ },
+ },
],
};
diff --git a/packages/desktop-client/src/components/SidebarWithData.js b/packages/desktop-client/src/components/SidebarWithData.js
index 68fb96d3c4..e24943c9bb 100644
--- a/packages/desktop-client/src/components/SidebarWithData.js
+++ b/packages/desktop-client/src/components/SidebarWithData.js
@@ -1,6 +1,5 @@
import React, { useState, useEffect } from 'react';
-import { connect } from 'react-redux';
-import { useDispatch } from 'react-redux';
+import { connect, useDispatch } from 'react-redux';
import { withRouter, useHistory } from 'react-router';
import { bindActionCreators } from 'redux';
diff --git a/packages/desktop-client/src/components/accounts/MobileTransaction.js b/packages/desktop-client/src/components/accounts/MobileTransaction.js
index ec2999aa23..0615a6ffe3 100644
--- a/packages/desktop-client/src/components/accounts/MobileTransaction.js
+++ b/packages/desktop-client/src/components/accounts/MobileTransaction.js
@@ -15,8 +15,11 @@ import memoizeOne from 'memoize-one';
import * as monthUtils from 'loot-core/src/shared/months';
import { getScheduledAmount } from 'loot-core/src/shared/schedules';
-import { titleFirst } from 'loot-core/src/shared/util';
-import { integerToCurrency, groupById } from 'loot-core/src/shared/util';
+import {
+ titleFirst,
+ integerToCurrency,
+ groupById,
+} from 'loot-core/src/shared/util';
import ArrowsSynchronize from '../../icons/v2/ArrowsSynchronize';
import CheckCircle1 from '../../icons/v2/CheckCircle1';
diff --git a/packages/desktop-client/src/components/manager/ConfigServer.js b/packages/desktop-client/src/components/manager/ConfigServer.js
index b2c88e7717..a4e7a1235c 100644
--- a/packages/desktop-client/src/components/manager/ConfigServer.js
+++ b/packages/desktop-client/src/components/manager/ConfigServer.js
@@ -4,8 +4,10 @@ import { useHistory } from 'react-router-dom';
import { createBudget } from 'loot-core/src/client/actions/budgets';
import { signOut, loggedIn } from 'loot-core/src/client/actions/user';
-import { isNonProductionEnvironment } from 'loot-core/src/shared/environment';
-import { isElectron } from 'loot-core/src/shared/environment';
+import {
+ isNonProductionEnvironment,
+ isElectron,
+} from 'loot-core/src/shared/environment';
import { useSetThemeColor } from '../../hooks';
import { colors } from '../../style';
diff --git a/packages/loot-core/src/client/data-hooks/accounts.tsx b/packages/loot-core/src/client/data-hooks/accounts.tsx
index dcbfb7ea9d..c19b2c4e6c 100644
--- a/packages/loot-core/src/client/data-hooks/accounts.tsx
+++ b/packages/loot-core/src/client/data-hooks/accounts.tsx
@@ -1,8 +1,8 @@
import React, { createContext, useContext } from 'react';
-import q from 'loot-core/src/client/query-helpers';
-import { useLiveQuery } from 'loot-core/src/client/query-hooks';
-import { getAccountsById } from 'loot-core/src/client/reducers/queries';
+import q from '../query-helpers';
+import { useLiveQuery } from '../query-hooks';
+import { getAccountsById } from '../reducers/queries';
export function useAccounts() {
return useLiveQuery(() => q('accounts').select('*'), []);
diff --git a/packages/loot-core/src/client/data-hooks/payees.tsx b/packages/loot-core/src/client/data-hooks/payees.tsx
index 6b86dbbad3..c06ba9a2e3 100644
--- a/packages/loot-core/src/client/data-hooks/payees.tsx
+++ b/packages/loot-core/src/client/data-hooks/payees.tsx
@@ -1,8 +1,8 @@
import React, { createContext, useContext } from 'react';
-import q from 'loot-core/src/client/query-helpers';
-import { useLiveQuery } from 'loot-core/src/client/query-hooks';
-import { getPayeesById } from 'loot-core/src/client/reducers/queries';
+import q from '../query-helpers';
+import { useLiveQuery } from '../query-hooks';
+import { getPayeesById } from '../reducers/queries';
export function usePayees() {
return useLiveQuery(() => q('payees').select('*'), []);
diff --git a/packages/loot-core/src/client/data-hooks/schedules.tsx b/packages/loot-core/src/client/data-hooks/schedules.tsx
index 960e259ec6..61e2419237 100644
--- a/packages/loot-core/src/client/data-hooks/schedules.tsx
+++ b/packages/loot-core/src/client/data-hooks/schedules.tsx
@@ -1,10 +1,7 @@
import React, { createContext, useEffect, useState, useContext } from 'react';
-import q, { liveQuery } from 'loot-core/src/client/query-helpers';
-import {
- getStatus,
- getHasTransactionsQuery,
-} from 'loot-core/src/shared/schedules';
+import { getStatus, getHasTransactionsQuery } from '../../shared/schedules';
+import q, { liveQuery } from '../query-helpers';
function loadStatuses(schedules, onData) {
return liveQuery(getHasTransactionsQuery(schedules), onData, {
diff --git a/packages/loot-core/src/client/query-hooks.tsx b/packages/loot-core/src/client/query-hooks.tsx
index e7bfe80095..5828a67159 100644
--- a/packages/loot-core/src/client/query-hooks.tsx
+++ b/packages/loot-core/src/client/query-hooks.tsx
@@ -7,7 +7,7 @@ import React, {
type DependencyList,
} from 'react';
-import { type Query } from 'loot-core/src/shared/query';
+import { type Query } from '../shared/query';
import { liveQuery, LiveQuery, PagedQuery } from './query-helpers';
diff --git a/upcoming-release-notes/1070.md b/upcoming-release-notes/1070.md
new file mode 100644
index 0000000000..6ffe085d8a
--- /dev/null
+++ b/upcoming-release-notes/1070.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [j-f1]
+---
+
+Add a few more `eslint-plugin-import` rules to keep our imports tidy