Skip to content

Add rule(s) to sort keys in nuxt.config.ts to keep everything in order

Open

Description

Describe the feature

As a possible new feature, I think that it could be useful to have a rule to keep nuxt.config.ts clean and tidy by sorting its keys with specific criteria.

The inspiration for this is the jsonc/sort-keys rule that is often used to keep package.json ordered according to a specific pattern.

Especially when a project grows, nuxt.config.ts can become quite large and contain many configuration items.

A possible example could be

export default defineNuxtConfig({
  // place "modules" section first, and keep all entries alphabetically sorted.
  modules: [
    '@nuxt/image',
    '@nuxtjs/seo',
    'nuxt-icon',
    // and so on
  ],
  
  // other builtin config items
  css: ['~/assets/css/fontface.css'],
  components: { 
    // ...
  }
  
  // modules options, maybe alphabetically
  
  image: {
    //
  }
  
  // and so on

})

This is just an example of possible sorting criteria, but there can be even better I think.

I don't know if it is a good idea to have some preset rules for this, or if it is just something best left to the user.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions