Skip to content

Commit 31bbd38

Browse files
build: enforce sort-imports eslint rule (#1147)
1 parent d77d3ac commit 31bbd38

File tree

149 files changed

+753
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+753
-305
lines changed

.eslintrc.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ const config = {
1111
react: {
1212
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
1313
},
14+
'import/resolver': {
15+
// Allows eslint-plugin-import to detect resolved imports
16+
typescript: {
17+
project: './tsconfig.json',
18+
},
19+
},
1420
},
1521
extends: [
1622
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
1723
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
1824
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
25+
'plugin:import/recommended', // Used along with eslint-plugin-import to sort imports with recommended standards
26+
'plugin:import/typescript', // To handle import order cases for typescript files
1927
],
28+
plugins: ['import'],
2029
rules: {
2130
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
2231
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
@@ -26,6 +35,47 @@ const config = {
2635
'@typescript-eslint/no-non-null-assertion': 'off',
2736
'@typescript-eslint/no-var-requires': 'off',
2837
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
38+
'sort-imports': [
39+
'error',
40+
{
41+
ignoreCase: false,
42+
ignoreDeclarationSort: true, // use eslint-plugin-import to handle this rule
43+
ignoreMemberSort: false,
44+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
45+
allowSeparatedGroups: true,
46+
},
47+
],
48+
'import/no-named-as-default-member': 'off',
49+
'import/namespace': 'off',
50+
'import/order': [
51+
'error',
52+
{
53+
groups: [
54+
'builtin', // Built-in imports
55+
'external', // External imports
56+
'internal', // Absolute imports
57+
['sibling', 'parent'], // Relative imports
58+
'index', // index imports
59+
'unknown',
60+
],
61+
// Keep all the `react` imports at the top level
62+
pathGroups: [
63+
{
64+
pattern: 'react',
65+
group: 'builtin',
66+
position: 'before',
67+
},
68+
],
69+
'newlines-between': 'always',
70+
alphabetize: {
71+
// sort in ascending order
72+
order: 'asc',
73+
caseInsensitive: true,
74+
},
75+
// Exclude `react` imports so that our custom pathGroups applies
76+
pathGroupsExcludedImportTypes: ['react'],
77+
},
78+
],
2979
},
3080
// the static folder is linted by standard
3181
ignorePatterns: ['/out', '/.webpack', '/coverage', '/static'],

forge.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const path = require('path');
21
const fs = require('fs');
2+
const path = require('path');
3+
34
const packageJson = require('./package.json');
45
const { maybeFetchContributors } = require('./tools/contributors');
56

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"contributors": "node ./tools/contributors.js",
1010
"lint:style": "stylelint \"./src/less/*.less\" --fix",
1111
"lint:ts": "eslint \"./**/*.{ts,tsx}\" --fix",
12+
"lint:js": "eslint \"./**/*.js\" --fix",
1213
"lint:templates": "standard \"static/**/*.js\" --fix",
1314
"lint:links": "node ./tools/check-links.js",
1415
"lint": "npm-run-all \"lint:*\"",
@@ -106,6 +107,8 @@
106107
"enzyme-to-json": "^3.6.1",
107108
"eslint": "^7.21.0",
108109
"eslint-config-prettier": "^8.1.0",
110+
"eslint-import-resolver-typescript": "^3.4.0",
111+
"eslint-plugin-import": "^2.26.0",
109112
"eslint-plugin-prettier": "^3.3.1",
110113
"eslint-plugin-react": "^7.22.0",
111114
"fetch-mock-jest": "^1.5.1",

rtl-spec/commands-address-bar.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { StateMock } from '../tests/mocks/state';
2-
31
import React from 'react';
2+
43
import { render } from '@testing-library/react';
54
import userEvent from '@testing-library/user-event';
5+
import { runInAction } from 'mobx';
66

7+
import { GistActionState } from '../src/interfaces';
78
import { AddressBar } from '../src/renderer/components/commands-address-bar';
89
import { AppState } from '../src/renderer/state';
9-
import { GistActionState } from '../src/interfaces';
10-
import { runInAction } from 'mobx';
10+
import { StateMock } from '../tests/mocks/state';
1111

1212
describe('AddressBar component', () => {
1313
let store: StateMock;

rtl-spec/commands-bisect.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as React from 'react';
2+
13
import { render } from '@testing-library/react';
24
import userEvent from '@testing-library/user-event';
3-
import * as React from 'react';
5+
46
import { VersionState } from '../src/interfaces';
57
import { BisectHandler } from '../src/renderer/components/commands-bisect';
68
import { AppState } from '../src/renderer/state';

src/ambient.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { App } from './renderer/app';
21
import * as MonacoType from 'monaco-editor';
32

3+
import { App } from './renderer/app';
4+
45
declare global {
56
interface Window {
67
ElectronFiddle: {

src/main/about-panel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as path from 'path';
2+
23
import { app } from 'electron';
4+
35
import { Contributor } from 'src/interfaces';
6+
47
import contributorsJSON from '../../static/contributors.json';
58

69
/**

src/main/command-line.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import * as os from 'os';
2+
13
import * as commander from 'commander';
24
import * as fs from 'fs-extra';
3-
import * as os from 'os';
45
import getos from 'getos';
56

67
import {

src/main/context-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Menu,
55
MenuItemConstructorOptions,
66
} from 'electron';
7+
78
import { IpcEvents } from '../ipc-events';
89
import { isDevMode } from '../utils/devmode';
910
import { ipcMainManager } from './ipc';

src/main/dialogs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { dialog, IpcMainEvent } from 'electron';
1+
import { IpcMainEvent, dialog } from 'electron';
2+
23
import { IpcEvents } from '../ipc-events';
34
import { ipcMainManager } from './ipc';
45
import { getOrCreateMainWindow } from './windows';

0 commit comments

Comments
 (0)