Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/shared-jsx-boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@frontify/eslint-config-react': patch
'@frontify/eslint-plugin': patch
'@frontify/oxlint-config-react': minor
---

Share the JSX boolean shorthand rule between ESLint and Oxlint. Oxlint now reports explicit `={true}` on JSX props as an error. Use the prop name alone, such as `<Button disabled />`.

Load the recommended JSX accessibility rules from the installed plugin's current configuration export.
13 changes: 6 additions & 7 deletions packages/eslint-config-react/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// @ts-check

import eslintPluginReact from '@eslint-react/eslint-plugin';
import eslintReactKit from '@eslint-react/kit';
import basicConfig from '@frontify/eslint-config-basic';
import frontifyPlugin from '@frontify/eslint-plugin';
import { defineConfig } from 'eslint/config';
// @ts-expect-error No types available
import eslintPluginJsxA11yX from 'eslint-plugin-jsx-a11y-x';

import { jsxShorthandBoolean } from './rules/jsx-shorthand-boolean.mjs';

export default defineConfig(
basicConfig,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
eslintPluginJsxA11yX.flatConfigs.recommended,
eslintPluginJsxA11yX.configs.recommended,
eslintPluginReact.configs['recommended-type-checked'],
eslintReactKit().use(jsxShorthandBoolean).getConfig(),
{
// Keep existing rule overrides and suppressions valid.
plugins: { '@eslint-react/kit': frontifyPlugin },
},
{
files: ['**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}'],
languageOptions: {
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
},
"main": "eslint.config.mjs",
"files": [
"rules",
"eslint.config.mjs"
],
"scripts": {
"lint": "eslint .",
"test": "node --test 'rules/**/*.test.mjs'",
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
Expand All @@ -27,8 +25,8 @@
},
"dependencies": {
"@eslint-react/eslint-plugin": "^5.8.9",
"@eslint-react/kit": "^5.8.9",
"@frontify/eslint-config-basic": "workspace:^",
"@frontify/eslint-plugin": "workspace:^",
"eslint-plugin-jsx-a11y-x": "^0.2.0",
"globals": "^17.6.0",
"typescript-eslint": "^8.60.0"
Expand Down
25 changes: 0 additions & 25 deletions packages/eslint-config-react/rules/jsx-shorthand-boolean.mjs

This file was deleted.

12 changes: 12 additions & 0 deletions packages/eslint-plugin/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

import jsxShorthandBoolean from './rules/jsx-shorthand-boolean.mjs';

export default {
meta: {
name: '@frontify/eslint-plugin',
},
rules: {
'jsx-shorthand-boolean': jsxShorthandBoolean,
},
};
29 changes: 29 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@frontify/eslint-plugin",
"type": "module",
"version": "0.0.1",
"description": "Shared Frontify lint rules for ESLint and Oxlint",
"author": "Frontify Developers <developers@frontify.com>",
"license": "MIT",
"repository": {
"directory": "packages/eslint-plugin",
"type": "git",
"url": "https://github.com/Frontify/code-style"
},
"exports": {
".": "./index.mjs"
},
"files": [
"index.mjs",
"rules/jsx-shorthand-boolean.mjs"
],
"scripts": {
"test": "node --test 'rules/**/*.test.mjs'"
},
"devDependencies": {
"eslint": "^10.4.1"
},
"publishConfig": {
"access": "public"
}
}
30 changes: 30 additions & 0 deletions packages/eslint-plugin/rules/jsx-shorthand-boolean.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

// @ts-check

const EXPLICIT_TRUE_PROP =
'JSXAttribute[value.type="JSXExpressionContainer"][value.expression.type="Literal"][value.expression.value=true]';
const SHORTHAND_MESSAGE_ID = 'shorthand';

/** @satisfies {import('eslint').Rule.RuleModule} */
const jsxShorthandBoolean = {
meta: {
schema: [],
messages: {
[SHORTHAND_MESSAGE_ID]: 'Use shorthand syntax for boolean JSX props instead of `={true}`.',
},
},
create(context) {
return {
/**
* Reports the explicit JSX prop.
* @param {import('eslint').JSSyntaxElement} node - The attribute matched by the selector.
*/
[EXPLICIT_TRUE_PROP](node) {
context.report({ node, messageId: SHORTHAND_MESSAGE_ID });
},
};
},
};

export default jsxShorthandBoolean;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import eslintReactKit from '@eslint-react/kit';
/* (c) Copyright Frontify Ltd., all rights reserved. */

import { RuleTester } from 'eslint';

import { jsxShorthandBoolean } from './jsx-shorthand-boolean.mjs';
import plugin from '../index.mjs';

const plugin = eslintReactKit().use(jsxShorthandBoolean).getPlugin();
const rule = plugin.rules['jsx-shorthand-boolean'];

const ruleTester = new RuleTester({
Expand All @@ -15,7 +15,12 @@ const ruleTester = new RuleTester({
});

ruleTester.run('jsx-shorthand-boolean', rule, {
valid: [{ code: '<Foo bar />' }, { code: '<Foo bar={false} />' }, { code: '<Foo bar={someVariable} />' }],
valid: [
{ code: '<Foo bar />' },
{ code: '<Foo bar={false} />' },
{ code: '<Foo bar={someVariable} />' },
{ code: '<Foo bar="true" />' },
],
invalid: [
{
code: '<Foo bar={true} />',
Expand Down
19 changes: 11 additions & 8 deletions packages/oxlint-config-react/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

import { fileURLToPath } from 'node:url';

import basicConfig from '@frontify/oxlint-config-basic';
import { defineConfig } from 'oxlint';

Expand Down Expand Up @@ -152,14 +154,15 @@ export default defineConfig({
'jsx-a11y/tabindex-no-positive': 'error',
},
overrides: [
// TODO: fix me when the kit plugin can be loaded in oxlint
// {
// files: ['**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}'],
// jsPlugins: ['@eslint-react/kit'],
// rules: {
// '@eslint-react/kit/jsx-shorthand-boolean': 'error',
// },
// },
{
files: ['**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}'],
jsPlugins: [
{ name: '@frontify', specifier: fileURLToPath(import.meta.resolve('@frontify/eslint-plugin')) },
],
rules: {
'@frontify/jsx-shorthand-boolean': 'error',
},
},
{
files: ['**/*.{js,jsx,ts,tsx}'],
jsPlugins: ['@eslint-react/eslint-plugin'],
Expand Down
2 changes: 1 addition & 1 deletion packages/oxlint-config-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@eslint-react/eslint-plugin": "^5.8.9",
"@eslint-react/kit": "^5.8.9",
"@frontify/eslint-plugin": "workspace:^",
"@frontify/oxlint-config-basic": "workspace:^"
},
"publishConfig": {
Expand Down
38 changes: 12 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.