Rel1cx/eslint-react

[feat] Support .js and .jsx

Closed this issue ยท 1 comments

Describe the problem

Hi ๐Ÿ‘‹ First I want to thank you for your perfect work. ๐Ÿ™

Currently, this plugin works in .ts and .tsx files. Is it possible to support .js and .jsx files? It would be great for projects using JS only.

Describe the solution you'd like

Just a thought. ๐Ÿค”

// eslint.config.js
import js from "@eslint/js";
import react from "@eslint-react/eslint-plugin";
import * as tsParser from "@typescript-eslint/parser";
 
export default [
  js.configs.recommended,
  // for .js and .jsx files
  {
    files: ["**/*.{js,jsx}"],
    ...react.configs.recommended,
  },
  // for .ts and .tsx files
  {
    files: ["**/*.{ts,tsx}"],
    ...react.configs.recommended,
    languageOptions: {
      parser: tsParser,
    },
  },
];

Actually, I know little about ESLint plugin so I can't provide information or a solution here. Sorry.

Alternatives considered

No response

Additional context

I tried a little.

npm create vite@latest
# Pick React then JavaScript + SWC
cd vite-project
npm install @eslint-react/eslint-plugin -D

Update eslint.config.js.

import react from "@eslint-react/eslint-plugin";

export default [
  { ignores: ["dist"] },
  {
    files: ["*.jsx"],
    ...react.configs.recommended,
  },
];

Create src/test.jsx.

import React, { Children } from "react";

function Example({ children }) {
  return (
    <div className="RowList">
      {Children.map(children, (child) => (
        <div className="Row">{child}</div>
      ))}
    </div>
  );
}

export default Example;

Run ESLint.

npm run lint

I get no error but I expect one https://eslint-react.xyz/docs/rules/no-access-state-in-setstate

The plugin already supports js and jsx, no need for any workarounds, I've added a JS project configuration example in examples https://github.com/Rel1cx/eslint-react/tree/main/examples/flat-config-react-dom.