@frontify/eslint-config-react 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frontify/eslint-config-react",
3
3
  "type": "module",
4
- "version": "1.0.14",
4
+ "version": "1.0.15",
5
5
  "author": "Frontify Developers <developers@frontify.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "main": "eslint.config.mjs",
13
13
  "files": [
14
+ "rules",
14
15
  "eslint.config.mjs"
15
16
  ],
16
17
  "peerDependencies": {
@@ -25,7 +26,7 @@
25
26
  "eslint-plugin-jsx-a11y-x": "^0.1.1",
26
27
  "globals": "^17.4.0",
27
28
  "typescript-eslint": "^8.57.2",
28
- "@frontify/eslint-config-basic": "^1.0.14"
29
+ "@frontify/eslint-config-basic": "^1.0.15"
29
30
  },
30
31
  "devDependencies": {
31
32
  "eslint": "^10.1.0",
@@ -0,0 +1,25 @@
1
+ /* (c) Copyright Frontify Ltd., all rights reserved. */
2
+
3
+ // @ts-check
4
+
5
+ /** @returns {import('@eslint-react/kit').RuleDefinition} */
6
+ export function jsxShorthandBoolean() {
7
+ return (context) => ({
8
+ JSXAttribute(node) {
9
+ const { value } = node;
10
+ if (
11
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
12
+ value?.type === 'JSXExpressionContainer' &&
13
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
14
+ value.expression.type === 'Literal' &&
15
+ 'value' in value.expression &&
16
+ value.expression.value === true
17
+ ) {
18
+ context.report({
19
+ node,
20
+ message: 'Use shorthand syntax for boolean JSX props instead of `={true}`.',
21
+ });
22
+ }
23
+ },
24
+ });
25
+ }
@@ -0,0 +1,37 @@
1
+ import eslintReactKit from '@eslint-react/kit';
2
+ import { RuleTester } from 'eslint';
3
+
4
+ import { jsxShorthandBoolean } from './jsx-shorthand-boolean.mjs';
5
+
6
+ const plugin = eslintReactKit().use(jsxShorthandBoolean).getPlugin();
7
+ const rule = plugin.rules['jsx-shorthand-boolean'];
8
+
9
+ const ruleTester = new RuleTester({
10
+ languageOptions: {
11
+ parserOptions: {
12
+ ecmaFeatures: { jsx: true },
13
+ },
14
+ },
15
+ });
16
+
17
+ ruleTester.run('jsx-shorthand-boolean', rule, {
18
+ valid: [{ code: '<Foo bar />' }, { code: '<Foo bar={false} />' }, { code: '<Foo bar={someVariable} />' }],
19
+ invalid: [
20
+ {
21
+ code: '<Foo bar={true} />',
22
+ errors: [
23
+ {
24
+ message: 'Use shorthand syntax for boolean JSX props instead of `={true}`.',
25
+ },
26
+ ],
27
+ },
28
+ {
29
+ code: '<Foo bar={true} baz="hello" />',
30
+ errors: [
31
+ {
32
+ message: 'Use shorthand syntax for boolean JSX props instead of `={true}`.',
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ });