Rel1cx / eslint-react

A series of composable ESLint plugins for libraries and frameworks that use React as a UI runtime.
https://eslint-react.xyz
MIT License
258 stars 11 forks source link

[bug] @eslint-react/naming-convention/filename not working for .ts files #856

Open palmjack opened 5 hours ago

palmjack commented 5 hours ago

Describe the bug

Not sure if it's a bug or a feature, but this rule works for *.{jsx,tsx} files only. I'm trying to make it work also for .ts files, since I want to enforce naming convention in the entire app. I tested on both next.js app and clean vite app.

Reproduction

My eslint file (shrinked for demo purposes)

// @ts-check

import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginReact from '@eslint-react/eslint-plugin';
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

const flatCompat = new FlatCompat();

export default tseslint.config(
  { ignores: ['node_modules', '.next'] },
  {
    files: ['src/**/*.{js,jsx,mjs,cjs,ts,tsx}'],
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        projectService: true
      }
    },
    extends: [
      eslint.configs.recommended,
      ...tseslint.configs.strictTypeChecked,
      ...tseslint.configs.stylisticTypeChecked,
      ...flatCompat.extends('next/core-web-vitals'),
      pluginReact.configs['recommended-type-checked']
    ],
    plugins: {
      '@typescript-eslint': tseslint.plugin
    },

    rules: {
      '@eslint-react/naming-convention/filename': ['error', 'kebab-case']
    }
  },
  pluginPrettierRecommended
);

Expected behavior

Throw error for files with .ts extension

Platform and versions

macOS v15.1
node - v22.11.0
"@eslint-react/eslint-plugin": "^1.16.1"
"@eslint/js": "^9.14.0"

Stack trace

No response

Additional context

No response

palmjack commented 4 hours ago

Looks like I was able to fix it, would be happy too make PR in order to clarify this possible config in docs '@eslint-react/naming-convention/filename': ['error', { extensions: ['.jsx', '.tsx', '.ts'], rule: 'kebab-case' }] Still would be better not to have fixed options in the rule itself

Rel1cx commented 4 hours ago

Looks like I was able to fix it, would be happy too make PR in order to clarify this possible config in docs '@eslint-react/naming-convention/filename': ['error', { extensions: ['.jsx', '.tsx', '.ts'], rule: 'kebab-case' }] Still would be better not to have fixed options in the rule itself

Great, looking forward to your PR!