Skip to content

Commit

Permalink
feat: move to nuxt.sortConfigKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 12, 2024
1 parent ea1d2df commit ff1045a
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 18 deletions.
8 changes: 5 additions & 3 deletions packages/eslint-config/src/flat/configs/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export default function nuxt(options: NuxtESLintConfigOptions): Linter.Config[]
...(dirs.components?.map(componentsDir => join(componentsDir, `**/*.server.${GLOB_EXTS}`)) || []),
].sort()

const stylistic = options.features?.stylistic === true ? {} : options.features?.stylistic || undefined
const {
sortConfigKeys = !!(options.features?.stylistic),
} = options.features?.nuxt || {}

const configs: Linter.Config[] = []

configs.push({
name: 'nuxt/configs',
name: 'nuxt/setup',
plugins: {
nuxt: nuxtPlugin,
},
Expand Down Expand Up @@ -48,7 +50,7 @@ export default function nuxt(options: NuxtESLintConfigOptions): Linter.Config[]
},
})

if (stylistic && stylistic.nuxtConfigSort !== false) {
if (sortConfigKeys) {
configs.push({
name: 'nuxt/sort-config',
files: [
Expand Down
27 changes: 15 additions & 12 deletions packages/eslint-config/src/flat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface ToolingOptions {
jsdoc?: boolean
}

export interface NuxtSpecificOptions {
/**
* Sort keys in nuxt.config to maintain a consistent order
*
* @default true when `features.stylistic` is enabled
*/
sortConfigKeys?: boolean
}

export interface NuxtESLintFeaturesOptions {
/**
* Setup basic JavaScript, TypeScript and Vue plugins and rules.
Expand All @@ -47,7 +56,12 @@ export interface NuxtESLintFeaturesOptions {
* @see https://eslint.style/guide/config-presets
* @default false
*/
stylistic?: boolean | StylisticOptions
stylistic?: boolean | StylisticCustomizeOptions<true>

/**
* Options for Nuxt specific rules
*/
nuxt?: NuxtSpecificOptions

/**
* Enable TypeScript support. Can also be an object to config the options.
Expand Down Expand Up @@ -126,17 +140,6 @@ export interface NuxtESLintConfigOptions {
}
}

export interface NuxtSpecificStylisticOptions {
/**
* Sort keys in nuxt.config to maintain a consistent order
*
* @default true
*/
nuxtConfigSort?: boolean
}

export interface StylisticOptions extends StylisticCustomizeOptions<true>, NuxtSpecificStylisticOptions {}

type NotNill<T> = T extends null | undefined ? never : T

export interface NuxtESLintConfigOptionsResolved {
Expand Down
106 changes: 103 additions & 3 deletions packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports[`flat config composition > custom src dirs 1`] = `
"name": "nuxt/import/rules",
},
{
"name": "nuxt/configs",
"name": "nuxt/setup",
},
{
"files": [
Expand Down Expand Up @@ -148,7 +148,7 @@ exports[`flat config composition > empty 1`] = `
"name": "nuxt/import/rules",
},
{
"name": "nuxt/configs",
"name": "nuxt/setup",
},
{
"files": [
Expand Down Expand Up @@ -185,7 +185,7 @@ exports[`flat config composition > empty 1`] = `
exports[`flat config composition > non-standalone 1`] = `
[
{
"name": "nuxt/configs",
"name": "nuxt/setup",
},
{
"files": [
Expand Down Expand Up @@ -218,3 +218,103 @@ exports[`flat config composition > non-standalone 1`] = `
},
]
`;

exports[`flat config composition > with stylistic 1`] = `
[
{
"ignores": [
"**/node_modules",
"**/*.iml",
"**/.idea",
"**/*.log",
"**/.nuxt",
"**/.output",
"**/.yarn/cache",
"**/.yarn/*state*",
"**/dist",
"**/.eslintcache",
],
"name": "gitignore",
},
{
"ignores": [
"**/dist",
"**/node_modules",
"**/.nuxt",
"**/.output",
"**/.vercel",
"**/.netlify",
"**/public",
],
},
{
"name": "nuxt/javascript",
},
{
"name": "nuxt/typescript/setup",
},
{
"files": [
"**/*.ts",
"**/*.tsx",
"**/*.mts",
"**/*.cts",
"**/*.vue",
],
"name": "nuxt/typescript/rules",
},
{
"name": "nuxt/vue/setup",
},
{
"files": [
"**/*.vue",
],
"name": "nuxt/vue/rules",
},
{
"name": "nuxt/import/rules",
},
{
"name": "nuxt/setup",
},
{
"files": [
"app/components/**/*.server.{js,ts,jsx,tsx,vue}",
"app/layouts/**/*.{js,ts,jsx,tsx,vue}",
"app/pages/**/*.{js,ts,jsx,tsx,vue}",
"components/**/*.server.{js,ts,jsx,tsx,vue}",
"layouts/**/*.{js,ts,jsx,tsx,vue}",
"pages/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/vue/single-root",
},
{
"name": "nuxt/rules",
},
{
"files": [
"**/nuxt.config.?([cm])[jt]s?(x)",
],
"name": "nuxt/sort-config",
},
{
"name": "nuxt/stylistic",
},
{
"files": [
"app.{js,ts,jsx,tsx,vue}",
"app/app.{js,ts,jsx,tsx,vue}",
"app/components/*/**/*.{js,ts,jsx,tsx,vue}",
"app/error.{js,ts,jsx,tsx,vue}",
"app/layouts/**/*.{js,ts,jsx,tsx,vue}",
"app/pages/**/*.{js,ts,jsx,tsx,vue}",
"components/*/**/*.{js,ts,jsx,tsx,vue}",
"error.{js,ts,jsx,tsx,vue}",
"layouts/**/*.{js,ts,jsx,tsx,vue}",
"pages/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/disables/routes",
},
]
`;

0 comments on commit ff1045a

Please sign in to comment.