-
Notifications
You must be signed in to change notification settings - Fork 9
feat: enforce consistent imports with import/order
#26
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import stylisticTS from '@stylistic/eslint-plugin-ts'; | ||
import * as tsParser from '@typescript-eslint/parser'; | ||
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; | ||
import pluginImport from 'eslint-plugin-import-x'; | ||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; | ||
import tseslint from 'typescript-eslint'; | ||
import { rules as blitzRules } from '../rules'; | ||
|
@@ -56,5 +57,16 @@ export function recommended(extenions?: RuleExtensions): FlatConfig.ConfigArray | |
...tsRules(extenions?.ts), | ||
}, | ||
}, | ||
{ | ||
name: 'blitz/import', | ||
files: [...tsFileExtensions, ...jsFileExtensions], | ||
plugins: { | ||
import: pluginImport, | ||
}, | ||
rules: { | ||
// https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/order.md | ||
'import/order': ['error', { alphabetize: { order: 'asc' } }], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we double check if it works correctly that it doesn't re-order imports that are separated by newlines? So that each block of imports is independently sorted and not all imports are sorted / grouped? There is often the use case to have say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this is allowed: import fs from 'fs';
import { test } from 'vitest';
import messages from '../util/messages';
import json from './json';
import utils from './utils';
import './side-effects';
import './some.css'; Looks like this is nicely configurable: https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/order.md#newlines-between-ignorealwaysalways-and-inside-groupsnever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing would be that I can prolly no longer use the "organize imports" in VSC since it doesn't match the ordering of this plugin. That's very unfortunate cause it's so easy but I guess the plugin provides a fixer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, there's autofix! Just run ESLint autofixes on save and it provides similar experience. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I guess I can re-map maybe that shortcut to run eslint or something. I have to look into it unless you know if that's possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've used just ESLint and prettier plugins for sorting the imports. IDE's modifying code is not consistent across all developers so I try to avoid those. 😄 |
||
}, | ||
}, | ||
]; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.