Skip to content

Commit

Permalink
fix: perfectionist/sort-imports sort types always on top
Browse files Browse the repository at this point in the history
Sorry for the massive diff again, but I after a second thought, I think this would make the imports more constant in the long run.
  • Loading branch information
antfu committed Sep 12, 2024
1 parent 574523f commit e283983
Show file tree
Hide file tree
Showing 35 changed files with 87 additions and 93 deletions.
5 changes: 2 additions & 3 deletions src/cli/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import c from 'picocolors'
import type { ExtraLibrariesOption, FrameworkOption, PromItem } from './types'

import c from 'picocolors'
import pkgJson from '../../package.json'

import type { ExtraLibrariesOption, FrameworkOption, PromItem } from './types'

export { pkgJson }

export const vscodeSettingsString = `
Expand Down
6 changes: 3 additions & 3 deletions src/cli/run.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable perfectionist/sort-objects */
import type { ExtraLibrariesOption, FrameworkOption, PromItem, PromptResult } from './types'

import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'

import * as p from '@clack/prompts'
import c from 'picocolors'

import { extra, extraOptions, frameworkOptions, frameworks } from './constants'
import { updateEslintFiles } from './stages/update-eslint-files'
import { updatePackageJson } from './stages/update-package-json'
import { updateVscodeSettings } from './stages/update-vscode-settings'
import { isGitClean } from './utils'

import type { ExtraLibrariesOption, FrameworkOption, PromItem, PromptResult } from './types'
import { isGitClean } from './utils'

export interface CliRunOptions {
/**
Expand Down
5 changes: 2 additions & 3 deletions src/cli/stages/update-eslint-files.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { PromptResult } from '../types'

import fs from 'node:fs'
import fsp from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'

import * as p from '@clack/prompts'
// @ts-expect-error missing types
import parse from 'parse-gitignore'
import c from 'picocolors'

import { getEslintConfigContent } from '../utils'

import type { PromptResult } from '../types'

export async function updateEslintFiles(result: PromptResult): Promise<void> {
const cwd = process.cwd()
const pathESLintIgnore = path.join(cwd, '.eslintignore')
Expand Down
6 changes: 3 additions & 3 deletions src/cli/stages/update-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ExtraLibrariesOption, PromptResult } from '../types'
import fsp from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'

import process from 'node:process'
import * as p from '@clack/prompts'

import c from 'picocolors'

import { dependenciesMap, pkgJson } from '../constants'

import type { ExtraLibrariesOption, PromptResult } from '../types'

export async function updatePackageJson(result: PromptResult): Promise<void> {
const cwd = process.cwd()

Expand Down
6 changes: 3 additions & 3 deletions src/cli/stages/update-vscode-settings.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { PromptResult } from '../types'
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'

import process from 'node:process'
import * as p from '@clack/prompts'

import c from 'picocolors'

import { vscodeSettingsString } from '../constants'

import type { PromptResult } from '../types'

export async function updateVscodeSettings(result: PromptResult): Promise<void> {
const cwd = process.cwd()

Expand Down
4 changes: 2 additions & 2 deletions src/configs/astro.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

import { GLOB_ASTRO } from '../globs'
import { interopDefault } from '../utils'

import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

export async function astro(
options: OptionsOverrides & OptionsStylistic & OptionsFiles = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createCommand from 'eslint-plugin-command/config'

import type { TypedFlatConfigItem } from '../types'

import createCommand from 'eslint-plugin-command/config'

export async function command(): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions src/configs/comments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pluginComments } from '../plugins'

import type { TypedFlatConfigItem } from '../types'

import { pluginComments } from '../plugins'

export async function comments(): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions src/configs/disables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GLOB_SRC, GLOB_SRC_EXT } from '../globs'

import type { TypedFlatConfigItem } from '../types'

import { GLOB_SRC, GLOB_SRC_EXT } from '../globs'

export async function disables(): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
8 changes: 4 additions & 4 deletions src/configs/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isPackageExists } from 'local-pkg'
import type { OptionsFormatters, StylisticConfig, TypedFlatConfigItem } from '../types'
import type { VendoredPrettierOptions } from '../vender/prettier-types'

import { isPackageExists } from 'local-pkg'
import { GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_GRAPHQL, GLOB_HTML, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SVG, GLOB_XML } from '../globs'

import { ensurePackages, interopDefault, isPackageInScope, parserPlain } from '../utils'
import { StylisticConfigDefaults } from './stylistic'

import type { OptionsFormatters, StylisticConfig, TypedFlatConfigItem } from '../types'
import type { VendoredPrettierOptions } from '../vender/prettier-types'

export async function formatters(
options: OptionsFormatters | true = {},
stylistic: StylisticConfig = {},
Expand Down
4 changes: 2 additions & 2 deletions src/configs/ignores.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GLOB_EXCLUDE } from '../globs'

import type { TypedFlatConfigItem } from '../types'

import { GLOB_EXCLUDE } from '../globs'

export async function ignores(userIgnores: string[] = []): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pluginAntfu, pluginImport } from '../plugins'

import type { OptionsStylistic, TypedFlatConfigItem } from '../types'

import { pluginAntfu, pluginImport } from '../plugins'

export async function imports(options: OptionsStylistic = {}): Promise<TypedFlatConfigItem[]> {
const {
stylistic = true,
Expand Down
4 changes: 2 additions & 2 deletions src/configs/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { OptionsIsInEditor, OptionsOverrides, TypedFlatConfigItem } from '../types'

import globals from 'globals'

import { pluginAntfu, pluginUnusedImports } from '../plugins'

import type { OptionsIsInEditor, OptionsOverrides, TypedFlatConfigItem } from '../types'

export async function javascript(
options: OptionsIsInEditor & OptionsOverrides = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/jsdoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { interopDefault } from '../utils'

import type { OptionsStylistic, TypedFlatConfigItem } from '../types'

import { interopDefault } from '../utils'

export async function jsdoc(options: OptionsStylistic = {}): Promise<TypedFlatConfigItem[]> {
const {
stylistic = true,
Expand Down
4 changes: 2 additions & 2 deletions src/configs/jsonc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

import { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from '../globs'
import { interopDefault } from '../utils'

import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

export async function jsonc(
options: OptionsFiles & OptionsStylistic & OptionsOverrides = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GLOB_JSX, GLOB_TSX } from '../globs'

import type { TypedFlatConfigItem } from '../types'

import { GLOB_JSX, GLOB_TSX } from '../globs'

export async function jsx(): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
6 changes: 3 additions & 3 deletions src/configs/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mergeProcessors, processorPassThrough } from 'eslint-merge-processors'
import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, TypedFlatConfigItem } from '../types'

import { mergeProcessors, processorPassThrough } from 'eslint-merge-processors'
import { GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN } from '../globs'
import { interopDefault, parserPlain } from '../utils'

import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, TypedFlatConfigItem } from '../types'
import { interopDefault, parserPlain } from '../utils'

export async function markdown(
options: OptionsFiles & OptionsComponentExts & OptionsOverrides = {},
Expand Down
4 changes: 2 additions & 2 deletions src/configs/node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pluginNode } from '../plugins'

import type { TypedFlatConfigItem } from '../types'

import { pluginNode } from '../plugins'

export async function node(): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
9 changes: 5 additions & 4 deletions src/configs/perfectionist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pluginPerfectionist } from '../plugins'

import type { TypedFlatConfigItem } from '../types'

import { pluginPerfectionist } from '../plugins'

/**
* Perfectionist plugin for props and items sorting.
*
Expand All @@ -18,12 +18,13 @@ export async function perfectionist(): Promise<TypedFlatConfigItem[]> {
'perfectionist/sort-exports': ['error', { order: 'asc', type: 'natural' }],
'perfectionist/sort-imports': ['error', {
groups: [
'type',
['parent-type', 'sibling-type', 'index-type'],

'builtin',
'external',
'type',
['internal', 'internal-type'],
['parent', 'sibling', 'index'],
['parent-type', 'sibling-type', 'index-type'],
'side-effect',
'object',
'unknown',
Expand Down
6 changes: 3 additions & 3 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isPackageExists } from 'local-pkg'
import type { OptionsFiles, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'

import { isPackageExists } from 'local-pkg'
import { GLOB_SRC } from '../globs'
import { ensurePackages, interopDefault, toArray } from '../utils'

import type { OptionsFiles, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
import { ensurePackages, interopDefault, toArray } from '../utils'

// react refresh
const ReactRefreshAllowConstantExportPackages = [
Expand Down
4 changes: 2 additions & 2 deletions src/configs/regexp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configs } from 'eslint-plugin-regexp'

import type { OptionsOverrides, OptionsRegExp, TypedFlatConfigItem } from '../types'

import { configs } from 'eslint-plugin-regexp'

export async function regexp(
options: OptionsRegExp & OptionsOverrides = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/solid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
import { GLOB_JSX, GLOB_TSX } from '../globs'
import { ensurePackages, interopDefault, toArray } from '../utils'

import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
import { ensurePackages, interopDefault, toArray } from '../utils'

export async function solid(
options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles & OptionsTypeScriptWithTypes = {},
Expand Down
4 changes: 2 additions & 2 deletions src/configs/stylistic.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsOverrides, StylisticConfig, TypedFlatConfigItem } from '../types'

import { pluginAntfu } from '../plugins'
import { interopDefault } from '../utils'

import type { OptionsOverrides, StylisticConfig, TypedFlatConfigItem } from '../types'

export const StylisticConfigDefaults: StylisticConfig = {
indent: 2,
jsx: true,
Expand Down
4 changes: 2 additions & 2 deletions src/configs/svelte.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

import { GLOB_SVELTE } from '../globs'
import { ensurePackages, interopDefault } from '../utils'

import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

export async function svelte(
options: OptionsHasTypeScript & OptionsOverrides & OptionsStylistic & OptionsFiles = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsFiles, OptionsIsInEditor, OptionsOverrides, TypedFlatConfigItem } from '../types'

import { GLOB_TESTS } from '../globs'
import { interopDefault } from '../utils'

import type { OptionsFiles, OptionsIsInEditor, OptionsOverrides, TypedFlatConfigItem } from '../types'

// Hold the reference so we don't redeclare the plugin on each call
let _pluginTest: any

Expand Down
4 changes: 2 additions & 2 deletions src/configs/toml.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

import { GLOB_TOML } from '../globs'
import { interopDefault } from '../utils'

import type { OptionsFiles, OptionsOverrides, OptionsStylistic, TypedFlatConfigItem } from '../types'

export async function toml(
options: OptionsOverrides & OptionsStylistic & OptionsFiles = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
11 changes: 5 additions & 6 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import process from 'node:process'

import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../globs'
import { pluginAntfu } from '../plugins'
import { interopDefault, renameRules } from '../utils'

import type {
OptionsComponentExts,
OptionsFiles,
Expand All @@ -14,6 +8,11 @@ import type {
TypedFlatConfigItem,
} from '../types'

import process from 'node:process'
import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../globs'
import { pluginAntfu } from '../plugins'
import { interopDefault, renameRules } from '../utils'

export async function typescript(
options: OptionsFiles & OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions & OptionsProjectType = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
4 changes: 2 additions & 2 deletions src/configs/unicorn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pluginUnicorn } from '../plugins'

import type { OptionsUnicorn, TypedFlatConfigItem } from '../types'

import { pluginUnicorn } from '../plugins'

export async function unicorn(options: OptionsUnicorn = {}): Promise<TypedFlatConfigItem[]> {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions src/configs/unocss.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ensurePackages, interopDefault } from '../utils'

import type { OptionsUnoCSS, TypedFlatConfigItem } from '../types'

import { ensurePackages, interopDefault } from '../utils'

export async function unocss(
options: OptionsUnoCSS = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
9 changes: 4 additions & 5 deletions src/configs/vue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { mergeProcessors } from 'eslint-merge-processors'

import { GLOB_VUE } from '../globs'
import { interopDefault } from '../utils'

import type {
OptionsFiles,
OptionsHasTypeScript,
Expand All @@ -12,6 +7,10 @@ import type {
TypedFlatConfigItem,
} from '../types'

import { mergeProcessors } from 'eslint-merge-processors'
import { GLOB_VUE } from '../globs'
import { interopDefault } from '../utils'

export async function vue(
options: OptionsVue & OptionsHasTypeScript & OptionsOverrides & OptionsStylistic & OptionsFiles = {},
): Promise<TypedFlatConfigItem[]> {
Expand Down
Loading

0 comments on commit e283983

Please sign in to comment.