nuxt-modules / eslint

ESLint module for Nuxt.js
MIT License
160 stars 15 forks source link

Autofix feauture not works with serverMiddleware files #60

Closed de-soul closed 2 years ago

de-soul commented 3 years ago

Hello,

i'am using @nuxtjs/eslint-module in nuxt.config.js:

...
buildModules: [
    '@nuxtjs/eslint-module',
  ],
...
...
  eslint: {
    fix: true
  },
...

It works well and my nuxt files autofixed on save correctly, such as in ./layouts, /pages etc. But after adding middleware (Express):

...
  serverMiddleware: {
    '/api': '~/api'
  },
...

ESLint and its plugins only checking /api files for errors, but dont autofixig them. I tryed to add /api folder to watch property under build options, but this do not have effect.

...
  build: {
    watch: ['api'],
  },
...
kissu commented 3 years ago

Your Nuxt version is probably not super old, hence you should use ['@nuxtjs/eslint-module', { /* module options */ }] syntax to set fix: true and not in the eslint key so

buildModules: [
  ['@nuxtjs/eslint-module', { fix: true }]
],

I'm still not sure what this is supposed to do. It is supposed to fix the errors, okay but when? Nothing works besides my usual ESlint extension.

EDIT: nvm, I found out that it does format it when the server is launched and with a little Husky configuration.

kissu commented 3 years ago

Could be nice to have more info on this one indeed. 😄

pi0 commented 3 years ago

Hi! Actually, it is not possible for server-middleware or nuxt config and this module only adds a webpack plugin that works for codes handled by webpack like pages/

You can use an IDE plugin for the auto fix or yarn eslint --fix . as an alternative.

kissu commented 3 years ago

Thanks for the confirmation Pooya!