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

Automatically sort imports #248

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/base/rules-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,20 @@
}
],
"import/no-webpack-loader-syntax": "error",
"import/order": "error",
"import/order": [
"error",
{
"newlines-between": "always",
"groups": [
["builtin", "external"],
["internal", "parent", "sibling", "index"]
],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"import/unambiguous": "error",
"indent": "off",
"indent-legacy": "off",
Expand Down
25 changes: 24 additions & 1 deletion packages/base/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,30 @@ module.exports = {
},
],
'import/no-webpack-loader-syntax': 'error',
'import/order': 'error',
'import/order': [
'error',
{
// This means that there will always be a newline between the import
// groups as defined below.
'newlines-between': 'always',
Copy link
Member Author

Choose a reason for hiding this comment

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

I think personally this makes it easier to distinguish external imports from internal ones. I'm open to change this however.


groups: [
// "builtin" is Node.js modules that are built into the runtime, and
// "external" is everything else from node_modules.
['builtin', 'external'],

// "internal" is unused, but could be used for absolute imports from
// the project root.
['internal', 'parent', 'sibling', 'index'],
],

// Alphabetically sort the imports within each group.
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/unambiguous': 'error',

/* jsdoc plugin rules */
Expand Down
4 changes: 2 additions & 2 deletions scripts/validate-configs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { readdirSync, readFileSync, promises: fs } = require('fs');
const pathUtils = require('path');
const { FlatCompat } = require('@eslint/eslintrc');
const { hasProperty } = require('@metamask/utils');
const { recommendedConfig: eslintRecommendedConfig } = require('eslint');
const {
configs: { recommended: prettierConfig },
} = require('eslint-plugin-prettier');
const deepEqual = require('fast-deep-equal');
const { readdirSync, readFileSync, promises: fs } = require('fs');
const pathUtils = require('path');
const prettier = require('prettier');

// For config parsing, validation, and rule flattening
Expand Down