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.62k stars 28 forks source link

Bug: (Failed to compile. [eslint] Cannot read properties of undefined (reading 'getTokensBetween') Occurred while linting /home/itpmbot-dev/builds/K/0/itpm-chat-bot/bot-frontend/src/index.jsx:2 Rule: "perfectionist/sort-imports") #101

Open evgeniyworkbel opened 4 months ago

evgeniyworkbel commented 4 months ago

Describe the bug

After upgrading plugin from 2.4.0 to 2.5.0 our app build have failed. Why?

Failed to compile.
[eslint] Cannot read properties of undefined (reading 'getTokensBetween')
Occurred while linting /home/itpmbot-dev/builds/K1xYuVj3R/0/itpm-chat-bot/bot-frontend/src/index.jsx:2
Rule: "perfectionist/sort-imports"

Code example

---
root: true

env:
  browser: true
  es2022: true

parserOptions:
  ecmaVersion: latest
  sourceType: module

plugins:
  - import
  - jsx-a11y
  - react
  - react-hooks
  - perfectionist

extends:
  - airbnb
  - plugin:import/recommended
  - plugin:react/recommended
  - plugin:react-hooks/recommended

rules:
  # base config rules
  arrow-body-style: "off"
  indent: ["error", 4, { "SwitchCase": 1 }]
  jsx-quotes: ["error", "prefer-single"]
  linebreak-style: "warn"
  lines-between-class-members: ["error", "always", { "exceptAfterSingleLine": true }]
  max-len: ["error", { "code": 135, "ignoreStrings": true, "ignoreComments": true }]
  no-console: "off" # replace with ["error", { "allow": ["warn", "error"] }] after major release
  no-param-reassign: ["error", { "props": false }]
  no-underscore-dangle: ["error", { "allow": ["_retry", ""] }]
  no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]
  object-curly-newline: ["error", { "minProperties": 9, "consistent": true }]

  # plugin rules
  import/extensions: "off"
  import/no-extraneous-dependencies: ["error", {"packageDir": './'}]
  import/prefer-default-export: "off"
  import/no-default-export: "error"
  jsx-a11y/label-has-associated-control: ["error", { "assert": "either" }]
  react/function-component-definition: "off"
  react/jsx-filename-extension: ["warn", { "extensions": [ ".js", ".jsx" ] }]
  react/jsx-indent: ["error", 4, { "indentLogicalExpressions": true }]
  react/jsx-indent-props: ["off", 4]
  react/react-in-jsx-scope: "off"
  react/jsx-sort-props: ["error", { "callbacksLast": true, "shorthandLast": true, "reservedFirst": true }]
  react/jsx-props-no-spreading: "off"
  react/jsx-uses-react: "off"
  react/jsx-uses-vars: "error"
  react/prop-types: "off"
  react/prefer-exact-props: "off"
  perfectionist/sort-imports: [
      "error",
      {
        "groups": [
          "react",
          ["builtin", "external"],
          "internal-type",
          "internal",
          ["parent-type", "sibling-type", "index-type"],
          ["parent", "sibling", "index"],
          "side-effect",
          "side-effect-style",
          "style",
          "object",
          "unknown"
        ],
        "custom-groups": {
          "value": {
            "react": ["react", "react-*"],
          },
        },
      }
    ]

overrides:
  # by default, linter checks only .js file. It allows checking .jsx files in addition
  - files: ["*.jsx", "*.js"]  
  - files: ["**/reused/Icons/**/*.jsx"]
    rules:
      react/jsx-sort-props: "off"

settings:
  react:
    createClass: createReactClass
    pragma: React
    fragment: Fragment
    version: detect
    flowVersion: "0.53"
  propWrapperFunctions:
  - property: freeze
    object: Object
  - property: myFavoriteWrapper
  - property: forbidExtraProps
    exact: true
  componentWrapperFunctions:
  - property: styled
  - property: observer
    object: Mobx
  - property: observer
    object: "<pragma>"
  formComponents:
  - name: Form
    formAttribute: endpoint
  linkComponents:
  - name: Link
    linkAttribute: to
...

ESLint version

8.54.0

ESLint Plugin Perfectionist version

2.5.0

Additional comments

No response

Validations

azat-io commented 4 months ago

There might be a problem with @typescript-eslint/parser. Could you tell me what version you have installed?

And which package manager are you using?

evgeniyworkbel commented 4 months ago

There might be a problem with @typescript-eslint/parser. Could you tell me what version you have installed?

And which package manager are you using?

Our app is based on create-react-app (v5.0.1, latest). The project does not have typescript-eslint/parser directly, but I assume CRA is used its version 5.57.1. Also yarn v 1.22.19 is installed

image

azat-io commented 4 months ago

Can you create a repository and reproduce the problem?

ESLint Plugin Perfectionist uses TypeScript ESLint v6+.

hogan0520 commented 4 months ago

Same issue! ESLint 8.15.0, typescript 5

azat-io commented 4 months ago

@hogan0520 Can you create a small repository and reproduce the problem? That would help me a lot to fix the problem.

hogan0520 commented 4 months ago

@hogan0520 Can you create a small repository and reproduce the problem? That would help me a lot to fix the problem.

I found the reason. Because @typescript-eslint do not have sourceCode property in lower version. Just have getSourceCode(). So, when I used "eslint-plugin-perfectionist": "2.4.0", resolved this issue.

Maybe you need to add some code or dependency limitation to handle it. @azat-io

Thank you for your response.

azat-io commented 4 months ago

@hogan0520 Yes, perhaps we should more rigorously specify the version of @typescript-eslint. Thank you