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

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
2 tasks done
evgeniyworkbel opened this issue Jan 7, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@evgeniyworkbel
Copy link

evgeniyworkbel commented Jan 7, 2024

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

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@evgeniyworkbel evgeniyworkbel added the bug Something isn't working label Jan 7, 2024
@evgeniyworkbel evgeniyworkbel changed the title Bug: (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") 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") Jan 7, 2024
@azat-io
Copy link
Owner

azat-io commented Jan 7, 2024

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
Copy link
Author

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
Copy link
Owner

azat-io commented Jan 9, 2024

Can you create a repository and reproduce the problem?

ESLint Plugin Perfectionist uses TypeScript ESLint v6+.

@hogan0520
Copy link

Same issue! ESLint 8.15.0, typescript 5

@azat-io
Copy link
Owner

azat-io commented Jan 17, 2024

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

@hogan0520
Copy link

@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
Copy link
Owner

azat-io commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants