Skip to content

Commit

Permalink
feat(configs): add jsx support to stylistic config and reference Next…
Browse files Browse the repository at this point in the history
….js ESLint rules

- Add JSX support in stylistic config to accommodate React syntax
- Include a reference to Next.js ESLint plugin rules for better context and maintainability
- Ensure stylistic config respects the presence of React in the project when enabling JSX rules
  • Loading branch information
Bluzzi committed Dec 24, 2024
1 parent 89e6838 commit 0469ed9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/configs/nextjs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const nextjs = (): TypedFlatConfigItem[] => {
nextjs: nextjsPlugin,
},
rules: {
// https://github.com/vercel/next.js/blob/7a47ed5123b8dac03e9483cb823e224370da2667/packages/eslint-plugin-next/src/index.ts#L26
...nextjsPlugin.configs.recommended.rules,
...nextjsPlugin.configs["core-web-vitals"].rules,
},
Expand Down
5 changes: 3 additions & 2 deletions src/configs/stylistic/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { TypedFlatConfigItem } from "#/types/type";
import { antfuPlugin, stylisticPlugin } from "#/utils/extension";
import { configName } from "#/utils/naming";

export const stylistic = ({ indent = 2, quotes = "double", semi = true }: ParamsStylistic = {}): TypedFlatConfigItem[] => {
const config = stylisticPlugin.configs.customize({ pluginName: "style", indent, quotes, semi });
export const stylistic = ({ indent = 2, quotes = "double", semi = true, jsx = false }: ParamsStylistic = {}): TypedFlatConfigItem[] => {
const config = stylisticPlugin.configs.customize({ pluginName: "style", indent, quotes, semi, jsx });

return [{
name: configName("stylistic", "rules"),
Expand All @@ -25,6 +25,7 @@ export const stylistic = ({ indent = 2, quotes = "double", semi = true }: Params

"style/jsx-props-no-multi-spaces": ["error"],
"style/jsx-self-closing-comp": ["error", { component: true, html: true }],
"style/jsx-curly-brace-presence": ["error", { props: "never", children: "never" }],

"antfu/consistent-list-newline": "error",
},
Expand Down
7 changes: 7 additions & 0 deletions src/configs/stylistic/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ export type ParamsStylistic = {
* @default true
*/
semi?: boolean;

/**
* Whether to enable JSX
*
* @default false - enabled if "react" package is found
*/
jsx?: boolean;
};
2 changes: 1 addition & 1 deletion src/utils/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const eslintConfig = async (

// Stylistic:
logger.info("stylistic - config enabled");
configs.push(stylistic(options.stylistic));
configs.push(stylistic({ ...options.stylistic, jsx: enabled.react }));

// React:
if (enabled.react) {
Expand Down

0 comments on commit 0469ed9

Please sign in to comment.