edvardchen / eslint-plugin-i18next

ESLint plugin for i18next. Prevent to display non-localized text for users
MIT License
136 stars 39 forks source link

eslint-plugin-i18next does not work with ESLint v9 #129

Closed vpishuk closed 1 month ago

vpishuk commented 3 months ago

Thie plugin stopped working with ESLint v9.

edvardchen commented 3 months ago

Could you share you eslitn config and this plugin version?

vpishuk commented 3 months ago

Here is my eslint config: https://github.com/laverve/utilities/blob/main/packages/eslint-utils/src/eslint.config.js Plugins version that I tried is the latest one. E2lint v9 is using flat format as a default one.

edvardchen commented 3 months ago

The config didn't use eslint-plugin-i18next at all. Did you provide the wrong branch of the repo?

vpishuk commented 3 months ago

It's not there because I haven't figured out how to get flat config from this plugin which is required by eslint v9.

vpishuk commented 3 months ago

I have figured out how to add it without flat config thanks to modules provided by eslint for backward compatibility. It would be nice to address this issue on plugin level.

Here is my solution:

import eslintJs from "@eslint/js";

import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";

import { fileURLToPath } from "node:url";
import { dirname } from "node:path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
    baseDirectory: __dirname,
    recommendedConfig: eslintJs.configs.recommended
});

function legacyPlugin(name, alias = name) {
    const plugin = compat.plugins(name)[0]?.plugins?.[alias];

    if (!plugin) {
        throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
    }

    return fixupPluginRules(plugin);
}

export const config = [
    {
        plugins: {
            i18next: legacyPlugin("eslint-plugin-i18next", "i18next")
        },
        rules: {}
    }
];
edvardchen commented 3 months ago

could you try this

import i18next from 'eslint-plugin-i18next';

export default [
  {
    plugins: { i18next },
    rules: {
      'i18next/no-literal-string': ['error', { mode: 'all' }],
    },
  },
];
vpishuk commented 3 months ago

@edvardchen thank you! This wirks. It would be nice to add it into the docs. It would be great to export sharable config for eslint9.

edvardchen commented 3 months ago

Let me guess. You mean like this?

// eslint.config.js
import jsdoc from 'eslint-plugin-jsdoc';

export default [
  jsdoc.configs['flat/recommended'],
];
vpishuk commented 3 months ago

Yes, this would be great.