godaddy / eslint-plugin-i18n-json

Fully extendable eslint plugin for JSON i18n translation files.
https://godaddy.github.io/2018/04/02/introducing-eslint-plugin-i18n-json/
MIT License
182 stars 25 forks source link

ESLint flat config / eslint.config.js #62

Open a-schyja opened 6 months ago

a-schyja commented 6 months ago

How to use this great plugin with the new flat config file format?

glitch452 commented 2 months ago

I was able to get it working with the below, but it would be awesome if the plugin added a flat config.

import i18nJsonPlugin from 'eslint-plugin-i18n-json';

export default {
  files: ['**/*.json'],
  plugins: { 'i18n-json': i18nJsonPlugin },
  processor: {
    meta: { name: '.json' },
    ...i18nJsonPlugin.processors['.json'],
  },
  rules: {
    ...i18nJsonPlugin.configs.recommended.rules,
    'i18n-json/valid-message-syntax': 'off',
  },
};
jamiter commented 2 months ago

@glitch452, thanks for sharing! It's working for me as well in an NX monorepo library containing the translation files:

// libs/i18n/messages/eslint.config.js

const { resolve } = require('node:path');

const i18nJsonPlugin = require('eslint-plugin-i18n-json');

const baseConfig = require('../../../eslint.config.js');

module.exports = [
  ...baseConfig,
  {
    files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
    rules: {},
  },
  {
    files: ['**/dictionaries/**/*.json'],
    plugins: { 'i18n-json': i18nJsonPlugin },
    processor: {
      meta: { name: '.json' },
      ...i18nJsonPlugin.processors['.json'],
    },
    rules: {
      ...i18nJsonPlugin.configs.recommended.rules,
      'i18n-json/identical-keys': [
        'error',
        {
          filePath: resolve('./src/dictionaries/en.json'),
        },
      ],
    },
  },
];