azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.64k stars 29 forks source link

Bug: next's 'use client' leads to 'Fix objects must not be overlapped in a report' #18

Closed ilmpc closed 11 months ago

ilmpc commented 11 months ago

Describe the bug

Plugin got stuck if it finds 'use client' on top line

Code example

"use client";

import { Input } from "@/components/ui/input";
import React from "react";
import { useEffect, useState } from "react";

const EmailNameChanging = () => {...}

ESLint version

8.42.0

ESLint Plugin Perfectionist version

1.2.0

Additional comments

No response

Validations

azat-io commented 11 months ago

I tried to reproduce the problem with your code, but everything works correctly for me.

Are you sure that this part of the code is the problem?

Can you run the eslint command with the --debug flag to find the problem file? Or perhaps the problem is in another part of that file?

azat-io commented 11 months ago

For convenience, I created a project on Stackblitz: https://stackblitz.com/edit/node-nth3q2?file=.eslintrc.js,src%2Findex.js

You can try to open this page, write some code and run the command pnpm run lint. I have not been able to reproduce your problem at this time.

ilmpc commented 11 months ago

It looks like it doesn't connected to 'use client' I thought it was exactly because of --debug output. Line 1 was stated as a problem. I've found that two empty lines in import statements creates the problem

import Image from "next/image";
import { useState } from "react";

import React from "react"; 
eslint --debug output ``` eslint:cli-engine Lint /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +12ms eslint:linter Linting code for /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx (pass 1) +4ms eslint:linter Verify +0ms eslint:linter With ConfigArray: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +0ms eslint:linter Parsing: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +1ms eslint:linter Parsing successful: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +2ms eslint:linter Scope analysis: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +0ms eslint:linter Scope analysis successful: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +0ms eslint:linter An error occurred while traversing +4ms eslint:linter Filename: /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx +0ms eslint:linter Line: 1 +0ms eslint:linter Parser Options: { ecmaFeatures: { globalReturn: false, jsx: true }, sourceType: 'module', warnOnUnsupportedTypeScriptVersion: true, requireConfigFile: false, allowImportExportEverywhere: true, babelOptions: { presets: [ 'next/babel' ], caller: { supportsTopLevelAwait: true } }, ecmaVersion: undefined } +0ms eslint:linter Parser Path: /home/mark/p/gg_frontend/node_modules/@typescript-eslint/parser/dist/index.js +0ms eslint:linter Settings: { react: { version: 'detect' }, 'import/parsers': { '/home/mark/p/gg_frontend/node_modules/@typescript-eslint/parser/dist/index.js': [ '.ts', '.mts', '.cts', '.tsx', '.d.ts' ] }, 'import/resolver': { '/home/mark/p/gg_frontend/node_modules/eslint-import-resolver-node/index.js': { extensions: [Array] }, '/home/mark/p/gg_frontend/node_modules/eslint-import-resolver-typescript/lib/index.cjs': { alwaysTryTypes: true } } } +0ms Oops! Something went wrong! :( ESLint: 8.42.0 AssertionError [ERR_ASSERTION]: Fix objects must not be overlapped in a report. at mergeFixes (/home/mark/p/gg_frontend/node_modules/eslint/lib/linter/report-translator.js:152:9) at normalizeFixes (/home/mark/p/gg_frontend/node_modules/eslint/lib/linter/report-translator.js:182:16) at /home/mark/p/gg_frontend/node_modules/eslint/lib/linter/report-translator.js:349:49 at Object.report (/home/mark/p/gg_frontend/node_modules/eslint/lib/linter/linter.js:1021:41) at /home/mark/p/gg_frontend/node_modules/eslint-plugin-perfectionist/dist/index.js:3:644 at D (/home/mark/p/gg_frontend/node_modules/eslint-plugin-perfectionist/dist/index.js:1:2730) at /home/mark/p/gg_frontend/node_modules/eslint-plugin-perfectionist/dist/index.js:3:143 at Array.forEach () at Program:exit (/home/mark/p/gg_frontend/node_modules/eslint-plugin-perfectionist/dist/index.js:3:131) at ruleErrorHandler (/home/mark/p/gg_frontend/node_modules/eslint/lib/linter/linter.js:1050:28) ```
azat-io commented 11 months ago

Can you show me content of /home/mark/p/gg_frontend/app/profile/settings/password-changed/page.tsx file?

Or you can use Stackblitz to figure out the problem.

ilmpc commented 11 months ago

Here's an example of a code with a empty lines in imports: link

azat-io commented 11 months ago

Nice. Thank you. I'll fix it soon.

azat-io commented 11 months ago

Fixed in 21bc7a8ef5ea21e308447aba7c8474a1368fb686

Released in v1.2.1