eslint-plugin icon indicating copy to clipboard operation
eslint-plugin copied to clipboard

Flat config support ?

Open yuriy-yarosh opened this issue 2 years ago • 6 comments

Using this plugin with flat config is a bit cumbersome atm. It would've been nice to update it to the most recent plugin structure and provide couple flat config examples.

yuriy-yarosh avatar Jan 10 '24 06:01 yuriy-yarosh

Could you elaborate a bit on that? May be show some examples by what you mean "cumbersome". As far as i understand having "flat" config vs legacy should not affect plugins and rules only the way how you declare them.

timofei-iatsenko avatar Jan 10 '24 08:01 timofei-iatsenko

should not affect plugins

@thekip It does require very specific structure, and plugin porting, with some backward compat guarantees.

Could you elaborate a bit on that?

This won't work

import lingui from 'eslint-plugin-lingui';

export default [{
  files: ['*.js', '*.cjs', '**/src/**/*.js', '**/src/**/*.jsx'],
  plugins: {
    lingui,
  },
  rules: {
    ...lingui.configs.recommended.rules
  }
}];

This won't work either...

import lingui from 'eslint-plugin-lingui';

export default [{
  files: ['*.js', '*.cjs', '**/src/**/*.js', '**/src/**/*.jsx'],
  plugins: {
    lingui,
  },
  rules: {
    ...Object.fromEntries(Object.entries(lingui.rules).map(([key, value]) => [`lingui/${key}`, 'warn']))
  }
}];

Because lingui plugin only exports obsolete rules format, and there are no Configs

зображення

yuriy-yarosh avatar Jan 11 '24 05:01 yuriy-yarosh

Go this, thanks. Would you be interesting opening a PR? It seems it's not a complicated change.

timofei-iatsenko avatar Jan 11 '24 07:01 timofei-iatsenko

@thekip sure, I'll fix this when I'll get some free time.

yuriy-yarosh avatar Jan 11 '24 09:01 yuriy-yarosh

Update: i've just checked the plugin, and it seems it's not a subject for the change at least for now. Because it doesn't expose any "recommended" setup, only rules which are not have to be updated.

timofei-iatsenko avatar Jan 11 '24 09:01 timofei-iatsenko

Waiting on this too. Though I've got a workaround working using Eslint's compatibility library. Let me know if this workaround works with you all as well.

import { fixupPluginRules } from '@eslint/compat'
import lingui from 'eslint-plugin-lingui'

export default [
  ...
  {
    files: ['**/*.{ts,tsx}'],
    plugins: {
      lingui: fixupPluginRules(lingui)
    },
    rules: {
      'lingui/no-unlocalized-strings': 'error',
      'lingui/t-call-in-function': 'error',
      'lingui/no-single-variables-to-translate': 'error',
      'lingui/no-expression-in-message': 'error',
      'lingui/no-single-tag-to-translate': 'error',
      'lingui/no-trans-inside-trans': 'error'
    }
  },
  ...
]

Screenshot 2024-07-01 080635 Screenshot 2024-07-01 080651

lemueldizon avatar Jul 01 '24 15:07 lemueldizon