Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this configuration to format JSX.Element #185

Closed
croatialu opened this issue May 22, 2023 · 7 comments
Closed

How to use this configuration to format JSX.Element #185

croatialu opened this issue May 22, 2023 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed pr welcome

Comments

@croatialu
Copy link

ignoredNodes: ['TemplateLiteral *', 'JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'],

I want to autofix indent in the JSX Element of the tsx file, but it doesn't work. and then i saw that the configuration ignored the indent rules related to JSX Element

I would like to ask why this configuration is necessary

When I configure it this way, my jsx element indent will work normally

{
  "extends": [
    "@antfu",
    "@unocss"
  ],
  "rules": {
    "indent": [
      "error",
      2,
      {
        "SwitchCase": 1,
        "VariableDeclarator": 1,
        "outerIIFEBody": 1,
        "MemberExpression": 1,
        "FunctionDeclaration": { "parameters": 1, "body": 1 },
        "FunctionExpression": { "parameters": 1, "body": 1 },
        "CallExpression": { "arguments": 1 },
        "ArrayExpression": 1,
        "ObjectExpression": 1,
        "ImportDeclaration": 1,
        "flatTernaryExpressions": false,
        "ignoreComments": false,
        "ignoredNodes": [
          // "TemplateLiteral *",
          // "JSXElement",
          // "JSXElement > *",
          // "JSXAttribute",
          // "JSXIdentifier",
          // "JSXNamespacedName",
          // "JSXMemberExpression",
          // "JSXSpreadAttribute",
          // "JSXExpressionContainer",
          // "JSXOpeningElement",
          // "JSXClosingElement",
          // "JSXFragment",
          // "JSXOpeningFragment",
          // "JSXClosingFragment",
          // "JSXText",
          // "JSXEmptyExpression",
          // "JSXSpreadChild",
          "TSTypeParameterInstantiation",
          "FunctionExpression > .params[decorators.length > 0]",
          "FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
          "ClassBody.body > PropertyDefinition[decorators.length > 0] > .key"
        ],
        "offsetTernaryExpressions": true
      }
    ]
  }
}

@kkfive
Copy link

kkfive commented May 23, 2023

I want to use it too

@ZaneL1u
Copy link

ZaneL1u commented Jul 6, 2023

+1

@LiZhequ
Copy link

LiZhequ commented Jul 18, 2023

for react, you can use eslint-config-standard-jsx

{
  "extends": ["standard-jsx", "@antfu/eslint-config-react"]
}

@chizukicn
Copy link

chizukicn commented Sep 30, 2023

My solution is to turn off the indent rule in typescript and use the @typescript-eslint/indent rule

{
    "indent": "off",
    "@typescript-eslint/indent": ["error", 2, {
      SwitchCase: 1,
      VariableDeclarator: 1,
      outerIIFEBody: 1,
      MemberExpression: 1,
      FunctionDeclaration: { parameters: 1, body: 1 },
      FunctionExpression: { parameters: 1, body: 1 },
      CallExpression: { arguments: 1 },
      ArrayExpression: 1,
      ObjectExpression: 1,
      ImportDeclaration: 1,
      flatTernaryExpressions: false,
      ignoreComments: false,
      offsetTernaryExpressions: true
    }],
}

@antfu
Copy link
Owner

antfu commented Oct 1, 2023

Since we have migrated to that flat config, it would be much easier to compose JSX support. If anyone has made a robust JSX/TSX config that could work generally for React/Solid/Vue JSX, then I'd be happy to have it built in.

@antfu antfu added enhancement New feature or request help wanted Extra attention is needed pr welcome labels Oct 1, 2023
@antfu
Copy link
Owner

antfu commented Oct 3, 2023

Related: eslint-stylistic/eslint-stylistic#12

@antfu antfu closed this as completed in 2dfb5fd Oct 9, 2023
@antfu
Copy link
Owner

antfu commented Oct 9, 2023

Supported in @antfu/eslint-config@1.0.0-beta.24. As I don't use JSX a lot myself, the rules might not cover all cases well, PR welcome if you spot any improvements. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed pr welcome
Projects
None yet
Development

No branches or pull requests

6 participants